Functions

sp::math::CollisionLibrary Namespace Reference

Here you will find each function for collision detection, distance computation and intersection tests. More...

Functions

SP_EXPORT dim::vector3df getClosestPoint (const dim::triangle3df &Triangle, const dim::vector3df &Point)
SP_EXPORT bool getClosestPointStraight (const dim::triangle3df &Triangle, const dim::vector3df &Point, dim::vector3df &PointOnTriangle)
SP_EXPORT dim::vector3df getClosestPoint (const dim::aabbox3df &Box, const dim::vector3df &Point)
SP_EXPORT dim::vector3df getClosestPoint (const dim::aabbox3df &Box, const dim::vector3df &Point, dim::vector3df &Normal)
SP_EXPORT dim::vector3df getClosestPoint (const dim::obbox3df &Box, const dim::vector3df &Point)
SP_EXPORT dim::line3df getClosestLine (const dim::triangle3df &Triangle, const dim::line3df &Line)
SP_EXPORT bool getClosestLineStraight (const dim::triangle3df &Triangle, const dim::line3df &Line, dim::line3df &LineToTriangle)
SP_EXPORT dim::line3df getClosestLine (const dim::quadrangle3df &Quadrangle, const dim::line3df &Line)
SP_EXPORT dim::line3df getClosestLine (const dim::aabbox3df &Box, const dim::line3df &Line)
SP_EXPORT f32 getPointBoxDistanceSq (const dim::obbox3df &Box, const dim::vector3df &Point)
 Computes the squared distance between the given box and point.
SP_EXPORT f32 getLineBoxDistanceSq (const dim::aabbox3df &Box, const dim::line3df &Line)
SP_EXPORT f32 getLineLineDistanceSq (const dim::line3df &LineA, const dim::line3df &LineB, dim::vector3df &PointP, dim::vector3df &PointQ)
SP_EXPORT bool getLineLineIntersection (const dim::line3df &LineA, const dim::line3df &LineB, dim::vector3df &Intersection)
SP_EXPORT dim::point2df get2DLineLineIntersectionStraight (const dim::point2df &A, const dim::point2df &B, const dim::point2df &C, const dim::point2df &D)
SP_EXPORT bool checkLineTriangleIntersection (const dim::triangle3df &Triangle, const dim::line3df &Line, dim::vector3df &Intersection)
SP_EXPORT bool checkLineSphereIntersection (const dim::line3df &Line, const dim::vector3df &SpherePosition, const f32 SphereRadius, dim::vector3df &Intersection, bool MakeRayTest)
SP_EXPORT bool checkLineBoxIntersection (const dim::line3df &Line, const dim::aabbox3df &Box, dim::vector3df &Intersection, bool MakeRayTest)
SP_EXPORT bool checkTriangleTriangleIntersection (const dim::triangle3df &TriangleA, const dim::triangle3df &TriangleB, dim::line3df &Intersection)
SP_EXPORT bool checkLineBoxOverlap (const dim::line3df &Line, const dim::aabbox3df &Box)
 Returns true if an intersection between "Line" and "Box" has been detected.
SP_EXPORT bool checkPlaneBoxOverlap (const dim::plane3df &Plane, const dim::aabbox3df &Box)
 Returns true if an intersection between "Plane" and "Box" has been detected.
SP_EXPORT bool checkTriangleBoxOverlap (const dim::triangle3df &Triangle, const dim::aabbox3df &Box)
 Returns true if an intersection between "Triangle" and "Box" has been detected.
SP_EXPORT bool checkOBBoxOBBoxOverlap (const dim::obbox3df &BoxA, const dim::obbox3df &BoxB)
bool checkPyramidPyramidOverlap (const dim::vector3df &OriginA, const scene::ViewFrustum &FrustumA, const dim::vector3df &OriginB, const scene::ViewFrustum &FrustumB)
f32 getPointBoxDistance (const dim::obbox3df &Box, const dim::vector3df &Point)
 Computes the distance between the given box and point.
f32 getLineBoxDistance (const dim::aabbox3df &Box, const dim::line3df &Line)
 Computes the distance between the given box and line.
