Yesterday I implemented the ability for a contact to resolve its velocity (meaning the resulting velocities after the collision). Today I dealt with the interpenetration, which moves the objects to avoid them from penetrating each other.
I also modified the velocity resolver to deal with resting: it checks if the velocity of a particle is fully generated during the current frame (meaning that it was not moving before). If that's the case, no contact resolution is applied, and the object will not look like it's trembling.
After that I implemented the class to handle contact resolution. Given a list of contacts, they are resolved with the following algorithm:
1) Sort the contacts and pick the one with greater separating velocity (should be resolved first)
2) If there is none, exit.
3) Resolve the picked contact (I'll call it A)
4) For each contact, if it was involved in the contact with A, move it by the correct amount to avoid interpenetration
5) After a certain amount of iterations, quit.
I've a few problems with this algorithm, and the book I'm reading is not clear at all at this point... One of them is step 4. When interpenetrations are resolved inside the contact.resolve function, the resolution takes into account the relative masses, while here this is ignored. I imagine a situation where a very light object interpenetrates another object and it is moved apart. If a block of metal is in contact with it, it will be moved by the same amount, with no respect for it's mass. I hope I'll understand it in the next days.
Nessun commento:
Posta un commento