Saturday, January 12, 2008

Rigid Body Physics

hi, i decided to add some rigid body physics.
there is a lot of physics engines out there that i could integrate into my engine, so i have checked few engines such as Agiea PhysX, newton dynamics and ode.
Agiea PhysX seems to be very fast and stable, and it comes with great sdk with tons of examples, so i decided to give it a try.
while trying t integrate i have founded that its not so great for me, because i already have very good and fast collision system that i'm using in my AI, projectiles,camera collision and more, so to make use of external lib i must change all the places that use my system to use theirs.
this wasn't an option because i need to check that everything that was working is still works after the change.
i could use their engine with my own systems but it required to duplicate the data, the scene for example must be known by both systems so they and mine could do collisions.
also, i just want simple physics and i wont even use all the features that Agiea PhysX support so i decided to write my own physics engine so the integration will be smooth and clean, this will take some time to do but i think its worth the a effort, i also will learn from the process :)
my physics system is impulsed based, that means that in order to move an object an impulse to act on the object on a certain point.
i choose to use impulsed base physics engine so i wont need to solve big linear equations system every frame, also i could give x ms for the physics engine and things that didn't solved correctly in current frame will get a chance next frame.
also in impulsed base, constraints system isn't stiff, that means the constraints is trying to be preserved by applying forces every frame/iteration, this is different from linear systems (implicit method) because if the system can't be solved (for example: one of the constraint needs very big forces to be preserved) the system will explode.
after reading some materials and got refreshed in my calculus, i'v started to wrote the engine.
i have finished the integration, also add simple shapes: sphere, box, cylinder
the collision system is also finished and support rigid body vs scene and rigid body vs rigid body collision.
for now each rigid body is a mesh, so the collision basically does mesh vs mesh collision, this simplify the things a lot because i don't need to a lot of collision functions based on rigid bodies type.
i also started working on few joint constraints: ball & socket, hinge and universal, next time i hope i will finish it and put some screenshots :)
here is few screenshots of the rigid bodies in action (wireframe mode).

box stacks
one of the stacks lost balance and fall

No comments: