Posted: 20th Jun 2007 9:13
I've written an extremely simple program designed to test simple collision in Newton. I've got a simple hut and a simple stickman and all I want is to move the Stickman forward until he runs into the hut and stops. (i realize the door is open on the hut, just bear with me on this)

The problem is, he won't move! The oddest thing is that the first time I compiled this, he moved perfectly fine. When I ran it a second time after tweaking some variables, he suddenly won't move anywhere. Can anyone spot what I'm doing wrong?

(a small zip file is attached to this post)

If the code is sufficient without the zip file, here's the code:

+ Code Snippet
set display mode 800,600,32
sync off
hide mouse

` starts Newton
_setupnewton:
NDB_NewtonCreate

_stickman:
StickmanCol = NDB_NewtonCreateBox(30,30,30)
` creates rigid body
StickmanBody = NDB_NewtonCreateBody(StickmanCol)
` sets orientation of rigid body
NDB_BuildMatrix 0,0,0,0,0,0
NDB_NewtonBodySetMatrix StickmanBody
` calculates mass of solid
NDB_CalculateMIBoxSolid 1, 30, 30, 30
NDB_NewtonBodySetMassMatrix StickmanBody, 1,1,1,1
` RELEASE
NDB_NewtonReleaseCollision StickmanCol

load object "media\player\stickman.x",2
position object 2,0,0,0
scale object 2,25,25,25
rotate object 2,0,180,0
fix object pivot 2
` This finally puts the rigid body and actual object together
NDB_BodySetDBProData StickmanBody, 2
` destroys both rigid object & 3d object whenever it gets called in the future
NDB_NewtonBodySetDestructorCallback StickmanBody
` applies gravity to the object (commented out for now)
`NDB_BodySetGravity StickmanBody, 1

_setuphouse:
HutCol = NDB_NewtonCreateBox(50,50,50)
` creates rigid body
HutBody = NDB_NewtonCreateBody(HutCol)
` sets orientation of rigid body
NDB_BuildMatrix 0,0,0,0,0,500
NDB_NewtonBodySetMatrix HutBody
` calculates mass of solid
NDB_CalculateMIBoxSolid 50, 75, 75, 75
NDB_NewtonBodySetMassMatrix HutBody, 50
` RELEASE
NDB_NewtonReleaseCollision HutCol

load object "media\player\hut1.x",3
position object 3,0,0,500
` This finally puts the rigid body and actual object together
NDB_BodySetDBProData HutBody, 3
` destroys both rigid object & 3d object whenever it gets called in the future
NDB_NewtonBodySetDestructorCallback HutBody
` applies gravity to the object (commented out for now)
`NDB_BodySetGravity HutBody, 3

time# = NDB_GetElapsedTimeInSec()
time# = NDB_GetElapsedTimeInSec()

do
 `gets the amount of time elapsed since the last call to this function, in seconds.
 time# = NDB_GetElapsedTimeInSec()
`then the big command that updates the physics world.
 NDB_NewtonUpdate time#

 x#=object position x(2)
 y#=object position y(2)
 z#=object position z(2)
 set camera to follow x#,y#,z#,object angle y(2),5,18,35,1

 if upkey()=1
  NDB_SetVector 1, 0.0, 0.0, 0.0
  NDB_SetVector 2, 0.0, 0.0, 20.0
  NDB_BodyAddForceLocal StickmanBody
 endif

 if downkey()=1
  NDB_SetVector 1, 0.0, 0.0, 0.0
  NDB_SetVector 2, 0.0, 0.0, -20.0
  NDB_BodyAddForceLocal StickmanBody
 endif

 sync
loop


Thanks so much!!
Weedfox
Posted: 20th Jun 2007 20:18
Another oddity happens when running the NewtonDebug thing ... every time I hit the button I've set to activate it, the program crashes, even though the code is lifted verbatim from a demo where it works perfectly well.

I'm entirely at a loss.
Posted: 21st Jun 2007 1:33
FIXED IT!

The problem was that the program needed this ONE SIMPLE LINE OF CODE. Apparently in Newton whenever an object comes to rest (or in this case starts at rest) it automatically freezes it. I hope this helps people who may run into my situation.

NDB_NewtonBodySetAutoFreeze StickmanBody, 0

THAT'S IT! I just put it before I did the release command and it worked perfectly fine.