All this stuff is more or less complicated to achieve, but from my previous research I have found some Open Source engines from which I can learn a lot.
The best documented one so far is ODE (www.ode.org), and also the one I intend to merge with Blender.
So, I present a very quick and thorough overview on how this works, in order to have some scope.
The first thing to disentangle is how it gets working. For that, just looking at the user's manual one gets the following algorithm:
1.-Create a Dynamics world
2.-Create the bodies
- This basically means to make an instance of the dxWorld struct.
3.-Create the joints
- Attach the bodies to the world (this means adding data to the dxBody* array of the dynamics world).
- Set their properties (position and orientation of point of reference, its linear and angular velocities, the mass of the bodies and some other stuff of the like).
- Attach the joints to the world (by adding data to the dxJoints* array of the dynamics world)
- Set their properties (depending of the selected type of joint, one has to provide different details).
- Create a new collision world (just by making an instance to the dxSpace struct).
- Create a joint group where collisions will be stored temporarily for every frame step.
6.-Destroy the dynamics and the collision worlds (wow, that sounds evil...hehehe).
- Apply forces to bodies.
- Adjust joint parameters.
- Call collision detection.
- Create a contact joint for every detected collision point and add it to the collision joint group.
- Take a simulation step.
- Clear the collision joint group.
All of this seems fairly easy to do but then one has to get to know where and how things have been implemented. This is when things become a bit harder.
I am sure the file structure and the class definitions make perfect sense for the programmers of this engine.
Fortunately, they have been careful enough so as to comment everything in an understandable way, for which I feel deeply grateful.
After some digging, I have managed to restructure the ode/src folder into the following topics:
Which means one can tackle the engine in an ordered manner and find things when needed.
- Memory management
- Matrix handling
- External applications
From a theoretical point of view, this engine presents the following features:
- A Lagrange multiplier velocity based model from Trinkle and Stewart
- A friction model from Baraff
- A Danzig LCP solver