I can't figure out why this won't work the way it should.
I am making 2 type lists, a list for the scale of and entity and a list for other related objects, such as it's rigid body and such.
The problem is that the scale list is combining somehow, ading the values of one list to the other. I have a function called set_objscale(2.0,1.0,1.0,0.0), then I call a function to make the object those values are suposed to scale, then I call the scale function again to give it new values, to apply to a different entity and the values of the first scale list are added to the second scale list. So if I set the first funtion to (2.0,1.0,1.0,0.0), and the scond function to (1.0,1.0,1.0,0.0),
it results in the first object being 2.0,1.0,1.0 and the second object 3.0,1.0,1.0. Just strange.
Here is the code, someone help Please?
I am making 2 type lists, a list for the scale of and entity and a list for other related objects, such as it's rigid body and such.
The problem is that the scale list is combining somehow, ading the values of one list to the other. I have a function called set_objscale(2.0,1.0,1.0,0.0), then I call a function to make the object those values are suposed to scale, then I call the scale function again to give it new values, to apply to a different entity and the values of the first scale list are added to the second scale list. So if I set the first funtion to (2.0,1.0,1.0,0.0), and the scond function to (1.0,1.0,1.0,0.0),
it results in the first object being 2.0,1.0,1.0 and the second object 3.0,1.0,1.0. Just strange.
Here is the code, someone help Please?
;A set of functions to make Rigid bodies using types rather than arrays Graphics3D 800,600 Const FPS=60 period=1000/FPS time=MilliSecs()-period imptime=MilliSecs() ;WireFrame True SeedRnd MilliSecs() Const Rigid_Bodies=2,Animated_Bodies=1 TOKSIM_SetRigidBodiesCount Rigid_Bodies TOKSIM_SetAnimatedBodiesCount Animated_Bodies TOKSIM_SetRigidParticleCount 0 TOKSIM_SetControllersCount 0 TOKSIM_SetGeometriesCount Rigid_bodies+Animated_Bodies ;Assuming each one only has one geometry. Not true with more complex rigid bodies and animated bodies. TOKSIM_CreateSimulator(0,-10,0) Type objscale Field x# Field y# Field z# Field rbx# Field rby# Field rbz# Field diameter# Field rb_diameter# End Type Type RB_OBJ Field rb Field obj Field parent Field solid Field segments ;Field its_a End Type Global p Global b Global c Global s set_objscale(2.0,1.0,1.0,0.0) box=Make_OBJ_RB(2,False,False,0,obj,rb) set_objscale(1.0,1.0,1.0,1.0) cill=Make_OBJ_RB(1,False,False,12,obj,rb) ;sets the scale of an object and rigid body automaticly by specifying just the object scale. ;values must be floats Function set_objscale(x#,y#,z#,diam#) If body.objscale<>Null Then For body.objscale=Each objscale Delete body Delete body.objscale Next EndIf body.objscale=New objscale body\x# = x# body\y# = y# body\z# = z# body\rbx#=body\x#*2.0 body\rby#=body\y#*2.0 body\rbz#=body\z#*2.0 body\diameter# = diam# body\rb_diameter# = body\diameter#*2.0 ;Return mesh End Function PositionEntity cill,0,5,0 PositionEntity box,0,9,-2 ;A function to make the object and rigid bodies with properties from the set_scale function ;Parameter 1: shape= the desired shape of object must be 1,Pill, 2,Box, 3,Sphere, or 4,convex ;Parameter 2: par= the desired parent of the object, if none set to false ;Parameter 3; sol= solid true or false, should be set to true for most cases ;Parameter 4; segments= number of sudevisions for spheres and pills, set to null for boxes ;Parameter 5; rb = handle ;Parameter 6; obj = handle Function Make_OBJ_RB(shape,par,sol,segm,obj,rb) Make.RB_OBJ=New RB_OBJ Make\parent=par Make\solid=sol Make\segments=segm Select shape Case 1 ;Pill ;Makes the main body and the two spheres for end caps Make\obj=CreateCylinder(Make\segments,Make\solid,Make\parent) Local spheresegments=Make\segments/2 t=CreateSphere(spheresegments,Make\obj) b=CreateSphere(spheresegments,Make\obj) For body.objscale=Each objscale ;Scale the pill and position caps ScaleMesh Make\obj,body\x#,body\y#,body\z# ScaleMesh t,body\x#,body\y#,body\z# PositionEntity t,0,body\y#,0 ScaleMesh b,body\x#,body\y#,body\z# PositionEntity b,0,-body\y#,0 Next p=True Return Make\obj Case 2 ;Box Make\obj=CreateCube(Make\parent) For body.objscale= Each objscale ScaleMesh Make\obj,body\x#,body\y#,body\z# Next Return Make\obj Case 3 ;Sphere Case 4 ;Convex Default End End Select End Function light=CreateLight() PositionEntity light,100,100,100 camera=CreateCamera() PositionEntity camera,0,10,-20 tex = LoadTexture("track.bmp") Terrain = LoadMesh("track.3ds") ScaleMesh Terrain,30.0,30.0,30.0 RotateMesh Terrain,-90,0,0 EntityTexture terrain,tex MakeTokCollider(Terrain) SetBuffer BackBuffer() While Not KeyHit(1) Repeat elapsed=MilliSecs()-time Until elapsed ticks=elapsed/period tween#=Float(elapsed Mod period)/Float(period) For k=1 To ticks time=time+period If k=ticks Then CaptureWorld TOKSIM_Advance(2.0/FPS,3.0) UpdateWorld Next RenderWorld tween# Text 0,10,"Render Time:"+FPS+ " milliseconds" Text 0,30," p " + p Flip Wend TOKSIM_DestroySimulator() End Function Update_RB_OBJ() End Function Function MakeTokCollider(mesh) scount=CountSurfaces(mesh) For ind=1 To scount surface=GetSurface(mesh,ind) ttltris=ttltris+CountTriangles(surface) ttlvert=ttlvert+CountVertices(surface) Next vertices=CreateBank(16*ttlvert) triangles=CreateBank(24*ttltris) offsetv=0 offsett=0 For ind=1 To scount surface = GetSurface(mesh,ind) ctr=CountTriangles(surface) tric=tric+cvt cvt=CountVertices(surface) ;fill bank with vertices For v=0 To cvt-1 PokeFloat vertices,offsetv,VertexX#(surface,v) PokeFloat vertices,offsetv+4,VertexY#(surface,v) PokeFloat vertices,offsetv+8,VertexZ#(surface,v) PokeFloat vertices,offsetv+12,0.0 offsetv=offsetv+16 Next ;fill bank with triangles For v=0 To ctr-1 PokeInt triangles,offsett,tric+TriangleVertex(surface,v,0) PokeInt triangles,offsett+4,tric+TriangleVertex(surface,v,1) PokeInt triangles,offsett+8,tric+TriangleVertex(surface,v,2) PokeInt triangles,offsett+12,2 ; Material ID PokeInt triangles,offsett+16,0 PokeInt triangles,offsett+20,0 offsett=offsett+24 Next Next ;Hand over the terrain data to Tokamak TOKSIM_SetStaticMesh vertices,ttlvert,triangles,ttltris ; Now we can free the banks as Tokamak has copied all data FreeBank vertices FreeBank triangles End Function