Hi dudes, I am trying to put some NEWTON objects over a matrix.
It\'s a simple mission but I have a problem..
Ok, I make 2 cube objects. Later I gave NEWTON rules to these cubes and I got no errors about.
The problem born when I try to give a XYZ position to each of these cubes BEFORE THE START OF THE MAIN LOOP (
but the problem is the same if I try to move my Newton object inside the main loop).
Here the code(I leave the example remarks to make you look more easy).
make matrix 1,1000,1000,10,10
load image \"grass.jpg\",1
position matrix 1,0,0,0
prepare matrix texture 1,1,1,1
rem SET MATRIX WIREFRAME ON 1
update matrix 1
`this first command initializes the Newton world, and must be called before
`any other Newton commands. to remove newton, use the NDB_NewtonDestroy command.
NDB_NewtonCreate
`We need to set the World limits, this is very important to do otherwise there
`could be some unpredictable results
NDB_SetVector 1, -500.0, -500.0, -500.0
NDB_SetVector 2, 500.0, 500.0, 500.0
NDB_NewtonSetWorldSize
`okay, we have a newto world now. let\'s make our cube!
`first we make the DBPro cube, like always.
make object cube 1, 100
make object cube 2, 30
`now we must make a cube just like this one, that will exist in the Newton world.
`this command makes a \"collision object\", which is how we describe the shape of an
`object to Newton. there are no \"cubes\" in newton, so we make a \"box\", with 100 for
`each dimension (length, width, height).
Col1 = NDB_NewtonCreateBox( 100.0, 100.0, 100.0 )
Col2 = NDB_NewtonCreateBox( 30.0, 30.0, 30.0 )
`okay, now our variable \"Col\" holds an index to this collision. we\'ll use this to create
`a \"rigid body\", which is an object in the Newton world (like our DBPro cube is an object in
`the visual world of dbpro).
Cube1 = NDB_NewtonCreateBody( Col1 )
Cube2 = NDB_NewtonCreateBody( Col2 )
`next, we need to set a mass for our cube, otherwise Newton will think that it\'s a static object.
`for now, don\'t worry too much about the other values, they deal with how much a body resists
`rotation around different axis... look at the docs for more info.
NDB_NewtonBodySetMassMatrix Cube1, 10.0, 1.0, 1.0, 1.0
NDB_NewtonBodySetMassMatrix Cube2, 10.0, 1.0, 1.0, 1.0
`now \"Cube\" holds an index to our new rigid body, with the shape of Col (which we described
`as a box 100x100x100 above).
`next, we will \"connect\" the Newton Rigid Body to the DBPro cube. this will let Newton
`position and rotate the DBPro object for us, based on the physics it calculates!
NDB_BodySetDBProData Cube1, 1
NDB_BodySetDBProData Cube2, 2
NDB_NewtonUpdate 0.1
`that assigned DBpro object# 1 to the Rigid Body indexed by \"Cube\".
`finally, we want the cube to spin, so we\'ll set an initial \"Omega\", which is just a name
`for \"spin\". this command is a good example of how you do things with newton... because many
`commands ask for a 3D vector (x,y,z), and sometimes commands actually RETURN a 3D vector, I had
`to come up with a simple way to get vectors in and out of Newton. as you know, a function cannot
`return more than 1 value in DBPro, so I came up with the \"temp vector\" system in my wrapper. basically,
`the wrapper has 4 internal \"temp\" vectors for temporarily storing data. so for example this Omega
`command wants you to tell it 3 values, the spin around each axis. rather than doing this:
` NDB_NewtonBodySetOmega Body, x#, y#, z#
`Instead, with the wrapper I require that you do this:
` NDB_SetVector x#, y#, z#
` NDB_NewtonBodySetOmega Cube
`
`This makes the system cleaner, I promise. anyway, you\'ll get used to it.
`okay so let\'s set an inital OMEGA for the cube body!
rem , X , Y , Z
NDB_SetVector 0.0 , 10.0 , 0.0
NDB_NewtonBodySetOmega Cube1
NDB_SetVector 10.0 , 0.0 , 0.0
NDB_NewtonBodySetOmega Cube2
`you\'ll notice that I only put in a value for the Y axis... so the cube should spin around
`the Y axis only, just like the simple DBPro demo.
`Giving the XYZ coords to each cubes
Position object NDB_GetDBPro(cube1),140,5,140
Position object NDB_GetDBPro(cube2),340,5,140
` giving the XYZ coords to camera
position camera -260,3,-260
`okay, that\'s all of the setup we need, let\'s make our main loop!
do
rem mouse view
if mouseclick()=1 then cf#=1
if mouseclick()=2 then cf#=-1
cx#=wrapvalue(cx#+mousemovey()*0.5)
cy#=wrapvalue(cy#+mousemovex()*0.5)
if cx#<=290 and cx#>180 then cx#=290
if cx#>=70 and cx#<=180 then cx#=70
acx#=curveangle(cx#,acx#,2.1)
acy#=curveangle(cy#,acy#,2.1)
rotate camera acx#,acy#,0
acf#=curvevalue(cf#,acf#,20)
move camera acf#
cf#=0
`gets the amount ot time elapsed since the last call to this function, in seconds.
time# = NDB_GetElapsedTimeInSec()
`then the big command that updates the physics world. you tell it how much
`time has passed, and it updates that much.
NDB_NewtonUpdate time#
loop
Damn I think the logic is right.. so why my cubes remaining in standard initial position instead of taking my XYZ coords?
Thanks in advance!