Show differencesHistory of post edits
Posted 21 December 2012 - 10:41 AM
I am writing a 2d physics engine. It is very simple, I only have circles and they do not rotate, so it is basically a particle engine.
My time step is pretty basic.
Find all collisions.
Integrate forces to find new velocities.
iterate over all contacts several times and apply impulses.
integrate velocities to find new positions
I am also using "warm starting" where if a contact persists for a frame then I use the old impulses as an initial guess for the new impulses. So I store a list of all contacts and in my Find all collisions routine
Make a new list for new contacts
Check for collision
If I find a collision I check to see if if the old contact list contains a contact with the 2 object that collided. If it does I store the prev impulses in the new contact. Then I add the new contact to the list of new contacts.
set contact list to new list
delete the old contact list
I notice in chipmunk and box2d they use a hash map, but I cant seem to figure out what they are doing. My method is very slow and theirs is much faster. Can anyone who has implemented this give me any pointers on how to do this?