Support Forum       G3D Web Page     
Static Public Member Functions | List of all members
G3D::CollisionDetection Class Reference


Collision detection primitives and tools for building higher order collision detection schemes. More...

Static Public Member Functions

static Vector3 bounceDirection (const class Sphere &sphere, const Vector3 &velocity, const float collisionTime, const Vector3 &collisionLocation, const Vector3 &collisionNormal)
 
Finds the direction of bounce that a sphere would have when it intersects an object with the given time of collision, the collision location and the collision normal. More...
 
static Vector3 closestPointOnLineSegment (const Vector3 &v0, const Vector3 &v1, const Vector3 &point)
 
Finds the closest point on a line segment to a given point. More...
 
static Vector3 closestPointOnLineSegment (const Vector3 &v0, const Vector3 &v1, const Vector3 &edgeDirection, float edgeLength, const Vector3 &point)
 
Finds the closest point on a line segment to a given point. More...
 
static Vector3 closestPointOnTrianglePerimeter (const Vector3 &v0, const Vector3 &v1, const Vector3 &v2, const Vector3 &point)
 
Finds the closest point on the perimeter of the triangle to an external point; given a triangle defined by three points v0, v1, & v2, and the external point. More...
 
static Vector3 closestPointOnTrianglePerimeter (const Vector3 v[3], const Vector3 edgeDirection[3], const float edgeLength[3], const Vector3 &point, int &edgeIndex)
 
Finds the closest point on the perimeter of the triangle to an external point; given a triangle defined by the array of points v, its edge directions and their lengths, as well as the external point. More...
 
static void closestPointsBetweenLineAndLine (const Line &line1, const Line &line2, Vector3 &closest1, Vector3 &closest2)
 Calculates the closest points on two lines with each other. More...
 
static Vector3 closestPointToRectangle (const Vector3 &v0, const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, const Vector3 &point)
 
Finds the closest point in the rectangle to an external point; Given a rectangle defined by four points v0, v1, v2, & v3, and the external point. More...
 
static Vector3 closestPointToRectanglePerimeter (const Vector3 &v0, const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, const Vector3 &point)
 
Finds the closest point on the perimeter of the rectangle to an external point; given a rectangle defined by four points v0, v1, v2, & v3, and the external point. More...
 
static bool collisionLocationForMovingPointFixedAABox (const Vector3 &point, const Vector3 &velocity, const class AABox &box, Vector3 &outLocation, bool &inside=ignoreBool, Vector3 &normal=ignore)
 
Calculates time between the intersection of a moving point and a fixed Axis-Aligned Box (AABox). More...
 
static float collisionTimeForMovingPointFixedAABox (const Vector3 &point, const Vector3 &velocity, const class AABox &box, Vector3 &outLocation, bool &inside=ignoreBool, Vector3 &outNormal=ignore)
 
If the ray origin is inside the box, returns inf() but inside is set to true. More...
 
static float collisionTimeForMovingPointFixedBox (const Vector3 &point, const Vector3 &velocity, const class Box &box, Vector3 &outLocation, Vector3 &outNormal=ignore)
 
Calculates time between the intersection of a moving point and a fixed box. More...
 
static float collisionTimeForMovingPointFixedCapsule (const Vector3 &point, const Vector3 &velocity, const class Capsule &capsule, Vector3 &outLocation, Vector3 &outNormal=ignore)
 
Calculates time between the intersection of a moving point and a fixed capsule. More...
 
static float collisionTimeForMovingPointFixedPlane (const Vector3 &point, const Vector3 &velocity, const class Plane &plane, Vector3 &outLocation, Vector3 &outNormal=ignore)
 Calculates time between the intersection of a moving point and a fixed plane. More...
 
static float collisionTimeForMovingPointFixedRectangle (const Vector3 &point, const Vector3 &velocity, const Vector3 &v0, const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, Vector3 &outLocation, Vector3 &outNormal=ignore)
 
Calculates time between the intersection of a moving point and a fixed rectangle defined by the points v0, v1, v2, & v3. More...
 
static float collisionTimeForMovingPointFixedSphere (const Vector3 &point, const Vector3 &velocity, const class Sphere &sphere, Vector3 &outLocation, Vector3 &outNormal=ignore, bool solid=false)
 
Calculates time between the intersection of a moving point and a fixed sphere. More...
 
static float collisionTimeForMovingPointFixedTriangle (const Vector3 &orig, const Vector3 &dir, const Vector3 &v0, const Vector3 &v1, const Vector3 &v2)
 Calculates time between the intersection of a moving point and a fixed triangle. More...
 
static float collisionTimeForMovingPointFixedTriangle (const Vector3 &orig, const Vector3 &dir, const Vector3 &v0, const Vector3 &v1, const Vector3 &v2, Vector3 &location)
 Calculates time between the intersection of a moving point and a fixed triangle. More...
 
static float collisionTimeForMovingPointFixedTriangle (const Vector3 &orig, const Vector3 &dir, const Triangle &tri, Vector3 &location=ignore, Vector3 &normal=ignore)
 Calculates time between the intersection of a moving point and a fixed triangle. More...
 
static float collisionTimeForMovingPointFixedTriangle (const Vector3 &orig, const Vector3 &dir, const Vector3 &v0, const Vector3 &v1, const Vector3 &v2, Vector3 &location, Vector3 &normal)
 Calculates time between the intersection of a moving point and a fixed triangle. More...
 
static float collisionTimeForMovingSphereFixedBox (const class Sphere &sphere, const Vector3 &velocity, const class Box &box, Vector3 &outLocation, Vector3 &outNormal=ignore)
 
Calculates time between the intersection of a moving sphere and a fixed box. More...
 
static float collisionTimeForMovingSphereFixedCapsule (const class Sphere &sphere, const Vector3 &velocity, const class Capsule &capsule, Vector3 &outLocation, Vector3 &outNormal=ignore)
 
Calculates time between the intersection of a moving sphere and a fixed capsule. More...
 
static float collisionTimeForMovingSphereFixedPlane (const class Sphere &sphere, const Vector3 &velocity, const class Plane &plane, Vector3 &outLocation, Vector3 &outNormal=ignore)
 
Calculates time between the intersection of a moving sphere and a fixed triangle. More...
 
