Game Development Reference
In-Depth Information
where p a is the scalar distance that object a willbemoved(we'llreturntothedirec-
tion later). The two distances are related to each other according to the ratio of their
masses:
=
m a p a
m b p b
which combined gives us
m b
p a
=
m b d
+
m a
and
m a
m a +
p b =
d
m b
Combining these with the direction from the contact normal, we get a total change
in the vector position of
m b
m a +
p a =
m b d n
and
m a
m b d n
where n is the contact normal. (Note the minus sign in the second equation: this is
because the contact normal is given from object a 's perspective.)
We can implement the interpenetration resolution equations with this function:
p b =−
m a
+
Excerpt from include/cyclone/pcontacts.h
class ParticleContact
{
// ... Other ParticleContact code as before ...
/**
* Handles the interpenetration resolution for this contact.
*/
void resolveInterpenetration(real duration);
};
Excerpt from src/pcontacts.cpp
void ParticleContact::resolve(real duration)
{
resolveVelocity(duration);
resolveInterpenetration(duration);
}
void ParticleContact::resolveInterpenetration(real duration)
{
Search Nedrilad ::

Custom Search