f32 getLineLineDistance (const dim::line3df &LineA, const dim::line3df &LineB, dim::vector3df &PointP, dim::vector3df &PointQ)
 Returns the square root of the result of the getLineLineDistanceSq function.
template<typename T , typename C >
bool getLinePlaneIntersection (const dim::plane3d< T > &Plane, const C &LineStart, const C &LineEnd, C &Intersection)
template<typename T , typename C >
bool clipPolygon (const dim::polygon< C > &Poly, const dim::plane3d< T > &Plane, dim::polygon< C > &FrontPoly, dim::polygon< C > &BackPoly)

Detailed Description

Here you will find each function for collision detection, distance computation and intersection tests.


Function Documentation

SP_EXPORT bool sp::math::CollisionLibrary::checkLineBoxIntersection ( const dim::line3df &  Line,
const dim::aabbox3df &  Box,
dim::vector3df &  Intersection,
bool  MakeRayTest = false 
)

Tests if a line intersects with an axis aligned bounding box.

Parameters:
[in] Line 3D line for the test.
[in] Box 3D AABB (Axis Aligned Bounding Box) for the test. In this case you can not transform the box (e.g. for rotations). Make an inverse transformation to the line.
[out] Intersection Resulting 3D intersection point.
[in] MakeRayTest Specifies whether the line is to be interpreted as a line or a ray. By default false. If the line is interpreted as a ray, the length of the line is ignored.
Returns:
True if an intersection has been detected.
SP_EXPORT bool sp::math::CollisionLibrary::checkLineBoxOverlap ( const dim::line3df &  Line,
const dim::aabbox3df &  Box 
)

Returns true if an intersection between "Line" and "Box" has been detected.

SP_EXPORT bool sp::math::CollisionLibrary::checkLineSphereIntersection ( const dim::line3df &  Line,
const dim::vector3df &  SpherePosition,
const f32  SphereRadius,
dim::vector3df &  Intersection,
bool  MakeRayTest = false 
)

Tests if a line intersects with a sphere.

Parameters:
[in] Line 3D line for the test.
[in] SpherePosition Sphere's 3D position.
[in] SphereRadius Sphere's radius.
[out] Intersection Resulting 3D intersection point.
[in] MakeRayTest Specifies whether the line is to be interpreted as a line or a ray. By default false.
Returns:
True if an intersection has been detected.
SP_EXPORT bool sp::math::CollisionLibrary::checkLineTriangleIntersection ( const dim::triangle3df &  Triangle,
const dim::line3df &  Line,
dim::vector3df &  Intersection 
)

Tests if a lines intersects with a triangle.

Parameters:
Triangle,: 3D triangle for the test.
Line,: 3D line for the test.
Intersection,: Resulting 3D intersection point.
Returns:
True if an intersection has been detected.
SP_EXPORT bool sp::math::CollisionLibrary::checkOBBoxOBBoxOverlap ( const dim::obbox3df &  BoxA,
const dim::obbox3df &  BoxB 
)
Returns:
True if an intersection between "BoxA" and "BoxB" has been detected. OOBs (orientated-bounding-boxes) may be transformed for intersection tests (With AABBs (axis-aliend-bounding-boxes) you have to transform the opposit intersection object by the inverse transformation).
SP_EXPORT bool sp::math::CollisionLibrary::checkPlaneBoxOverlap ( const dim::plane3df &  Plane,
const dim::aabbox3df &  Box 
)

Returns true if an intersection between "Plane" and "Box" has been detected.

bool sp::math::CollisionLibrary::checkPyramidPyramidOverlap ( const dim::vector3df &  OriginA,
const scene::ViewFrustum &  FrustumA,
const dim::vector3df &  OriginB,
const scene::ViewFrustum &  FrustumB 
)

Returns true if the two view frustums overlap each other. In this case the two view frustums are aproximated as pyramids for performance optimzation.

SP_EXPORT bool sp::math::CollisionLibrary::checkTriangleBoxOverlap ( const dim::triangle3df &  Triangle,
const dim::aabbox3df &  Box 
)

Returns true if an intersection between "Triangle" and "Box" has been detected.

SP_EXPORT bool sp::math::CollisionLibrary::checkTriangleTriangleIntersection ( const dim::triangle3df &  TriangleA,
const dim::triangle3df &  TriangleB,
dim::line3df &  Intersection 
)

Tests if a triangle intersects with an other triangle.

Parameters:
TriangleA,: First 3D triangle for the test.
TriangleB,: Second 3D triangle for the test.
Intersection,: Resulting 3D line (or rather "intersection cut").
Returns:
True if an intersection has been detected.
template<typename T , typename C >
bool sp::math::CollisionLibrary::clipPolygon ( const dim::polygon< C > &  Poly,
const dim::plane3d< T > &  Plane,
dim::polygon< C > &  FrontPoly,
dim::polygon< C > &  BackPoly 
)

Clips the given polygon with the given plane.

Template Parameters:
T Specifies the data type (float, double, int etc.).
C Specifies the class type (point2d, vector3d etc.). Requires that the class implements a function called "vector3d<T> getCoord() const".
Parameters:
[in] Poly Specifies the polygon which is to be clipped.
[in] Plane Specifies the clipping plane.
[out] FrontPoly Specifies the output polygon which is in front of the clipping plane.
[out] BackPoly Specifies the output polygon which is behind the clipping plane.
Returns:
True on success. Otherwise the input is invalid.
See also:
scene::ClipVertex
SP_EXPORT dim::point2df sp::math::CollisionLibrary::get2DLineLineIntersectionStraight ( const dim::point2df &  A,
const dim::point2df &  B,
const dim::point2df &  C,
const dim::point2df &  D 
)

Computes the intersection of two lines (or rather rays because an intersection will always be detected).

Parameters:
A,: Start point of the first lines.
B,: End point of the first lines.
C,: Start point of the second lines.
D,: End point of the second lines.
Returns:
Intersection point of the two lines (or rather rays).
SP_EXPORT dim::line3df sp::math::CollisionLibrary::getClosestLine ( const dim::quadrangle3df &  Quadrangle,
const dim::line3df &  Line 
)

Computes the closest line from the given quadrangle and line.

Parameters:
Quadrangle,: 3D quadrangle for the computation.
Line,: 3D line to which the clsoest point is to be computed.
Returns:
Closest 3D line from "Line" to "Quadrangle" where the start point is onto the quadrangle.
Todo:
This function has not been tested yet!
SP_EXPORT dim::line3df sp::math::CollisionLibrary::getClosestLine ( const dim::aabbox3df &  Box,
const dim::line3df &  Line 
)

Computes the closest line from the given axis-aligned bounding box and line.

Parameters:
[in] Box Specifies the AABB.
[in] Line Specifies the 3D line.
Returns:
Closest 3D line from "Line" to "Box" where the start point is onto the box.
SP_EXPORT dim::line3df sp::math::CollisionLibrary::getClosestLine ( const dim::triangle3df &  Triangle,
const dim::line3df &  Line 
)

Computes the closest line between the given triangle and line.

Parameters:
Triangle,: 3D triangle for the computation.
Line,: 3D line to which the closest point is to be computed.
Returns:
Closest 3D line from "Line" to "Triangle" where the start point is onto the triangle.
SP_EXPORT bool sp::math::CollisionLibrary::getClosestLineStraight ( const dim::triangle3df &  Triangle,
const dim::line3df &  Line,
dim::line3df &  LineToTriangle 
)

Computes the closest line between the given triangle and line.

Parameters:
Triangle,: 3D triangle for the computation.
Line,: 3D line to which the closest point is to be computed.
LineToTriangle,: Resulting 3D line.
Returns:
True if the line's start or end point lies onto the triangle. Otherwise false and the resulting 3d line is empty.
SP_EXPORT dim::vector3df sp::math::CollisionLibrary::getClosestPoint ( const dim::aabbox3df &  Box,
const dim::vector3df &  Point 
)

Computes the closest point from an other point to a box.