static float collisionTimeForMovingSphereFixedRectangle (const class Sphere &sphere, const Vector3 &velocity, const Vector3 &v0, const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, Vector3 &outLocation, Vector3 &outNormal=ignore)
 
Calculates time between the intersection of a moving sphere and a fixed rectangle defined by the points v0, v1, v2, & v3. More...
 
static float collisionTimeForMovingSphereFixedSphere (const Sphere &sphere, const Vector3 &velocity, const Sphere &fixedSphere, Vector3 &outLocation, Vector3 &outNormal=ignore)
 Calculates time between the intersection of a moving sphere and a fixed sphere. More...
 
static float collisionTimeForMovingSphereFixedTriangle (const class Sphere &sphere, const Vector3 &velocity, const Triangle &triangle, Vector3 &outLocation, float b[3]=(float *)&ignore, bool twoSided=false)
 
Calculates time between the intersection of a moving sphere and a fixed triangle. More...
 
static bool conservativeBoxBoxTest (const Vector3 &a, const Vector3 &b, const Vector3 &D)
 Performs a simple bounding sphere check between two boxes to determine whether these boxes could possibly intersect. More...
 
static void fillSolidBoxSolidBoxInfo (const Box &box1, const Box &box2, Vector3 &a, Vector3 &b, Vector3 &D, double *c, double *ca, double *ad, double *bd)
 Creates a set of standard information about two boxes in order to solve for their collision. More...
 
static bool fixedSolidBoxIntersectsFixedSolidBox (const Box &box1, const Box &box2, const int lastSeparatingAxis=-1)
 Determines whether two fixed solid boxes intersect. More...
 
static bool fixedSolidBoxIntersectsFixedTriangle (const AABox &box, const Triangle &triangle)
 
static bool fixedSolidSphereIntersectsFixedSolidBox (const Sphere &sphere, const Box &box)
 
Tests for the intersection of a fixed sphere and a fixed box. More...
 
static bool fixedSolidSphereIntersectsFixedSolidSphere (const Sphere &sphere1, const Sphere &sphere2)
 
Tests for the intersection of two fixed spheres. More...
 
static bool fixedSolidSphereIntersectsFixedTriangle (const Sphere &sphere, const Triangle &triangle)
 
static bool isPointInsideRectangle (const Vector3 &v0, const Vector3 &v1, const Vector3 &v2, const Vector3 &v3, const Vector3 &normal, const Vector3 &point)
 
Tests whether a point is inside a rectangle defined by the vertexes v0, v1, v2, & v3, and the rectangle's plane normal. More...
 
static bool isPointInsideTriangle (const Vector3 &v0, const Vector3 &v1, const Vector3 &v2, const Vector3 &normal, const Vector3 &point, float b[3], Vector3::Axis primaryAxis=Vector3::DETECT_AXIS)
 
Tests whether a point is contained within the triangle defined by v0, v1, and v2 and its plane's normal. More...
 
static bool isPointInsideTriangle (const Vector3 &v0, const Vector3 &v1, const Vector3 &v2, const Vector3 &normal, const Vector3 &point, Vector3::Axis primaryAxis=Vector3::DETECT_AXIS)
 
static bool movingSpherePassesThroughFixedBox (const Sphere &sphere, const Vector3 &velocity, const Box &box, double timeLimit=inf())
 
Tests for the intersection of a moving sphere and a fixed box in a given time limit. More...
 
static bool movingSpherePassesThroughFixedSphere (const Sphere &sphere, const Vector3 &velocity, const Sphere &fixedSphere, double timeLimit=inf())
 
Tests for the intersection of a moving sphere and a fixed sphere in a given time limit. More...
 
static bool parallelAxisForSolidBoxSolidBox (const double *ca, const double epsilon, int &axis1, int &axis2)
 Tests whether two boxes have axes that are parallel to each other. More...
 
static float penetrationDepthForFixedBoxFixedBox (const Box &box1, const Box &box2, Array< Vector3 > &contactPoints, Array< Vector3 > &contactNormals, const int lastSeparatingAxis=-1)
 Calculates the depth of penetration between two fixed boxes. More...
 
static float penetrationDepthForFixedBoxFixedPlane (const Box &box, const Plane &plane, Array< Vector3 > &contactPoints, Array< Vector3 > &contactNormals=ignoreArray)
 Calculates the depth of penetration between a fixed box and a fixed plane as well as the vertexes of the box that penetrate the plane and the plane normals at those intersections. More...
 
static float penetrationDepthForFixedSphereFixedBox (const Sphere &sphere, const Box &box, Array< Vector3 > &contactPoints, Array< Vector3 > &contactNormals=ignoreArray)
 Calculates the depth of penetration between a fixed sphere and a fixed box as well as the deepest point of the sphere that penetrates the box and the normal at that intersection. More...
 
static float penetrationDepthForFixedSphereFixedPlane (const Sphere &sphereA, const class Plane &planeB, Array< Vector3 > &contactPoints, Array< Vector3 > &contactNormals=ignoreArray)
 Calculates the depth of penetration between a Fixed Sphere and a Fixed Plane as well as the deepest point of the sphere that penetrates the plane and the plane normal at that intersection. More...
 
static float penetrationDepthForFixedSphereFixedSphere (const class Sphere &sphereA, const Sphere &sphereB, Array< Vector3 > &contactPoints, Array< Vector3 > &contactNormals=ignoreArray)
 Calculates the depth of penetration between two fixed spheres as well as the deepest point of Sphere A that penetrates Sphere B. More...
 
static float projectedDistanceForSolidBoxSolidBox (const int separatingAxisIndex, const Vector3 &a, const Vector3 &b, const Vector3 &D, const double *c, const double *ca, const double *ad, const double *bd)
 Calculates the projected distance between the two boxes along the specified separating axis, negative distances correspond to an overlap along that separating axis. More...
 
static bool rayAABox (const Ray &ray, const Vector3 &invDir, const AABox &box, const Vector3 &boxCenter, float boundingRadiusSquared, Vector3 &location, bool &inside)
 
Calculates intersection of a ray and a static Axis-Aligned Box (AABox). More...
 
