static inline Scalar penetrationOnAxis(const ShapeBox &boxA, const Transform &boxATransform, const ShapeBox &boxB, const Transform &boxBTransform, const Vec3 &axis, const Vec3 &separation) { Scalar projectionA = transformToAxis(boxA, boxATransform, axis); Scalar projectionB = transformToAxis(boxB, boxBTransform, axis); Scalar distance = abs( separation.dot(axis) ); return projectionA + projectionB - distance; }
/** * This function checks if the two boxes overlap * along the given axis. The final parameter toCentre * is used to pass in the vector between the boxes centre * points, to avoid having to recalculate it each time. */ static inline bool overlapOnAxis( const CollisionBox &one, const CollisionBox &two, const Vector3 &axis, const Vector3 &toCentre ) { // Project the half-size of one onto axis real oneProject = transformToAxis(one, axis); real twoProject = transformToAxis(two, axis); // Project this onto the axis real distance = real_abs(toCentre * axis); // Check for overlap return (distance < oneProject + twoProject); }
/* * This function checks if the two boxes overlap * along the given axis, returning the ammount of overlap. * The final parameter toCentre * is used to pass in the vector between the boxes centre * points, to avoid having to recalculate it each time. */ static inline real penetrationOnAxis( const CollisionBox &one, const CollisionBox &two, const Vector3 &axis, const Vector3 &toCentre ) { // Project the half-size of one onto axis real oneProject = transformToAxis(one, axis); real twoProject = transformToAxis(two, axis); // Project this onto the axis real distance = real_abs(toCentre * axis); // Return the overlap (i.e. positive indicates // overlap, negative indicates separation). return oneProject + twoProject - distance; }
bool IntersectionTests::boxAndHalfSpace( const CollisionBox &box, const CollisionPlane &plane ) { // Work out the projected radius of the box onto the plane direction real projectedRadius = transformToAxis(box, plane.direction); // Work out how far the box is from the origin real boxDistance = plane.direction * box.getAxis(3) - projectedRadius; // Check for the intersection return boxDistance <= plane.offset; }