a array position question
Blitz3D Forums/Blitz3D Beginners Area/a array position question
| ||
Here's the code you helped me with I added Some more rings to form a square formation AppTitle "A test of mine" Graphics3D 800,600,32,2 SetBuffer BackBuffer() cam1=CreateCamera() light=CreateLight() PositionEntity cam1,80,10,5 RotateEntity light,0,0,90 Dim box(9,9) For m = 1 To 9 box(m,0)=LoadMesh("ring1.3ds") box(m,1)=LoadMesh("ring2.3ds") box(m,2)=LoadMesh("ring1.3ds") box(m,3)=LoadMesh("ring2.3ds") box(m,4)=LoadMesh("ring1.3ds") box(m,5)=LoadMesh("ring2.3ds") box(m,6)=LoadMesh("ring1.3ds") box(m,7)=LoadMesh("ring2.3ds") box(m,8)=LoadMesh("ring1.3ds") box(m,9)=LoadMesh("ring2.3ds") PositionEntity box(m,0),Rand(5,5),0,Rand(-5,-5) PositionEntity box(m,1),Rand(10,10),0,Rand(-10,-10) PositionEntity box(m,2),Rand(15,15),0,Rand(-15,-15) PositionEntity box(m,3),Rand(20,20),0,Rand(-20,-20) PositionEntity box(m,4),Rand(25,25),0,Rand(-25,-25) PositionEntity box(m,5),Rand(30,30),0,Rand(-30,-30) PositionEntity box(m,6),Rand(35,35),0,Rand(-35,-35) PositionEntity box(m,7),Rand(40,40),0,Rand(-40,-40) PositionEntity box(m,8),Rand(45,45),0,Rand(-45,-45) PositionEntity box(m,9),Rand(50,50),0,Rand(-50,-50) Next While Not KeyHit(1) If KeyHit(88)=True Then enable=1-enable WireFrame enable If KeyDown(16)=True Then TurnEntity Cam1,.9,0,.9 If KeyDown(18)=True Then TurnEntity Cam1,0,.9,.9 If KeyDown(30) TurnEntity Cam1,0,9,0 If KeyDown(32) TurnEntity Cam1,0,-9,0 If KeyDown(31) MoveEntity Cam1,0,0,-.09 If KeyDown(17) MoveEntity Cam1,0,0,.09 UpdateWorld RenderWorld Text 280,0,"Turn Right with D Letter" Flip Wend End I'm been trying a for a while now to align them like * * * * * * * * * * * * * * * * * * * * In the pattern above. any suggestions? |
| ||
Well, you are creating a multi-dimensioned array - which is okay. However, you are only creating one row of that array. You have realised (correctly) that arrays begin at 0 - however, you begin your loop at 1 - if you were looping through successive rows (which you are not currently doing) you would get problems with the 'rings' from a line appearing on another line. Pretending you were doing it with a single shape - look at this example: AppTitle "A test of mine" Graphics3D 800,600,32,2 SetBuffer BackBuffer() cam1=CreateCamera() light=CreateLight() PositionEntity cam1,80,10,5 RotateEntity light,0,0,90 Dim box(9,9) For mx = 0 To 9 For my = 0 To 9 box(mx,my)=CreateCube() PositionEntity box(mx,my),mx*10,0,my*10 Next Next While Not KeyHit(1) If KeyHit(88)=True Then enable=1-enable WireFrame enable If KeyDown(16)=True Then TurnEntity Cam1,.9,0,.9 If KeyDown(18)=True Then TurnEntity Cam1,0,.9,.9 If KeyDown(30) TurnEntity Cam1,0,9,0 If KeyDown(32) TurnEntity Cam1,0,-9,0 If KeyDown(31) MoveEntity Cam1,0,0,-.09 If KeyDown(17) MoveEntity Cam1,0,0,.09 UpdateWorld RenderWorld Text 280,0,"Turn Right with D Letter" Flip Wend End I just did that quickly - not checked the array positioning for accuracy - but you see the idea I am creating here. |
| ||
There is nothing wrong with your method of - creating the 'ring' then manually putting them in line by line: box(m,0)=LoadMesh("ring1.3ds") PositionEntity box(m,0),Rand(5,5),0,Rand(-5,-5) However, you have to remember the array is multi-dimensioned So you would also need to create successive blocks (like you did above) - but increase the second value in box(m,0) 0,0 - 0,1 - 0,2 - etc 1,0 - 1,1 - 1,2 - etc 2,0 - 2,1 - 2,2 - etc etc. |
| ||
Haggis I understand your first code example But I don't understand this but increase the second value in box(m,0) I understand this in your first code example using a cube but this 0,0 - 0,1 - 0,2 - etc 1,0 - 1,1 - 1,2 - etc 2,0 - 2,1 - 2,2 - etc etc. I don't and Also Would this be correct as a type AppTitle "A test of mine" Graphics3D 800,600,32,2 SetBuffer BackBuffer() cam1=CreateCamera() light=CreateLight() PositionEntity cam1,80,10,5 RotateEntity light,0,0,90 Type box Field mx Field my End Type For mx = 0 To 9 For my = 0 To 9 box(mx,my)=LoadMesh("ring1.3ds") PositionEntity box(mx,my),mx*10,0,my*10 Next Next While Not KeyHit(1) If KeyHit(88)=True Then enable=1-enable WireFrame enable If KeyDown(16)=True Then TurnEntity Cam1,.9,0,.9 If KeyDown(18)=True Then TurnEntity Cam1,0,.9,.9 If KeyDown(30) TurnEntity Cam1,0,9,0 If KeyDown(32) TurnEntity Cam1,0,-9,0 If KeyDown(31) MoveEntity Cam1,0,0,-.09 If KeyDown(17) MoveEntity Cam1,0,0,.09 UpdateWorld RenderWorld Text 280,0,"Turn Right with D Letter" Flip Wend End |
| ||
uh, never mind, thought something is not clear yet, but it seems it acutally is. |
| ||
No Look Here AppTitle "A test of mine" Graphics3D 800,600,32,2 SetBuffer BackBuffer() ;Scene Setup pivcam = CreatePivot() cam=CreateCamera(pivcam) PositionEntity cam,0,15,-20 PositionEntity pivcam, 50,0,50 PointEntity cam,pivcam light=CreateLight() RotateEntity light,0,0,90 MasterRingModel = CreateTorus(1,0.2,16,8) RotateMesh MasterRingModel, 60,0,0 EntityColor MasterRingModel, 236,236,0 EntityShininess MasterRingModel, 1 HideEntity MasterRingModel ;Ring Type Type ringType Field Model End Type ;Ring Type Populate For mx = 0 To 9 For my = 0 To 9 Ring.RingType = New RingType Ring\Model=CopyEntity (MasterRingModel) PositionEntity Ring\Model,mx*10,0,my*10 Next Next ;Main Loop While Not KeyHit(1) TurnEntity pivcam,0,0.2,0 For Ring.RingType = Each RingType TurnEntity Ring\Model,0,-5,0 Next UpdateWorld RenderWorld Flip Wend End Function CreateTorus(torrad#,torwidth#,segments,sides,parent=0) torusmesh=CreateMesh(parent) surf=CreateSurface(torusmesh) FATSTEP#=360.0/sides DEGSTEP#=360.0/segments radius#=0 x#=0 y#=0 z#=0 fat#=0 Repeat radius = torrad + (torwidth)*Sin(fat) deg#=0 z=torwidth*Cos(fat) Repeat x=radius*Cos(deg) y=radius*Sin(deg) AddVertex surf,x,y,z,x,y,z deg=deg+DEGSTEP Until deg>=360 fat=fat+FATSTEP Until fat>=360 For vert=0 To segments*sides-1 v0=vert v1=vert+segments v2=vert+1 v3=vert+1+segments If v1>=(segments*sides) Then v1=v1-(segments*sides) If v2>=(segments*sides) Then v2=v2-(segments*sides) If v3>=(segments*sides) Then v3=v3-(segments*sides) AddTriangle surf,v0,v1,v2 AddTriangle surf,v1,v3,v2 Next UpdateNormals torusmesh Return torusmesh End Function Oh and you can ignore the big confusing function if you want. It is just a torus creation function from the code archives (by Phil74) |
| ||
seferey: Why are you assigning random positions to your rings if you want a an array in a box shape, as per the below? * * * * * * * * * * * * * * * * * * * * Come to think of it, since the Rand command uses low-to-high numbers, and you're using the same number in both positions, why are you using the Rand command at all? |