static Vector3 separatingAxisForSolidBoxSolidBox (const int separatingAxisIndex, const Box &box1, const Box &box2)
 Converts an index [0, 15] to the corresponding separating axis. More...
 
static Vector3 slideDirection (const class Sphere &sphere, const Vector3 &velocity, const float collisionTime, const Vector3 &collisionLocation)
 
Finds the direction of slide given a moving sphere, its velocity, the time of collision and the collision location. More...
 

Detailed Description


Collision detection primitives and tools for building higher order collision detection schemes.

These routines provide moving and static collision detection. Moving collision detection allows the calculation of collisions that occur during a period of time – as opposed to the intersection of two static bodies.

Moving collision detection routines detect collisions between only static primitives and moving spheres or points. Since the reference frame can be user defined, these functions can be used to detect the collision between two moving bodies by subtracting the velocity vector of one object from the velocity vector of the sphere or point the detection is to occur with. This unified velocity vector will act as if both objects are moving simultaneously.

Collisions are detected for single-sided objects only. That is, no collision is detected when leaving a primitive or passing through a plane or triangle opposite the normal... except for the point-sphere calculation or when otherwise noted.

For a sphere, the collision location returned is the point in world space where the surface of the sphere and the fixed object meet. It is not the position of the center of the sphere at the time of the collision.

The collision normal returned is the surface normal to the fixed object at the collision location.

Static Collision Detection: (Neither object is moving)

Point3LineSegmentRay *LinePlaneTriangleSphereCylinderCapsuleAABoxBox
Point3P3::== V3::fuzzy distance
LineSegmentLS::closestPoint LS::distance CD
Ray *Ray::closestPoint Ray::distance
LineLine::closestPoint Line::distanceCD
Plane
Triangle
SphereSphere::containsCD , R::timeCDCD
CylinderCylinder::contains
CapsuleCapsule::contains CD
AABoxAABox::containsCD
BoxBox::contains(treat as Ray)CD(treat as Ray)CD CDCDNone (use OPCODE)CD CDCD

Moving Collision Detection:

