more bodies = more force required?

Grom

20-01-2007 22:07:29

I'm still just playing around with boxes. I have one box that is controllable with the WASD keys, like so:

if(m_InputReader->isKeyDown(KC_W))
myBody->addForce(Vector3(0,0,-50));


I set up code to dump a bunch of boxes in front of this box like so (this is where I create the moveable box and a bunch of ones falling in a line):

myBody = mScene->createBody("myCube", "Box01.mesh", new cubeShape(1.0f), 10.0f, Vector3(0,10,0) );

for(int i=0; i<10; i++)
mScene->createBody("cubes" + StringConverter::toString(i), "Box01.mesh", new cubeShape(1.0f), 10.0f, Vector3(0, 10 + i*10 ,-20) );




This looks pretty cool, except the first box no longer moves with the amount of force applied to it. I notice that the more boxes I dump into the scene, the more force I have to apply to the first box in order to get it moving. Why is this?

betajaen

20-01-2007 22:26:33

Yep.

The force is applied once every frame, less frame rate the lower the force is applied each second.

So say you want 500 newtons of force each second to a box. So you do "500 * timeSinceLastFrame".

Easy ;)

Grom

20-01-2007 22:51:57

Interesting. This behavior occurs with Vsync enabled. Are you talking about some kind of internal Physx framerate?

betajaen

20-01-2007 22:59:47

No, it's more independent on the Ogre frame rate. But since you have VSync enabled then, you can accurately predict the frame rate:

forceToApply * 0.01667

And to make the scene run at 60 frames per second, which is easier on the iterator:

mWorld = new world(...);
mScene = mWorld->createScene(...);
mScene->setTiming(scene::FIXED, 1.0f / 60.0f);


Now that should work ;)

Grom

20-01-2007 23:31:25

multiplying it by the timeSinceLastFrame seems to work pretty well, it seems to act the same way regardless of if I add 10 or 1000 boxes (1000 boxes is awesome, still getting 60 fps and it's all interacting perfectly. Awesome.)

I tried the setTiming call but got:
error C2039: 'setTiming' : is not a member of 'nxOgre::scene'

betajaen

21-01-2007 11:36:29

setTiming, I believe is new in 0.4RC3.

If you don't want to upgrade, you can use this code instead:

mScene->mScene->setTiming(1.0f / 60.0f, 8, NX_TIMESTEP_FIXED);