Public Types | Static Public Member Functions

decCollisionDetection Class Reference

Collection of collision detection routines. More...

#include <decCollisionDetection.h>

List of all members.

Public Types

enum  eIntersectionResult { eirInside, eirPartial, eirOutside }
 

Intersection test results.

More...

Static Public Member Functions

static bool AABoxHitsAABox (const decVector &minExtend1, const decVector &maxExtend1, const decVector &minExtend2, const decVector &maxExtend2)
 Determines if two axis aligned boxes defined by their extends intersect.
static int AABoxIntersectsAABox (const decVector &minExtend1, const decVector &maxExtend1, const decVector &minExtend2, const decVector &maxExtend2)
 Determines how the first axis aligned box intersects the second one.
static bool RayHitsBox (const decVector &rayOrigin, const decVector &rayDirection, const decVector &boxCenter, const decVector &boxHalfExtends, float &hitDistance)
 Determines if a ray hits an axis aligned box.
static bool RayHitsCapsule (const decVector &rayOrigin, const decVector &rayDirection, const decVector &capsuleCenter, float capsuleHalfHeight, float capsuleRadius, float &hitDistance)
 Determines if a ray hits a capsule with uniform radius oriented along the Y-Axis.
static bool RayHitsCylinder (const decVector &rayOrigin, const decVector &rayDirection, const decVector &cylinderCenter, float cylinderHalfHeight, float cylinderRadius, float &hitDistance)
 Determines if a ray hits a cylinder with uniform radius oriented along the Y-Axis.
static bool RayHitsTaperedCapsule (const decVector &rayOrigin, const decVector &rayDirection, const decVector &capsuleCenter, float capsuleHalfHeight, float capsuleTopRadius, float capsuleBottomRadius, float &hitDistance)
 Determines if a ray hits a tapered capsule oriented along the Y-Axis.
static bool RayHitsTaperedCylinder (const decVector &rayOrigin, const decVector &rayDirection, const decVector &cylinderCenter, float cylinderHalfHeight, float cylinderTopRadius, float cylinderBottomRadius, float &hitDistance)
 Determines if a ray hits a tapered cylinder oriented along the Y-Axis.
static bool RayHitsTriangle (const decVector &rayOrigin, const decVector &rayDirection, const decVector &tri1, const decVector &tri2, const decVector &tri3)
 Determines if a ray hits a triangle.
static bool RayHitsTriangle (const decVector &rayOrigin, const decVector &rayDirection, const decVector &tri1, const decVector &tri2, const decVector &tri3, const decVector &trinormal)
 Determines if a ray hits a triangle using a precalculated triangle normal.
static float SphereMoveHitsSphere (const decVector &sphere1Center, float sphere1Radius, const decVector &sphere2Center, float sphere2Radius, const decVector &displacement, decVector *normal)
 Determines if a sphere collides with another sphere while moving.
Closest Point Routines
static decVector ClosestPointOnLine (const decVector &la, const decVector &lb, const decVector &p)
 Retrieves the closest point on a line to another point.
static decVector ClosestPointOnTriangle (const decVector &tp1, const decVector &tp2, const decVector &tp3, const decVector &p)
 Retrieves the closest point on a triangle to a given point.
static decVector ClosestPointOnQuad (const decVector &tp1, const decVector &tp2, const decVector &tp3, const decVector &tp4, const decVector &p)
 Retrieves the closest point on a quad to a given point.
Intersection Routines
static float RayPlane (const decVector &pp, const decVector &pn, const decVector &rp, const decVector &rd)
 Intersections a ray with a plane.
static float RaySphere (const decVector &rp, const decVector &rd, const decVector &sc, float sr)
 Intersections a ray with a sphere.
Distance Routines
static float SegmentSegmentDistance (const decVector &as, const decVector &ae, const decVector &bs, const decVector &be)
 Retrieves the smallest distance of a line segment to another line segment.
Collision Tests
static bool PointInTriangle (const decVector &tp1, const decVector &tp2, const decVector &tp3, const decVector &p)
 Determines if a point is inside a triangle.
static bool PointInTriangle (const decVector &tp1, const decVector &tp2, const decVector &tp3, const decVector &tnormal, const decVector &p)
 Determines if a point is inside a triangle.