* Note: Moving collision detection against certain primitives is equivalent to static collision detection against a bigger primitive. Ray, Line Segment == moving Point''; Capsule ==moving Sphere''; Plane == `‘moving Line’'

Deprecated:
Routines moving to the G3D::Intersect class in G3D 9.0

Member Function Documentation

◆ bounceDirection()

static Vector3 G3D::CollisionDetection::bounceDirection ( const class Sphere sphere,
const Vector3 velocity,
const float  collisionTime,
const Vector3 collisionLocation,
const Vector3 collisionNormal 
)
static


Finds the direction of bounce that a sphere would have when it intersects an object with the given time of collision, the collision location and the collision normal.

Note
This function works like a pong style ball bounce.
Parameters
sphereMoving sphere.
velocitySphere's velocity.
collisionTimeTime of collision.
collisionLocationCollision location.
collisionNormalSurface collision normal.
Returns
Direction of bounce.

◆ closestPointOnLineSegment() [1/2]

static Vector3 G3D::CollisionDetection::closestPointOnLineSegment ( const Vector3 v0,
const Vector3 v1,
const Vector3 point 
)
static


Finds the closest point on a line segment to a given point.

Parameters
v0line vertex 1.
v1line vertex 2.
pointExternal point.
Returns
Closests point to point on the line segment.

◆ closestPointOnLineSegment() [2/2]

static Vector3 G3D::CollisionDetection::closestPointOnLineSegment ( const Vector3 v0,
const Vector3 v1,
const Vector3 edgeDirection,
float  edgeLength,
const Vector3 point 
)
static


Finds the closest point on a line segment to a given point.

Note
This is an optimization to closestPointOnLineSegment. Edge length and direction can be used in this function if already pre-calculated. This prevents doing the same work twice.
Parameters
v0line vertex 0.
v1line vertex 1.
edgeDirectionThe direction of the segment (unit length).
edgeLengthThe length of the segment.
pointExternal point.
Returns
Closests point to point on the line segment.

◆ closestPointOnTrianglePerimeter() [1/2]

static Vector3 G3D::CollisionDetection::closestPointOnTrianglePerimeter ( const Vector3 v0,
const Vector3 v1,
const Vector3 v2,
const Vector3 point 
)
static


Finds the closest point on the perimeter of the triangle to an external point; given a triangle defined by three points v0, v1, & v2, and the external point.

Parameters
v0Triangle vertex 0.
v1Triangle vertex 1.
v2Triangle vertex 2.
pointExternal point.
Returns
Closests point to point on the perimeter of the triangle.

◆ closestPointOnTrianglePerimeter() [2/2]

static Vector3 G3D::CollisionDetection::closestPointOnTrianglePerimeter ( const Vector3  v[3],
const Vector3  edgeDirection[3],
const float  edgeLength[3],
const Vector3 point,
int &  edgeIndex 
)
static


Finds the closest point on the perimeter of the triangle to an external point; given a triangle defined by the array of points v, its edge directions and their lengths, as well as the external point.

Note
This is an optimization to closestPointToTrianglePerimeter. Edge length and direction can be used in this function if already pre-calculated. This prevents doing the same work twice.
Parameters
vTriangle vertices.
pointExternal point.
edgeIndexThe point lies on the edge between v[edgeIndex] and v[(edgeIndex + 1) % 3]
Returns
Closest point to point on the perimeter of the triangle.

◆ closestPointsBetweenLineAndLine()

static void G3D::CollisionDetection::closestPointsBetweenLineAndLine ( const Line line1,
const Line line2,
Vector3 closest1,
Vector3 closest2 
)
static

Calculates the closest points on two lines with each other.

If the lines are parallel then using the starting point, else calculate the closest point on each line to the other.

Note
This is very similiar to calculating the intersection of two lines. Logically then, the two points calculated would be identical if calculated with inifinite precision, but with the finite precision of floating point calculations, these values could (will) differ as the line slope approaches zero or inifinity.
Referenced Code: variables and algorithm based on derivation at the following website:
http://softsurfer.com/Archive/algorithm_0106/algorithm_0106.htm
Parameters
line1Line 1.
line2Line 2.
closest1Closest point on line 1.
closest2Closest point on line 2.

◆ closestPointToRectangle()

static Vector3 G3D::CollisionDetection::closestPointToRectangle ( const Vector3 v0,
const Vector3 v1,
const Vector3 v2,
const Vector3 v3,
const Vector3 point 
)
static


Finds the closest point in the rectangle to an external point; Given a rectangle defined by four points v0, v1, v2, & v3, and the external point.

Parameters
v0Rectangle vertex 1.
v1Rectangle vertex 2.
v2Rectangle vertex 3
v3Rectangle vertex 4.
pointExternal point.
Returns
Closet point in the rectangle to the external point.

◆ closestPointToRectanglePerimeter()

static Vector3 G3D::CollisionDetection::closestPointToRectanglePerimeter ( const Vector3 v0,
const Vector3 v1,
const Vector3 v2,
const Vector3 v3,
const Vector3 point 
)
static


Finds the closest point on the perimeter of the rectangle to an external point; given a rectangle defined by four points v0, v1, v2, & v3, and the external point.

Parameters
v0Rectangle vertex 1.
v1Rectangle vertex 2.
v2Rectangle vertex 3.
v3Rectangle vertex 4.
pointExternal point.
Returns
Closests point to point on the perimeter of the rectangle.

◆ collisionLocationForMovingPointFixedAABox()

static bool G3D::CollisionDetection::collisionLocationForMovingPointFixedAABox ( const Vector3 point,
const Vector3 velocity,
const class AABox box,
Vector3 outLocation,
bool &  inside = ignoreBool,
Vector3 normal = ignore 
)
static


Calculates time between the intersection of a moving point and a fixed Axis-Aligned Box (AABox).

Note
Avoids the sqrt from collisionTimeForMovingPointFixedAABox.
Parameters
pointMoving point.
velocitySphere's velocity.
boxFixed AAbox.
outLocationLocation of collision. [Post Condition]
insideDoes the ray originate inside the box? [Post Condition]
normalBox's surface normal to collision [Post Condition]
Returns
Time til collision. If there is no collision then the return value will be inf().

Referenced by G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::Node::intersectRay(), and G3D::KDTree< T, BoundsFunc, HashFunc, EqualsFunc >::Node::intersects().

◆ collisionTimeForMovingPointFixedAABox()

static float G3D::CollisionDetection::collisionTimeForMovingPointFixedAABox ( const Vector3 point,
const Vector3 velocity,
const class AABox box,
Vector3 outLocation,
bool &  inside = ignoreBool,
Vector3 outNormal = ignore 
)
static


If the ray origin is inside the box, returns inf() but inside is set to true.

Beta API

Referenced Code: Andrew Woo, from "Graphics Gems", Academic Press, 1990
Referenced Code: Optimized code by Pierre Terdiman, 2000 (~20-30% faster on Celeron 500)
Referenced Code: Epsilon value added by Klaus Hartmann
Referenced Code: http://www.codercorner.com/RayAABB.cpp

◆ collisionTimeForMovingPointFixedBox()

static float G3D::CollisionDetection::collisionTimeForMovingPointFixedBox ( const Vector3 point,
const Vector3 velocity,
const class Box box,
Vector3 outLocation,
Vector3 outNormal = ignore 
)
static


Calculates time between the intersection of a moving point and a fixed box.

Note
If the point is already inside the box, no collision: inf is returned.
Parameters
pointMoving point.
velocitySphere's velocity.
boxFixed box.
outLocationPosition of collision. [Post Condition]
outNormalBox's surface normal to collision [Post Condition]
Returns
Time til collision. If there is no collision then the return value will be inf().

◆ collisionTimeForMovingPointFixedCapsule()

static float G3D::CollisionDetection::collisionTimeForMovingPointFixedCapsule ( const Vector3 point,
const Vector3 velocity,
const class Capsule capsule,
Vector3 outLocation,
Vector3 outNormal = ignore 
)
static


Calculates time between the intersection of a moving point and a fixed capsule.

Parameters
pointMoving point.
velocityPoint's velocity.
capsuleFixed capsule.
outLocationLocation of collision. [Post Condition]
outNormalCapsule's surface normal to collision [Post Condition]
Returns
Time til collision. If there is no collision then the return value will be inf().

◆ collisionTimeForMovingPointFixedPlane()

static float G3D::CollisionDetection::collisionTimeForMovingPointFixedPlane ( const Vector3 point,
const Vector3 velocity,
const class Plane plane,
Vector3 outLocation,
Vector3 outNormal = ignore 
)
static

Calculates time between the intersection of a moving point and a fixed plane.

Note
This is only a one sided collision test. The side defined by the plane's surface normal is the only one tested. For a two sided collision, call the function once for each side's surface normal.
Parameters
pointMoving point.
velocityPoint's velocity.
planeFixed plane.
outLocationLocation of collision. [Post Condition] (Infinite vector on no collision)
outNormalPlane's surface normal. [Post Condition]
Returns
Time til collision. If there is no collision then the return value will be inf().

◆ collisionTimeForMovingPointFixedRectangle()

static float G3D::CollisionDetection::collisionTimeForMovingPointFixedRectangle ( const Vector3 point,
const Vector3 velocity,
const Vector3 v0,
const Vector3 v1,
const Vector3 v2,
const Vector3 v3,
Vector3 outLocation,
Vector3 outNormal = ignore 
)
static


Calculates time between the intersection of a moving point and a fixed rectangle defined by the points v0, v1, v2, & v3.

Note
This is only a one sided collision test. The side defined by the rectangle's surface normal is the only one tested. For a two sided collision, call the function once for each side's surface normal.
Parameters
pointMoving point.
velocitySphere's velocity.
v0Rectangle vertex 1.
v1Rectangle vertex 2.
v2Rectangle vertex 3
v3Rectangle vertex 4.
outLocationLocation of collision [Post Condition]
outNormalRectangle's surface normal. [Post Condition]
Returns
Time til collision. If there is no collision then the return value will be inf().

◆ collisionTimeForMovingPointFixedSphere()

static float G3D::CollisionDetection::collisionTimeForMovingPointFixedSphere ( const Vector3 point,
const Vector3 velocity,
const class Sphere sphere,
Vector3 outLocation,
Vector3 outNormal = ignore,
bool  solid = false 
)
static


Calculates time between the intersection of a moving point and a fixed sphere.

Note
When ray is starts inside the rectangle, the exiting intersection is detected.
Parameters
pointMoving point.
velocityPoint's velocity.
sphereFixed Sphere.
outLocationLocation of collision. [Post Condition]
outNormalSphere's surface normal to collision [Post Condition]
solidIf true, rays inside the sphere immediately intersect (good for collision detection). If false, they hit the opposite side of the sphere (good for ray tracing).
Returns
Time until collision. If there is no collision then the return value will be inf().

◆ collisionTimeForMovingPointFixedTriangle() [1/4]

static float G3D::CollisionDetection::collisionTimeForMovingPointFixedTriangle ( const Vector3 orig,
const Vector3 dir,
const Vector3 v0,
const Vector3 v1,
const Vector3 v2 
)
inlinestatic

Calculates time between the intersection of a moving point and a fixed triangle.

Note
This is only a one sided collision test. The side defined by the triangle's surface normal is the only one tested. For a two sided collision, call the function once for each side's surface normal.
Parameters
origMoving point.
dirPoint's velocity.
v0Triangle vertex 1.
v1Triangle vertex 2.
v2Triangle vertex 3
Returns
Time til collision. If there is no collision then the return value will be inf().

Referenced by collisionTimeForMovingPointFixedTriangle().

◆ collisionTimeForMovingPointFixedTriangle() [2/4]

static float G3D::CollisionDetection::collisionTimeForMovingPointFixedTriangle ( const Vector3 orig,
const Vector3 dir,
const Vector3 v0,
const Vector3 v1,
const Vector3 v2,
Vector3 location 
)
inlinestatic

Calculates time between the intersection of a moving point and a fixed triangle.

Note
This is only a one sided collision test. The side defined by the triangle's surface normal is the only one tested. For a two sided collision, call the function once for each side's surface normal.
Parameters
origMoving point.
dirPoint's velocity.
v0Triangle vertex 1.
v1Triangle vertex 2.
v2Triangle vertex 3
locationLocation of collision. [Post Condition] (Infinite vector on no collision)
Returns
Time til collision. If there is no collision then the return value will be inf().

◆ collisionTimeForMovingPointFixedTriangle() [3/4]

static float G3D::CollisionDetection::collisionTimeForMovingPointFixedTriangle ( const Vector3 orig,
const Vector3 dir,
const Triangle tri,
Vector3 location = ignore,
Vector3 normal = ignore 
)
inlinestatic

Calculates time between the intersection of a moving point and a fixed triangle.

Note
This is only a one sided collision test. The side defined by the triangle's surface normal is the only one tested. For a two sided collision, call the function once for each side's surface normal.
Parameters
origMoving point.
dirPoint's velocity.
triFixed triangle.
locationLocation of collision. [Post Condition] (Infinite vector on no collision)
normalTriangle's surface normal. [Post Condition]
Returns
Time til collision. If there is no collision then the return value will be inf().

◆ collisionTimeForMovingPointFixedTriangle() [4/4]

static float G3D::CollisionDetection::collisionTimeForMovingPointFixedTriangle ( const Vector3 orig,
const Vector3 dir,
const Vector3 v0,
const Vector3 v1,
const Vector3 v2,
Vector3 location,
Vector3 normal 
)
inlinestatic

Calculates time between the intersection of a moving point and a fixed triangle.

Note
This is only a one sided collision test. The side defined by the triangle's surface normal is the only one tested. For a two sided collision, call the function once for each side's surface normal.
Parameters
origMoving point.
dirPoint's velocity.
v0Triangle vertex 1.
v1Triangle vertex 2.
v2Triangle vertex 3
locationLocation of collision. [Post Condition] (Infinite vector on no collision)
normalTriangle's surface normal. [Post Condition]
Returns
Time til collision. If there is no collision then the return value will be inf().

◆ collisionTimeForMovingSphereFixedBox()

static float G3D::CollisionDetection::collisionTimeForMovingSphereFixedBox ( const class Sphere sphere,
const Vector3 velocity,
const class Box box,
Vector3 outLocation,
Vector3 outNormal = ignore 
)
static


Calculates time between the intersection of a moving sphere and a fixed box.

Note
This function will not detect an intersection between a moving object that is already interpenetrating the fixed object.
Parameters
sphereMoving sphere.
velocitySphere's velocity.
boxFixed box.
outLocationLocation of collision – not center position of sphere at the collision time. [Post Condition]
outNormalBox's surface normal to collision [Post Condition]
Returns
Time til collision. If there is no collision then the return value will be inf().

◆ collisionTimeForMovingSphereFixedCapsule()

static float G3D::CollisionDetection::collisionTimeForMovingSphereFixedCapsule ( const class Sphere sphere,
const Vector3 velocity,
const class Capsule capsule,
Vector3 outLocation,
Vector3 outNormal = ignore 
)
static


Calculates time between the intersection of a moving sphere and a fixed capsule.

Note
This won't detect a collision if the sphere is already interpenetrating the capsule.
Parameters
sphereMoving sphere.
velocitySphere's velocity.
capsuleFixed capsule.
outLocationLocation of collision – not center position of sphere at the collision time. [Post Condition]
outNormalCapsule's surface normal to the collision [Post Condition]
Returns
Time til collision. If there is no collision then the return value will be inf().

◆ collisionTimeForMovingSphereFixedPlane()

static float G3D::CollisionDetection::collisionTimeForMovingSphereFixedPlane ( const class Sphere sphere,
const Vector3 velocity,
const class Plane plane,
Vector3 outLocation,
Vector3 outNormal = ignore 
)
static


Calculates time between the intersection of a moving sphere and a fixed triangle.

Parameters
sphereMoving sphere.
velocitySphere's velocity.
planeFixed Plane.
outLocationLocation of collision – not center position of sphere at the collision time. [Post Condition]
outNormalBox's surface normal to collision [Post Condition]
Returns
Time til collision. If there is no collision then the return value will be inf().

◆ collisionTimeForMovingSphereFixedRectangle()

static float G3D::CollisionDetection::collisionTimeForMovingSphereFixedRectangle ( const class Sphere sphere,
const Vector3 velocity,
const Vector3 v0,
const Vector3 v1,
const Vector3 v2,
const Vector3 v3,
Vector3 outLocation,
Vector3 outNormal = ignore 
)
static


Calculates time between the intersection of a moving sphere and a fixed rectangle defined by the points v0, v1, v2, & v3.

Parameters
sphereMoving sphere.
velocitySphere's velocity.
v0Rectangle vertex 1.
v1Rectangle vertex 2.
v2Rectangle vertex 3
v3Rectangle vertex 4.
outLocationLocation of collision – not center position of sphere at the collision time. [Post Condition]
outNormalBox's surface normal to collision [Post Condition]
Returns
Time til collision. If there is no collision then the return value will be inf().

◆ collisionTimeForMovingSphereFixedSphere()

static float G3D::CollisionDetection::collisionTimeForMovingSphereFixedSphere ( const Sphere sphere,
const Vector3 velocity,
const Sphere fixedSphere,
Vector3 outLocation,
Vector3 outNormal = ignore 
)
static

Calculates time between the intersection of a moving sphere and a fixed sphere.

If they are already interpenetrating, returns 0 and location is the closest point on the surface of the fixed sphere to the center of the moving sphere.

Parameters
sphereMoving sphere.
velocitySphere's velocity.
fixedSphereFixed Sphere.
outLocationLocation of collision – not center position of sphere at the collision time. [Post Condition]
outNormalMoving sphere's surface normal to collision [Post Condition]
Returns
Time until collision. If there is no collision then the return value will be inf().

◆ collisionTimeForMovingSphereFixedTriangle()

static float G3D::CollisionDetection::collisionTimeForMovingSphereFixedTriangle ( const class Sphere sphere,
const Vector3 velocity,
const Triangle triangle,
Vector3 outLocation,
float  b[3] = (float *)&ignore,
bool  twoSided = false 
)
static


Calculates time between the intersection of a moving sphere and a fixed triangle.

Parameters
sphereThe moving sphere.
velocityThe sphere's velocity.
triangleSingle-sided fixed triangle.
outLocationLocation of collision, if collision occurs – not center position of sphere at the collision time. If there is interpenetration at the start, this point may be inside the sphere.
bBarycentric coordinates. These are not valid unless collision occurs.
Returns
Time until collision. If there is no collision then the return value will be finf().

◆ conservativeBoxBoxTest()

static bool G3D::CollisionDetection::conservativeBoxBoxTest ( const Vector3 a,
const Vector3 b,
const Vector3 D 
)
static

Performs a simple bounding sphere check between two boxes to determine whether these boxes could possibly intersect.

This is a very cheap operation (three dot products, two sqrts and a few others). If it returns true, an intersection is possible, but not necessarily guaranteed.

Parameters
aVector from box A's center to an outer vertex
bVector from box B's center to an outer vertex
DDistance between the centers of the two boxes
Returns
true - if possible intersection
false - otherwise (This does not guarantee an intersection)

◆ fillSolidBoxSolidBoxInfo()

static void G3D::CollisionDetection::fillSolidBoxSolidBoxInfo ( const Box box1,
const Box box2,
Vector3 a,
Vector3 b,
Vector3 D,
double *  c,
double *  ca,
double *  ad,
double *  bd 
)
static

Creates a set of standard information about two boxes in order to solve for their collision.

This information includes a vector to the radius of the bounding sphere for each box, the vector between each boxes' center and a series of dot products between differing important vectors. These dot products include those between the axes of both boxes (signed and unsigned values), and the dot products between all the axes of box1 and the boxes' center vector and box2 and the boxes' center vector.

Precondition
The following space requirements must be met:
  • c[] 9 elements
  • ca[] 9 elements
  • ad[] 3 elements
  • bd[] 3 elements
Referenced Code: dobted from David Eberly's papers, variables used in this function
correspond to variables used in pages 6 and 7 in the pdf http://www.magic-software.com/Intersection.html http://www.magic-software.com/Documentation/DynamicCollisionDetection.pdf
Note
Links are out-dated. (Kept to preserve origin and authorship)
Parameters
box1Box 1
box2Box 2
aBox 1's bounding sphere vector
bBox 2's bounding sphere vector
DVector between Box 1 and Box 2's center points
cPointer to array of dot products of the axes of Box 1 and Box 2.
caPointer to array of unsigned dot products of the axes of Box 1 and Box 2.
adPointer to array of dot products of Box 1 axes and D.
bdPointer to array of dot products of Box 2 axes and D.

◆ fixedSolidBoxIntersectsFixedSolidBox()

static bool G3D::CollisionDetection::fixedSolidBoxIntersectsFixedSolidBox ( const Box box1,
const Box box2,
const int  lastSeparatingAxis = -1 
)
static

Determines whether two fixed solid boxes intersect.

Note
To speed up collision detection, the lastSeparatingAxis from the previous time step can be passed in and that plane can be checked first. If the separating axis was not saved, or if the two boxes intersected then lastSeparatingAxis should equal -1.
Referenced Code: Adobted from David Eberly's papers, variables used in this function
correspond to variables used in pages 6 and 7 in the pdf http://www.magic-software.com/Intersection.html http://www.magic-software.com/Documentation/DynamicCollisionDetection.pdf
Parameters
box1Box 1.
box2Box 2.
lastSeparatingAxisLast separating axis. (optimization - see note)
Returns
true - Intersection.
false - otherwise.

◆ fixedSolidBoxIntersectsFixedTriangle()

static bool G3D::CollisionDetection::fixedSolidBoxIntersectsFixedTriangle ( const AABox box,
const Triangle triangle 
)
static

◆ fixedSolidSphereIntersectsFixedSolidBox()

static bool G3D::CollisionDetection::fixedSolidSphereIntersectsFixedSolidBox ( const Sphere sphere,
const Box box 
)
static


Tests for the intersection of a fixed sphere and a fixed box.

Parameters
sphereFixed sphere.
boxFixed box.
Returns
true - if the two objects touch.
false - if there is no intersection.

◆ fixedSolidSphereIntersectsFixedSolidSphere()

static bool G3D::CollisionDetection::fixedSolidSphereIntersectsFixedSolidSphere ( const Sphere sphere1,
const Sphere sphere2 
)
static


Tests for the intersection of two fixed spheres.

Parameters
sphere1Fixed sphere 1.
sphere2Fixed sphere 2.
Returns
true - if the two spheres touch.
false - if there is no intersection.

◆ fixedSolidSphereIntersectsFixedTriangle()

static bool G3D::CollisionDetection::fixedSolidSphereIntersectsFixedTriangle ( const Sphere sphere,
const Triangle triangle 
)
static

◆ isPointInsideRectangle()

static bool G3D::CollisionDetection::isPointInsideRectangle ( const Vector3 v0,
const Vector3 v1,
const Vector3 v2,
const Vector3 v3,
const Vector3 normal,
const Vector3 point 
)
static


Tests whether a point is inside a rectangle defined by the vertexes v0, v1, v2, & v3, and the rectangle's plane normal.

Parameters
v0Rectangle vertex 1.
v1Rectangle vertex 2.
v2Rectangle vertex 3.
v3Rectangle vertex 4.
normalNormal to rectangle's plane.
pointThe point in question.
Returns
true - if point is inside the rectangle.
false - otherwise

◆ isPointInsideTriangle() [1/2]

static bool G3D::CollisionDetection::isPointInsideTriangle ( const Vector3 v0,
const Vector3 v1,
const Vector3 v2,
const Vector3 normal,
const Vector3 point,
float  b[3],
Vector3::Axis  primaryAxis = Vector3::DETECT_AXIS 
)
static


Tests whether a point is contained within the triangle defined by v0, v1, and v2 and its plane's normal.

Parameters
v0Triangle vertex 0.
v1Triangle vertex 1.
v2Triangle vertex 2.
normalNormal to triangle's plane.
pointThe point in question.
primaryAxisPrimary axis of triangle. This will be detected if not given. This parameter is provided as an optimization.
bBarycentric coordinates; b[i] is the weight on v[i]
Returns
true - if point is inside the triangle.
false - otherwise

Referenced by isPointInsideTriangle().

◆ isPointInsideTriangle() [2/2]

static bool G3D::CollisionDetection::isPointInsideTriangle ( const Vector3 v0,
const Vector3 v1,
const Vector3 v2,
const Vector3 normal,
const Vector3 point,
Vector3::Axis  primaryAxis = Vector3::DETECT_AXIS 
)
inlinestatic

◆ movingSpherePassesThroughFixedBox()

static bool G3D::CollisionDetection::movingSpherePassesThroughFixedBox ( const Sphere sphere,
const Vector3 velocity,
const Box box,
double  timeLimit = inf() 
)
static


Tests for the intersection of a moving sphere and a fixed box in a given time limit.

Note
Returns true if any part of the sphere is inside the box during the time period (inf means "ever"). Useful for performing bounding-box collision detection.
Parameters
sphereMoving sphere.
velocityVelocity of moving sphere.
boxFixed box.
timeLimitTime limit for intersection test.
Returns
true - if the two objects will touch.
false - if there is no intersection.

◆ movingSpherePassesThroughFixedSphere()

static bool G3D::CollisionDetection::movingSpherePassesThroughFixedSphere ( const Sphere sphere,
const Vector3 velocity,
const Sphere fixedSphere,
double  timeLimit = inf() 
)
static


Tests for the intersection of a moving sphere and a fixed sphere in a given time limit.

Note
This function will not detect an intersection between a moving object that is already interpenetrating the fixed object.
Parameters
sphereMoving sphere.
velocityVelocity of moving sphere.
fixedSphereFixed sphere.
timeLimitTime limit for intersection test.
Returns
true - if the two spheres will touch.
false - if there is no intersection.

◆ parallelAxisForSolidBoxSolidBox()

static bool G3D::CollisionDetection::parallelAxisForSolidBoxSolidBox ( const double *  ca,
const double  epsilon,
int &  axis1,
int &  axis2 
)
static

Tests whether two boxes have axes that are parallel to each other.

If they are, axis1 and axis2 are set to be the parallel axes for both box1 and box2 respectively.

Parameters
caDot products of each of the boxes axes
epsilonFudge factor (small unit by which the dot products may vary and still be considered zero).
axis1Parallel Axis 1. [Post Condition]
axis2Parallel Axis 2. [Post Condition]
Returns
true - If boxes have a parallel axis
false - otherwise.

◆ penetrationDepthForFixedBoxFixedBox()

static float G3D::CollisionDetection::penetrationDepthForFixedBoxFixedBox ( const Box box1,
const Box box2,
Array< Vector3 > &  contactPoints,
Array< Vector3 > &  contactNormals,
const int  lastSeparatingAxis = -1 
)
static

Calculates the depth of penetration between two fixed boxes.

Contact normal faces away from box1 and into box2. If there is contact, only one contact point is returned. The minimally violated separating plane is computed

  • if the separating axis corresponds to a face the contact point is half way between the deepest vertex and the face
  • if the separating axis corresponds to two edges the contact point is the midpoint of the smallest line segment between the two edge lines
Note
This is very similiar to calculating the intersection of two lines. Logically then, the two points calculated would be identical if calculated with inifinite precision, but with the finite precision of floating point calculations, these values could (will) differ as the line slope approaches zero or inifinity.
Referenced Code: adobted from David Eberly's papers, variables used in this function
correspond to variables used in pages 6 and 7 in the pdf http://www.magic-software.com/Intersection.html http://www.magic-software.com/Documentation/DynamicCollisionDetection.pdf
Parameters
box1Box 1
box2Box 2
contactPointsContact point between boxes. [Post Condition]
contactNormalsSurface normal at contact point. [Post Condition]
lastSeparatingAxisLast separating axis. (Used for optimization)
Returns
Depth of penetration between the two boxes. If there is no intersection between the boxes, then a negative value is returned.

◆ penetrationDepthForFixedBoxFixedPlane()

static float G3D::CollisionDetection::penetrationDepthForFixedBoxFixedPlane ( const Box box,
const Plane plane,
Array< Vector3 > &  contactPoints,
Array< Vector3 > &  contactNormals = ignoreArray 
)
static

Calculates the depth of penetration between a fixed box and a fixed plane as well as the vertexes of the box that penetrate the plane and the plane normals at those intersections.

Parameters
boxFixed Box.
planeFixed Plane.
contactPointsBox points that penetrate the plane. [Post Condition]
contactNormalsNormals at penetration points [Post Condition]
Returns
Depth of penetration. If there is no intersection between the objects then the depth will be a negative value.

◆ penetrationDepthForFixedSphereFixedBox()

static float G3D::CollisionDetection::penetrationDepthForFixedSphereFixedBox ( const Sphere sphere,
const Box box,
Array< Vector3 > &  contactPoints,
Array< Vector3 > &  contactNormals = ignoreArray 
)
static

Calculates the depth of penetration between a fixed sphere and a fixed box as well as the deepest point of the sphere that penetrates the box and the normal at that intersection.

Note
There are three possible intersections between a sphere and box.
  • Sphere completely contained in the box
  • Sphere intersects one edge
  • Sphere intersects one vertex

The contact point and contact normal vary for each of these situations.

  • Sphere contained in Box:
    • Normal is based on side of least penetration (as is the depth calculation).
    • Point is based on center of sphere
  • Sphere intersects one edge
    • Normal is based on vector from the box center to the point of depth.
    • Point is closest point to the sphere on the line
  • Sphere intersects one vertex
    • Normal is based on vector from the box center to the vertex of penetration.
    • Point is vertex of penetration.
Referenced Code: Adapted from Jim Arvo's method in Graphics Gems
See also http://www.win.tue.nl/~gino/solid/gdc2001depth.pdf
Parameters
sphereFixed Sphere.
boxFixed Box.
contactPointsSphere point that penetrates the box. [Post Condition]
contactNormalsNormal at the penetration point. [Post Condition]
Returns
Depth of penetration. If there is no intersection between the objects then the depth will be a negative value.

◆ penetrationDepthForFixedSphereFixedPlane()

static float G3D::CollisionDetection::penetrationDepthForFixedSphereFixedPlane ( const Sphere sphereA,
const class Plane planeB,
Array< Vector3 > &  contactPoints,
Array< Vector3 > &  contactNormals = ignoreArray 
)
static

Calculates the depth of penetration between a Fixed Sphere and a Fixed Plane as well as the deepest point of the sphere that penetrates the plane and the plane normal at that intersection.

Parameters
sphereAFixed Sphere.
planeBFixed Plane.
contactPointsSphere point that penetrates the plane. [Post Condition]
contactNormalsNormal at penetration point. [Post Condition]
Returns
Depth of penetration. If there is no intersection between the objects then the depth will be a negative value.

◆ penetrationDepthForFixedSphereFixedSphere()

static float G3D::CollisionDetection::penetrationDepthForFixedSphereFixedSphere ( const class Sphere sphereA,
const Sphere sphereB,
Array< Vector3 > &  contactPoints,
Array< Vector3 > &  contactNormals = ignoreArray 
)
static

Calculates the depth of penetration between two fixed spheres as well as the deepest point of Sphere A that penetrates Sphere B.

The normal returned points away from the object A, although it may represent a perpendicular to either the faces of object B or object A depending on their relative orientations.

Parameters
sphereAFixed Sphere A.
sphereBFixed Sphere B.
contactPointsSphere A's deepest point that penetrates Sphere B. [Post Condition]
contactNormalsNormal at penetration point. [Post Condition]
Returns
Depth of penetration. If there is no intersection between the objects then the depth will be a negative value.

◆ projectedDistanceForSolidBoxSolidBox()

static float G3D::CollisionDetection::projectedDistanceForSolidBoxSolidBox ( const int  separatingAxisIndex,
const Vector3 a,
const Vector3 b,
const Vector3 D,
const double *  c,
const double *  ca,
const double *  ad,
const double *  bd 
)
static

Calculates the projected distance between the two boxes along the specified separating axis, negative distances correspond to an overlap along that separating axis.

The distance is not divided by denominator dot(L, L), see penetrationDepthForFixedSphereFixedBox() for more details

Parameters
separatingAxisIndex
aBox 1's bounding sphere vector
bBox 2's bounding sphere vector
DVector between Box 1 and Box 2's center points
cPointer to array of dot products of the axes of Box 1 and Box 2.
caPointer to array of unsigned dot products of the axes of Box 1 and Box 2.
adPointer to array of dot products of Box 1 axes and D.
bdPointer to array of dot products of Box 2 axes and D.
Returns
Projected distance between the two boxes along the specified separating axis.

◆ rayAABox()

static bool G3D::CollisionDetection::rayAABox ( const Ray ray,
const Vector3 invDir,
const AABox box,
const Vector3 boxCenter,
float  boundingRadiusSquared,
Vector3 location,
bool &  inside 
)
static


Calculates intersection of a ray and a static Axis-Aligned Box (AABox).

Note
Avoids the sqrt from collisionTimeForMovingPointFixedAABox; early-out branches and operations optimized for Intel Core2 architecture.
Parameters
invDir1/dir
locationLocation of collision. [Post Condition]
insideDoes the ray originate inside the box? [Post Condition]
Returns
True if the ray hits the box

◆ separatingAxisForSolidBoxSolidBox()

static Vector3 G3D::CollisionDetection::separatingAxisForSolidBoxSolidBox ( const int  separatingAxisIndex,
const Box box1,
const Box box2 
)
static

Converts an index [0, 15] to the corresponding separating axis.

Does not return normalized vector in the edge-edge case (indices 6 through 15).

Parameters
separatingAxisIndexSeparating axis.
box1Box 1.
box2Box 2.
Returns
Axis that separates the two boxes.

◆ slideDirection()

static Vector3 G3D::CollisionDetection::slideDirection ( const class Sphere sphere,
const Vector3 velocity,
const float  collisionTime,
const Vector3 collisionLocation 
)
static


Finds the direction of slide given a moving sphere, its velocity, the time of collision and the collision location.

This function works as if the sphere intersects the surface and continues to hug it.

Note
The result will work well for calculating the movement of a player who collides with an object and continues moving along the object instead of just bouncing off it.
Parameters
sphereMoving sphere.
velocitySphere's velocity.
collisionTimeTime of collision
collisionLocationCollision location.
Returns
Direction of slide.

documentation generated on Wed Nov 24 2021 08:01:53 using doxygen 1.8.15