Game Development Reference
In-Depth Information
// 1. Calculate Separation
ImpactRadiusSum = body1.GetScaledRadius() + body2.GetScaledRadius();
Vector3 Position1 = body1.m_Orientation.GetPosition();
Vector3 Position2 =body2.m_Orientation.GetPosition();
Vector3 DistanceVec = Vector3.Subtract(Position1, Position2);
CollisionDistance = DistanceVec.Length() - ImpactRadiusSum;
// 2. Set Collision Normal Vector
DistanceVec.Normalize();
m_CollisionNormal = DistanceVec;
// 3. Calculate Relative Normal Velocity:
Body1Velocity = body1.GetObjectPhysics().GetVelocity();
Body2Velocity = body2.GetObjectPhysics().GetVelocity();
m_RelativeVelocity = Vector3.Subtract(Body1Velocity , Body2Velocity);
RelativeVelocityNormal = m_RelativeVelocity.DotProduct(m_CollisionNormal);
// 4. Test for collision
if((Math.abs(CollisionDistance) <= m_CollisionTolerance) && (RelativeVelocityNormal < 0.0))
{
retval = CollisionStatus.COLLISION;
}
else
if ((CollisionDistance < -m_CollisionTolerance) && (RelativeVelocityNormal < 0.0))
{
retval = CollisionStatus.PENETRATING_COLLISION;
}
else
if (CollisionDistance < -m_CollisionTolerance)
{
retval = CollisionStatus.PENETRATING;
}
else
{
retval = CollisionStatus.NOCOLLISION;
}
return retval;
}
Calculating Collisions
Now we will derive the formula used to calculate the force acting on the two colliding objects after
impact. The forces acting on the objects will be equal and opposite, according to Newton's third law
of motion.
The three equations we will need are listed below. The first two equations are Newton's second law
applied to both objects, with the force on one object the opposite of the other. The third equation
is the coefficient of restitution or “e,” which determines how elastic the collision is. A fully elastic
 
Search WWH ::




Custom Search