static bool PointInQuad (const decVector &tp1, const decVector &tp2, const decVector &tp3, const decVector &tp4, const decVector &p)
 Determines if a point is inside a quad.
static bool RayHitsSphere (const decVector &rayOrigin, const decVector &rayDirection, const decVector &sphereCenter, float sphereRadius, float &hitDistance)
 Determines if a ray hits a sphere.
static bool SphereHitsSphere (const decVector &sphere1Center, float sphere1Radius, const decVector &sphere2Center, float sphere2Radius)
 Determines if a sphere collides with another sphere.
Side Test Routines
static int PointOnPlaneSide (const decVector &pp, const decVector &pn, const decVector &p)
 Determines on which side of a plane the given point lies in respect to the plane normal.

Detailed Description

Collection of collision detection routines.

Contains a set of collision detection routines used often in a game engine or similar 3D project. Some collision routines from collision volumes have been moved over here as they can be used then also by scripting modules which do not want to create collision volume objects for doing collision detection.

Author:
Plüss Roland
Version:
1.0
Date:
2008

Member Enumeration Documentation

Intersection test results.

Enumerator:
eirInside 

Fully inside.

eirPartial 

Partiall inside.

eirOutside 

Fully outside.


Member Function Documentation

static bool decCollisionDetection::AABoxHitsAABox ( const decVector minExtend1,
const decVector maxExtend1,
const decVector minExtend2,
const decVector maxExtend2 
) [inline, static]

Determines if two axis aligned boxes defined by their extends intersect.

Parameters:
minExtend1Minimum extend of the first box.
maxExtend1Maximum extend of the first box.
minExtend2Minimum extend of the second box.
maxExtend2Maximum extend of the second box.
Returns:
True if the boxes intersect.
static int decCollisionDetection::AABoxIntersectsAABox ( const decVector minExtend1,
const decVector maxExtend1,
const decVector minExtend2,
const decVector maxExtend2 
) [static]

Determines how the first axis aligned box intersects the second one.

Parameters:
minExtend1Minimum extend of the first box.
maxExtend1Maximum extend of the first box.
minExtend2Minimum extend of the second box.
maxExtend2Maximum extend of the second box.
Returns:
Intersection result one of eir* .
static decVector decCollisionDetection::ClosestPointOnLine ( const decVector la,
const decVector lb,
const decVector p 
) [static]

Retrieves the closest point on a line to another point.

Parameters:
laBegin of line.
lbEnd of line.
pPoint to check.
static decVector decCollisionDetection::ClosestPointOnQuad ( const decVector tp1,
const decVector tp2,
const decVector tp3,
const decVector tp4,
const decVector p 
) [static]

Retrieves the closest point on a quad to a given point.

The corners of the quad have to be coplanar or the result is is falsified.

Parameters:
tp1First quad point.
tp2Second quad point.
tp3Third quad point.
tp4Fourth quad point.
pPoint to check.
static decVector decCollisionDetection::ClosestPointOnTriangle ( const decVector tp1,
const decVector tp2,
const decVector tp3,
const decVector p 
) [static]

Retrieves the closest point on a triangle to a given point.

Parameters:
tp1First triangle point.
tp2Second triangle point.
tp3Third triangle point.
pPoint to check.
static bool decCollisionDetection::PointInQuad ( const decVector tp1,
const decVector tp2,
const decVector tp3,
const decVector tp4,
const decVector p 
) [static]

Determines if a point is inside a quad.

The point and the all corners of the quad have to be coplanar for this test to work.

Parameters:
tp1First quad point.
tp2Second quad point.
tp3Third quad point.
tp4Fourth quad point.
pPoint to check.
static bool decCollisionDetection::PointInTriangle ( const decVector tp1,
const decVector tp2,
const decVector tp3,
const decVector tnormal,
const decVector p 
) [static]

Determines if a point is inside a triangle.

The point has to be coplanar with the triangle for this test to work.

Parameters:
tp1First triangle point.
tp2Second triangle point.
tp3Third triangle point.
tnormalTriangle normal.
pPoint to check.
static bool decCollisionDetection::PointInTriangle ( const decVector tp1,
const decVector tp2,
const decVector tp3,
const decVector p 
) [static]

Determines if a point is inside a triangle.

The point has to be coplanar with the triangle for this test to work.

