Game Development Reference
In-Depth Information
penetration += sphere.radius;
// Create the contact - it has a normal in the plane direction.
Contact* contact = data->contacts;
contact->contactNormal = normal;
contact->penetration = penetration;
contact->contactPoint = position - plane.direction * centerDistance;
// Write the appropriate data.
contact->body[0] = sphere.body;
contact->body[1] = NULL;
contact->restitution = data->restitution;
contact->friction = data->friction;
return 1;
}
Both are implemented on the CD, but only the half-space is used in any of the demos.
13.3.3
C OLLIDING A B OX AND A P LANE
The last of the very simple contact generation algorithms is between a box and a
plane (strictly a half-space). This is the first algorithm that can return more than one
contact.
Remember that we are trying to use contacts that are as simple to process as pos-
sible. We prefer to use point-face contacts if we can. In this case we can. Rather than
return the contact of the face of one box with the half-space, we return four contacts
for each corner point with the half-space. Similarly, if an edge is colliding with the
plane, we treat it as two point-face contacts for each end of that edge. Thus there can
be up to four contacts, and each is a point-face contact. Figure 13.10 illustrates this.
We can find the set of contacts by simply checking each vertex of the box one by
one and generating a contact if it lies below the plane. 1
The check for each vertex looks just like the check we made with the sphere-plane
detector:
d
=
p
·
l
l
Because the vertices are only points, and have no radius, we simply need to check to
see whether the sign of d is positive or negative. A collision therefore occurs if
p
·
l < l
1. Generating contacts for a true plane, rather than a half-space, is somewhat more difficult because we
need to find the set of contacts on each side of the plane, determine which side the box is on, and generate
contacts for the opposite set. For a half-space we simply test whether vertices are through the plane.
Search Nedrilad ::




Custom Search