[ODE] ODE gravity

Roel van Dijk R.vanDijk at rad.umcn.nl
Fri Dec 19 10:22:20 MST 2003


On Friday 19 December 2003 08:58, arcad wrote:
> What assign in determined volume of space gravity different from that
> which is set in dWorldSetGravity(world, 0, -9.81f, 0)
> I make a stab in its level pool with water.
I think it is easier to not use dWorldSetGravity if you want to do anything 
different then simple gravity. Just apply a certain force on all your objects 
every simulation step.
Lets say we have an object 'car'. The world is a perfect flat plane. To 
simulate gravity I first create a normal vector that points down. First I 
multiply the normal with some gravity constant. Then I multiply the normal 
vector with the mass of the car, because gravity pulls harder on objects with 
a greater mass. Then I add that vector to a body as a force:

// assuming +y is up
vector g(0, -1, 0);
g *= gravity_constant;
g *= car.mass;
dBodyAddForce(car, g.x, g.y, g.z);

Now in your simulation you have to check where your object is. If it is in an 
area with less gravity you just use a lower gravity constant.




More information about the ODE mailing list