Parameters:
tp1First triangle point.
tp2Second triangle point.
tp3Third triangle point.
pPoint to check.
static int decCollisionDetection::PointOnPlaneSide ( const decVector pp,
const decVector pn,
const decVector p 
) [inline, static]

Determines on which side of a plane the given point lies in respect to the plane normal.

Parameters:
ppPlane point.
pnPlane normal.
pPoint to test.
Returns:
1 if in front side, -1 if on back side or 0 if coplanar
static bool decCollisionDetection::RayHitsBox ( const decVector rayOrigin,
const decVector rayDirection,
const decVector boxCenter,
const decVector boxHalfExtends,
float &  hitDistance 
) [static]

Determines if a ray hits an axis aligned box.

Parameters:
rayOriginOrigin of the ray.
rayDirectionNormalized direction of the ray.
boxCenterCenter of the box.
boxHalfExtendsHalf extends of the spherbox. All components have to be greater than 0.
hitDistanceIf the ray hits this will be set to the distance from the ray origin to the collision point.
Returns:
True if the ray hits the box.
static bool decCollisionDetection::RayHitsCapsule ( const decVector rayOrigin,
const decVector rayDirection,
const decVector capsuleCenter,
float  capsuleHalfHeight,
float  capsuleRadius,
float &  hitDistance 
) [static]

Determines if a ray hits a capsule with uniform radius oriented along the Y-Axis.

Parameters:
rayOriginOrigin of the ray.
rayDirectionNormalized direction of the ray.
capsuleCenterCenter of the capsule.
capsuleHalfHeightHalf height of capsule. Has to be greater than 0.
capsuleRadiusRadius of the capsule. Has to be greater than 0.
hitDistanceIf the ray hits this will be set to the distance from the ray origin to the collision point.
Returns:
True if the ray hits the capsule
static bool decCollisionDetection::RayHitsCylinder ( const decVector rayOrigin,
const decVector rayDirection,
const decVector cylinderCenter,
float  cylinderHalfHeight,
float  cylinderRadius,
float &  hitDistance 
) [static]

Determines if a ray hits a cylinder with uniform radius oriented along the Y-Axis.

Parameters:
rayOriginOrigin of the ray.
rayDirectionNormalized direction of the ray.
cylinderCenterCenter of the cylinder.
cylinderHalfHeightHalf height of cylinder. Has to be greater than 0.
cylinderRadiusRadius of the cylinder. Has to be greater than 0.
hitDistanceIf the ray hits this will be set to the distance from the ray origin to the collision point.
Returns:
True if the ray hits the cylinder.
static bool decCollisionDetection::RayHitsSphere ( const decVector rayOrigin,
const decVector rayDirection,
const decVector sphereCenter,
float  sphereRadius,
float &  hitDistance 
) [static]

Determines if a ray hits a sphere.

Parameters:
rayOriginOrigin of the ray.
rayDirectionNormalized direction of the ray.
sphereCenterCenter of the sphere.
sphereRadiusRadius of the sphere. Has to be greater than 0.
hitDistanceIf the ray hits this will be set to the distance from the ray origin to the collision point.
Returns:
True if the ray hits the sphere.
static bool decCollisionDetection::RayHitsTaperedCapsule ( const decVector rayOrigin,
const decVector rayDirection,
const decVector capsuleCenter,
float  capsuleHalfHeight,
float  capsuleTopRadius,
float  capsuleBottomRadius,
float &  hitDistance 
) [static]

Determines if a ray hits a tapered capsule oriented along the Y-Axis.

Parameters:
rayOriginOrigin of the ray.
rayDirectionNormalized direction of the ray.
capsuleCenterCenter of the capsule.
capsuleHalfHeightHalf height of capsule. Has to be greater than 0.
capsuleTopRadiusRadius of the top cap of the capsule. Has to be greater than 0.
capsuleBottomRadiusRadius of the bottom cap of the capsule. Has to be greater than 0.
hitDistanceIf the ray hits this will be set to the distance from the ray origin to the collision point.
Returns:
True if the ray hits the capsule.
static bool decCollisionDetection::RayHitsTaperedCylinder ( const decVector rayOrigin,
const decVector rayDirection,
const decVector cylinderCenter,
float  cylinderHalfHeight,
float  cylinderTopRadius,
float  cylinderBottomRadius,
float &  hitDistance 
) [static]

