very simple Physic failing

siddian

18-04-2010 12:16:00

Hi,

finally I got the all the necessary Files/libs installed and the tutorial code is running!
Then I tried my one stuff and the simplest example create a mess (no pun intended).

when creating a cube of 1kg and applying a force of (0, 9.81, 0) given a gravity of (0, -9.81, 0)
the cube should stand still right?
Well sadly not in this world...

I tried a lot of stuff, e.g. modifying the fields from the NxOgre::SceneDescription to create the scene,
but this changes nothing.
All it does is creating even more questions.
It seems like several fields are not used, e.g. mMaxSubSteps, mMaxTimeStep, ...

I can't even modify the value of "mTimeController->advance(_1_60);".

I am quite helpless here and could need some good advice.

siddian

betajaen

18-04-2010 13:31:28

F=mA

And Gravity is an acceleration (not a force)

You need to multiply your force by the bodies mass.

siddian

18-04-2010 13:36:31

F=mA

And Gravity is an acceleration (not a force)

You need to multiply your force by the bodies mass.


oh sorry I did in the code, but anyway f = 1kg * 9.81 m/s^2 = 9.81N, right ?

and I also tried setting the forcemode to ForceMode_Acceleration which should always work...

betajaen

18-04-2010 13:46:00

I thought so too, but it's Impulse apparently. I also thought you had to multiply the force by the timestep, but no as well.

Anyway, I assume you just want anti-gravity.

float Fy = (9.81 * test->getMass())
+ (-test->getLinearVelocity().y * test->getMass())
+ (10 - test->getGlobalPosition().y * test->getMass());

test->addForce(Vec3(0, Fy, 0), NxOgre::Enums::ForceMode_Impulse);


"10" is vertical position where you want to be, 9.81 obviously the acceleration of gravity.

[Edit]

Hmm. I just checked and "10" doesn't really make it 10 metres of the ground, you'll see what I mean if you increase it to 20.

Anyway, I have done anti-gravity before via forces, I just can't remember where I put the code. If you want proper Anti-gravity, then set the Enums::BodyFlags_DisableGravity to the flags in the BodyDescription when you create the body.

siddian

18-04-2010 15:33:37


Anyway, I assume you just want anti-gravity.


actually no, I want to use Ogre3D/NxOgre/PhysX to built up a simulation environment to use with a Swarm of Unmanned Arial Vehicles (UAV).
But before that I want to make sure that everything is OK.

I tried this test on a different (a lot faster) machine and with a fixed timestep of _1_60 and always advancing _1_60
mTimeController->advance(_1_60);
instead of
mTimeController->advance(evt.timeSinceLastFrame);
it seems to be running OK - at least the cube doesn't move :-)
The same code running on my notebook results in the cube going up...

By the way, where can I change the fixed timestep to e.g. _1_100?
Seems to me only the maxTimeStep can be changed...

Thanks for your fast answers and help, I'm quite a newbie with this :-)

siddian

20-04-2010 09:01:51

So I did a little testing on several machines.
for this I compiled and ran the binary to see whether the cube stays still (like it should)
or whether it floats up again (like it shouldn't).
all of the machines use the same version of Ogre3D+NxOgre+PhysX SDK+PhysX System Software!

the machines:
1. 1x machine with pentium 4 and Nvidia 9800 GT
2. 2x machines have the same hardware - Intel Xeon CPU, Nvidia 9800GT
3. 1x different laptop with Intel core duo + a quadro card
4. 1x my laptop intel core 2 duo + nvidia 7600 GO

the results:
On all except the first one the cube moves up!

But I found a workaround which is really ugly in a way.
Instead of defining a global gravity, I define this a the very beginning of every timestep:
mCube->addForce(NxOgre::Vec3(0, -9.81, 0), NxOgre::Enums::ForceMode_Acceleration);

while setting the scene-gravity to zero
that way I get a gravity for this specific cube
adding a force of :
mCube->addForce(NxOgre::Vec3(0, mCube->getMass() * 9.81, 0), NxOgre::Enums::ForceMode_Force);
lets my cube hover (of course)

If you want proper Anti-gravity, then set the Enums::BodyFlags_DisableGravity to the flags in the BodyDescription when you create the body.

Trying this resulted in several compiling errors, but I will look into this further.