Game Development Reference

In-Depth Information

box.halfSize.x * real_abs(axis * box.getAxis(0)) +

box.halfSize.y * real_abs(axis * box.getAxis(1)) +

box.halfSize.z * real_abs(axis * box.getAxis(2));

}

bool overlapOnAxis(

const Box &one,

const Box &two,

const Vector3 &axis

)

{

// Project the half-size of one onto axis.

real oneProject = transformToAxis(one, axis);

real twoProject = transformToAxis(two, axis);

// Find the vector between the two centers.

Vector3 toCenter = two.getAxis(3) - one.getAxis(3);

// Project this onto the axis.

real distance = real_abs(toCenter * axis);

// Check for overlap.

return (distance < oneProject + twoProject);

}

For convex objects we can go one stage farther: if the objects are not touching,

then there must be at least one axis that would show this. Objects that are concave in

F
IGURE
13.16

The projection of two boxes onto separating axes.