Game Development Reference
In-Depth Information
// size to hand.
Vector3 normal = midline * (((real)1.0)/size);
Contact* contact = data->contacts;
contact->contactNormal = normal;
contact->contactPoint = positionOne + midline * (real)0.5;
// Write the appropriate data.
contact->body[0] = one.body;
contact->body[1] = two.body;
contact->restitution = data->restitution;
contact->friction = data->friction;
return 1;
}
13.3.2
C OLLIDING A S PHERE AND A P LANE
Colliding a sphere and a plane is just as simple as colliding two spheres. The sphere
collides with the plane if the distance of the center of the sphere is farther from the
plane than the sphere's radius. The distance of a point from a plane is given by
d
=
p
·
l
l
where l is the normal vector of the plane and l is the offset of the plane. This is a
standard way to represent a plane in 3D geometry.
We can represent the plane in code as
class Plane : public Primitive
{
public:
Vector3 normal;
real offset;
};
Planes are almost always associated with immovable geometry rather than a rigid
body, so the rigid body pointer in the Primitive class will typically be NULL.
The algorithm takes a sphere and a plane and may add a contact to the contact
data. Again the algorithm is simple enough not to benefit from a separate early-out
algorithm.