Game Development Reference
In-Depth Information
F IGURE 13.9
The difference in contact normal for a plane and a half-space.
Excerpt from src/collide_fine.cpp
unsigned CollisionDetector::sphereAndTruePlane(
const Sphere &sphere,
const Plane &plane,
CollisionData *data
)
{
// Make sure we have contacts.
if (data->contactsLeft <= 0) return 0;
// Cache the sphere position.
Vector3 position = sphere.getAxis(3);
// Find the distance from the plane.
real centerDistance = plane.direction * position - plane.offset;
// Check if we're within radius.
if (centerDistance*centerDistance > sphere.radius*sphere.radius)
{
return 0;
}
// Check which side of the plane we're on.
Vector3 normal = plane.direction;
real penetration = -centerDistance;
if (centerDistance < 0)
{
normal *= -1;
penetration = -penetration;
}
Search Nedrilad ::




Custom Search