Public Types | Static Public Member Functions

decDCollisionDetection Class Reference

Collection of collision detection routines. More...

#include <decDCollisionDetection.h>

List of all members.

Public Types

enum  eIntersectionResult { eirInside, eirPartial, eirOutside }
 

Intersection test results.

More...

Static Public Member Functions

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

Retrieves the closest point on a line to another point.

Parameters:
laBegin of line.
lbEnd of line.
pPoint to check.
static decDVector decDCollisionDetection::ClosestPointOnQuad ( const decDVector tp1,
const decDVector tp2,
const decDVector tp3,
const decDVector tp4,
const decDVector 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 decDVector decDCollisionDetection::ClosestPointOnTriangle ( const decDVector tp1,
const decDVector tp2,
const decDVector tp3,
const decDVector 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 decDCollisionDetection::PointInQuad ( const decDVector tp1,
const decDVector tp2,
const decDVector tp3,
const decDVector tp4,
const decDVector 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 decDCollisionDetection::PointInTriangle ( const decDVector tp1,
const decDVector tp2,
const decDVector tp3,
const decDVector tnormal,
const decDVector 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 decDCollisionDetection::PointInTriangle ( const decDVector tp1,
const decDVector tp2,
const decDVector tp3,
const decDVector 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 decDCollisionDetection::PointOnPlaneSide ( const decDVector pp,
const decDVector pn,
const decDVector 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 decDCollisionDetection::RayHitsBox ( const decDVector rayOrigin,
const decDVector rayDirection,
const decDVector boxCenter,
const decDVector boxHalfExtends,
double &  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 decDCollisionDetection::RayHitsCapsule ( const decDVector rayOrigin,
const decDVector rayDirection,
const decDVector capsuleCenter,
double  capsuleHalfHeight,
double  capsuleRadius,
double &  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 decDCollisionDetection::RayHitsCylinder ( const decDVector rayOrigin,
const decDVector rayDirection,
const decDVector cylinderCenter,
double  cylinderHalfHeight,
double  cylinderRadius,
double &  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 decDCollisionDetection::RayHitsSphere ( const decDVector rayOrigin,
const decDVector rayDirection,
const decDVector sphereCenter,
double  sphereRadius,
double &  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 decDCollisionDetection::RayHitsTaperedCapsule ( const decDVector rayOrigin,
const decDVector rayDirection,
const decDVector capsuleCenter,
double  capsuleHalfHeight,
double  capsuleTopRadius,
double  capsuleBottomRadius,
double &  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 decDCollisionDetection::RayHitsTaperedCylinder ( const decDVector rayOrigin,
const decDVector rayDirection,
const decDVector cylinderCenter,
double  cylinderHalfHeight,
double  cylinderTopRadius,
double  cylinderBottomRadius,
double &  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 decDCollisionDetection::RayHitsTriangle ( const decDVector rayOrigin,
const decDVector rayDirection,
const decDVector tri1,
const decDVector tri2,
const decDVector 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 decDCollisionDetection::RayHitsTriangle ( const decDVector rayOrigin,
const decDVector rayDirection,
const decDVector tri1,
const decDVector tri2,
const decDVector tri3,
const decDVector 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 double decDCollisionDetection::RayPlane ( const decDVector pp,
const decDVector pn,
const decDVector rp,
const decDVector 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 double decDCollisionDetection::RaySphere ( const decDVector rp,
const decDVector rd,
const decDVector sc,
double  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 double decDCollisionDetection::SegmentSegmentDistance ( const decDVector as,
const decDVector ae,
const decDVector bs,
const decDVector 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 decDCollisionDetection::SphereHitsSphere ( const decDVector sphere1Center,
double  sphere1Radius,
const decDVector sphere2Center,
double  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 double decDCollisionDetection::SphereMoveHitsSphere ( const decDVector sphere1Center,
double  sphere1Radius,
const decDVector sphere2Center,
double  sphere2Radius,
const decDVector displacement,
decDVector 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: