Game Development Reference
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
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
const Sphere &one,
const Sphere &two,
// 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)
// We manually create the normal, because we have the