Parameters:
Box,: 3D AABB (Axis-Aliend-Bounding-Box) for the computation.
Point,: 3D point to which the closest point shall be computed.
Returns:
Closest 3D point from "Point" to "Box" (or rather to a Box's surface).
SP_EXPORT dim::vector3df sp::math::CollisionLibrary::getClosestPoint ( const dim::triangle3df &  Triangle,
const dim::vector3df &  Point 
)

Computes the closest point onto given triangle from an other point to this trianlge.

Parameters:
Triangle,: 3D triangle for the computation.
Point,: 3D point to which the closest point is to be computed.
Returns:
Closest 3D point from "Point" to "Triangle".
SP_EXPORT dim::vector3df sp::math::CollisionLibrary::getClosestPoint ( const dim::aabbox3df &  Box,
const dim::vector3df &  Point,
dim::vector3df &  Normal 
)

Same like the function above but computes additional the normalized normal vector by "Point" and the resulting 3D point.

SP_EXPORT dim::vector3df sp::math::CollisionLibrary::getClosestPoint ( const dim::obbox3df &  Box,
const dim::vector3df &  Point 
)

Computes the closest point from an other point to a box.

Parameters:
Box,: 3D OBB (Oriented-Bounding-Box) for the computation.
Point,: 3D point to which the closest point shall be computed.
Returns:
Closest 3D point from "Point" to "Box" (or rather to a Box's surface).
SP_EXPORT bool sp::math::CollisionLibrary::getClosestPointStraight ( const dim::triangle3df &  Triangle,
const dim::vector3df &  Point,
dim::vector3df &  PointOnTriangle 
)

Computes the closest point from an other point to a triangle if this computed point lies onto the triangle.

Parameters:
PointOnTriangle,: Resulting 3D point.
Returns:
True if the point lies onto the triangle. In this case "Point" and "PointOnTrianlge" offer a normal vector to "Trianlge".
f32 sp::math::CollisionLibrary::getLineBoxDistance ( const dim::aabbox3df &  Box,
const dim::line3df &  Line 
) [inline]

Computes the distance between the given box and line.

SP_EXPORT f32 sp::math::CollisionLibrary::getLineBoxDistanceSq ( const dim::aabbox3df &  Box,
const dim::line3df &  Line 
)

Computes the squared distance between the given box and line.

Todo:
This function has not been tested yet!
f32 sp::math::CollisionLibrary::getLineLineDistance ( const dim::line3df &  LineA,
const dim::line3df &  LineB,
dim::vector3df &  PointP,
dim::vector3df &  PointQ 
) [inline]

Returns the square root of the result of the getLineLineDistanceSq function.

SP_EXPORT f32 sp::math::CollisionLibrary::getLineLineDistanceSq ( const dim::line3df &  LineA,
const dim::line3df &  LineB,
dim::vector3df &  PointP,
dim::vector3df &  PointQ 
)

Computes the squared distance between two lines. If you want to have the real distance take the square-root of the return value.

Parameters:
LineA,: First line.
LineB,: Second line.
PointP,: First point of the closest distance (or rather line).
PointQ,: Second point of the closest distance (or rather line).
Returns:
Closest distance of the two lines or rather the length of the closest line PQ.
SP_EXPORT bool sp::math::CollisionLibrary::getLineLineIntersection ( const dim::line3df &  LineA,
const dim::line3df &  LineB,
dim::vector3df &  Intersection 
)

Tests if the two lines are intersecting.

Parameters:
LinesA,: First line.
LinesB,: Second line.
Intersection,: Resulting intersection point of the two lines if an intersection has been deteced.
Returns:
True if an intersection has been detected.
template<typename T , typename C >
bool sp::math::CollisionLibrary::getLinePlaneIntersection ( const dim::plane3d< T > &  Plane,
const C &  LineStart,
const C &  LineEnd,
C &  Intersection 
)
f32 sp::math::CollisionLibrary::getPointBoxDistance ( const dim::obbox3df &  Box,
const dim::vector3df &  Point 
) [inline]

Computes the distance between the given box and point.

SP_EXPORT f32 sp::math::CollisionLibrary::getPointBoxDistanceSq ( const dim::obbox3df &  Box,
const dim::vector3df &  Point 
)

Computes the squared distance between the given box and point.

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines