Game Development Reference
In-Depth Information
Vector3 position;
real radius;
The center point of the sphere is given by the offset from the origin of the rigid body,
the data for which is contained in the Primitive . The sphere implementation we'll
use looks like this:
class Sphere : public Primitive
real radius;
The algorithm takes two spheres and may generate a contact in the contact data.
Because the algorithm to determine whether the two spheres collide is part of de-
termining the contact data, we don't have a separate algorithm to provide an early
Excerpt from src/collide_fine.cpp
unsigned CollisionDetector::sphereAndSphere(
const Sphere &one,
const Sphere &two,
CollisionData *data
// Make sure we have contacts.
if (data->contactsLeft <= 0) return 0;
// Cache the sphere positions.
Vector3 positionOne = one.getAxis(3);
Vector3 positionTwo = two.getAxis(3);
// Find the vector between the objects.
Vector3 midline = positionOne - positionTwo;
real size = midline.magnitude();
// See if it is large enough.
if (size <= 0.0f || size >= one.radius+two.radius)
return 0;
// We manually create the normal, because we have the
Search Nedrilad ::

Custom Search