I want to do my own satellite simulator. I would have a large static object (the planet) and a whole bunch of dynamic ridged bodies orbiting (or crashing into) it.
Currently gravity in most physics libraries (including bullet) assume that gravity is global and position independent. So I can't use it as is.
I want to assume that gravity is 9.8m/s2 towards the point (0,0,0), rather than to a plane.
From what I can gather looking at the source code, the application of gravity (using applyGravity()) is independent to the number of sub steps in the simulation (btDiscreteDynamicsWorld.cpp: 275). For my method, gravity is dependent on position (which can change in the substeps), so it isn't independent to the number of sub steps in the simulation.
This means that I can't just modify gravity before each call to stepSimulation() if there are any substeps.
Searching the forum led me to this thread:
http://www.bulletphysics.org/Bullet/php ... f=9&t=3315
Which basically says that I can't use the tick callback to apply forces each substep either.
However, If got me thinking. I could apply the position dependent gravity force in the Pretick callback, then remove it again in the normal tick callback. Either that or apply the initial force before calling stepSimulation(), and then modifying it every tick callback depending on the body's new position.
So, my question is:
Is there an easier/better/more attractive way to apply position dependent gravity than the one I have described above?
Changing gravity depending on position.
-
Jodi
- Posts: 4
- Joined: Thu Sep 23, 2010 3:07 am
- Location: Auckland, New Zealand
-
robagar
- Posts: 48
- Joined: Fri May 21, 2010 1:49 am
Re: Changing gravity depending on position.
How about modifying btRigidBody::applyGravity() in Bullet itself, and submitting a patch? Perhaps with #ifdefs so the default is constant gravity like it is now.
-
Jodi
- Posts: 4
- Joined: Thu Sep 23, 2010 3:07 am
- Location: Auckland, New Zealand
Re: Changing gravity depending on position.
btRigidBody::applyGravity() is only called once per simulation step, not once per substep. So overriding that wouldn't work.
I would have to add the gravity calculation to btRigidBody::integrateVelocities() instead, maybe putting the gravity code in there instead.
Hmmmm.
I would have to add the gravity calculation to btRigidBody::integrateVelocities() instead, maybe putting the gravity code in there instead.
Hmmmm.
-
Jodi
- Posts: 4
- Joined: Thu Sep 23, 2010 3:07 am
- Location: Auckland, New Zealand
Re: Changing gravity depending on position.
Tell you what. I'm going to cheat. I'm going to just apply gravity once per simulation step, and accept the error due to sub-stepping. The easiest fix is no fix at all 