Determines if a ray hits a tapered cylinder oriented along the Y-Axis.

Parameters:
rayOriginOrigin of the ray.
rayDirectionNormalized direction of the ray.
cylinderCenterCenter of the cylinder.
cylinderHalfHeightHalf height of cylinder. Has to be greater than 0.
cylinderTopRadiusRadius of the top cap of the cylinder. Has to be greater than 0.
cylinderBottomRadiusRadius of the bottom cap of the cylinder. Has to be greater than 0.
hitDistanceIf the ray hits this will be set to the distance from the ray origin to the collision point.
Returns:
True if the ray hits the cylinder.
static bool decCollisionDetection::RayHitsTriangle ( const decVector rayOrigin,
const decVector rayDirection,
const decVector tri1,
const decVector tri2,
const decVector tri3 
) [static]

Determines if a ray hits a triangle.

Parameters:
rayOriginOrigin of the ray.
rayDirectionNormalized direction of the ray.
tri1First point of the triangle.
tri2Second point of the triangle.
tri3Third point of the triangle.
Returns:
True if the ray hits the triangle.
static bool decCollisionDetection::RayHitsTriangle ( const decVector rayOrigin,
const decVector rayDirection,
const decVector tri1,
const decVector tri2,
const decVector tri3,
const decVector trinormal 
) [static]

Determines if a ray hits a triangle using a precalculated triangle normal.

Parameters:
rayOriginOrigin of the ray.
rayDirectionNormalized direction of the ray.
tri1First point of the triangle.
tri2Second point of the triangle.
tri3Third point of the triangle.
trinormalNormal of the triangle.
Returns:
True if the ray hits the triangle.
static float decCollisionDetection::RayPlane ( const decVector pp,
const decVector pn,
const decVector rp,
const decVector rd 
) [static]

Intersections a ray with a plane.

Parameters:
ppPlane position.
pnPlane normal.
rpRay position.
rdRay direction.
Returns:
Distance to travel on the ray in his view direction to reach the collision point. If no collision occures ( because the ray is parallel to the plane ) -1 is returned.
static float decCollisionDetection::RaySphere ( const decVector rp,
const decVector rd,
const decVector sc,
float  sr 
) [static]

Intersections a ray with a sphere.

Parameters:
rpRay position.
rdRay direction.
scSphere center.
srSphere radius.
Returns:
Distance to travel on the ray in his view direction to reach the collision point. If no collision occures ( because the ray is parallel to the plane ) -1 is returned.
static float decCollisionDetection::SegmentSegmentDistance ( const decVector as,
const decVector ae,
const decVector bs,
const decVector be 
) [static]

Retrieves the smallest distance of a line segment to another line segment.

Parameters:
asSegment a start position.
aeSegment a end position.
bsSegment b start position.
beSegment b end position.
static bool decCollisionDetection::SphereHitsSphere ( const decVector sphere1Center,
float  sphere1Radius,
const decVector sphere2Center,
float  sphere2Radius 
) [static]

Determines if a sphere collides with another sphere.

Parameters:
sphere1CenterCenter of the first sphere.
sphere1RadiusRadius of the first sphere. Has to be greater than 0.
sphere2CenterCenter of the second sphere.
sphere2RadiusRadius of the second sphere. Has to be greater than 0.
Returns:
True if the spheres collide.
static float decCollisionDetection::SphereMoveHitsSphere ( const decVector sphere1Center,
float  sphere1Radius,
const decVector sphere2Center,
float  sphere2Radius,
const decVector displacement,
decVector normal 
) [static]

Determines if a sphere collides with another sphere while moving.

Parameters:
sphere1CenterCenter of the first sphere.
sphere1RadiusRadius of the first sphere. Has to be greater than 0.
sphere2CenterCenter of the second sphere.
sphere2RadiusRadius of the second sphere. Has to be greater than 0.
displacementDisplacement of the first sphere.
normalStores the collision normal into. Set to NULL if you do not require the normal.
Returns:
Time of impact. 0 correspondes to the beginning of the moving and 1 to moving along the entire displacement. Hence scaling the direction by the returned time of impact yields the displacement right up to the time of the collision. If no collision happend -1 is returned.

The documentation for this class was generated from the following file: