Saga3D API Documentation  1.0-RC4
saga::core::triangle3d< T > Class Template Reference

3d triangle template class for doing collision detection and other things. More...

#include <triangle3d.h>

Public Member Functions

 triangle3d ()
 Constructor for an all 0 triangle. More...
 
 triangle3d (const glm::vec3 &v1, const glm::vec3 &v2, const glm::vec3 &v3)
 Constructor for triangle with given three vertices. More...
 
bool operator== (const triangle3d< T > &other) const
 Equality operator. More...
 
bool operator!= (const triangle3d< T > &other) const
 Inequality operator. More...
 
bool isTotalInsideBox (const aabbox3d< T > &box) const
 Determines if the triangle is totally inside a bounding box. More...
 
bool isTotalOutsideBox (const aabbox3d< T > &box) const
 Determines if the triangle is totally outside a bounding box. More...
 
glm::vec3 closestPointOnTriangle (const glm::vec3 &p) const
 Get the closest point on a triangle to a point on the same plane. More...
 
bool isPointInside (const glm::vec3 &p) const
 Check if a point is inside the triangle (border-points count also as inside) More...
 
bool isPointInsideFast (const glm::vec3 &p) const
 Check if a point is inside the triangle (border-points count also as inside) More...
 
bool getIntersectionWithLimitedLine (const line3d< T > &line, glm::vec3 &outIntersection) const
 Get an intersection with a 3d line. More...
 
bool getIntersectionWithLine (const glm::vec3 &linePoint, const glm::vec3 &lineVect, glm::vec3 &outIntersection) const
 Get an intersection with a 3d line. More...
 
bool getIntersectionOfPlaneWithLine (const glm::vec3 &linePoint, const glm::vec3 &lineVect, glm::vec3 &outIntersection) const
 Calculates the intersection between a 3d line and the plane the triangle is on. More...
 
glm::vec3 getNormal () const
 Get the normal of the triangle. More...
 
bool isFrontFacing (const glm::vec3 &lookDirection) const
 Test if the triangle would be front or backfacing from any point. More...
 
plane3d< T > getPlane () const
 Get the plane of this triangle. More...
 
getArea () const
 Get the area of the triangle. More...
 
void set (const glm::vec3 &a, const glm::vec3 &b, const glm::vec3 &c)
 sets the triangle's points More...
 

Public Attributes

glm::vec3 pointA
 the three points of the triangle More...
 
glm::vec3 pointB
 
glm::vec3 pointC
 

Detailed Description

template<class T>
class saga::core::triangle3d< T >

3d triangle template class for doing collision detection and other things.

Definition at line 19 of file triangle3d.h.

Constructor & Destructor Documentation

◆ triangle3d() [1/2]

template<class T >
saga::core::triangle3d< T >::triangle3d ( )
inline

Constructor for an all 0 triangle.

Definition at line 24 of file triangle3d.h.

◆ triangle3d() [2/2]

template<class T >
saga::core::triangle3d< T >::triangle3d ( const glm::vec3 &  v1,
const glm::vec3 &  v2,
const glm::vec3 &  v3 
)
inline

Constructor for triangle with given three vertices.

Definition at line 26 of file triangle3d.h.

Member Function Documentation

◆ closestPointOnTriangle()

template<class T >
glm::vec3 saga::core::triangle3d< T >::closestPointOnTriangle ( const glm::vec3 &  p) const
inline

Get the closest point on a triangle to a point on the same plane.

Parameters
pPoint which must be on the same plane as the triangle.
Returns
The closest point of the triangle

Definition at line 67 of file triangle3d.h.

◆ getArea()

template<class T >
T saga::core::triangle3d< T >::getArea ( ) const
inline

Get the area of the triangle.

Definition at line 223 of file triangle3d.h.

◆ getIntersectionOfPlaneWithLine()

template<class T >
bool saga::core::triangle3d< T >::getIntersectionOfPlaneWithLine ( const glm::vec3 &  linePoint,
const glm::vec3 &  lineVect,
glm::vec3 &  outIntersection 
) const
inline

Calculates the intersection between a 3d line and the plane the triangle is on.

Parameters
lineVectVector of the line to intersect with.
linePointPoint of the line to intersect with.
outIntersectionPlace to store the intersection point, if there is one.
Returns
True if there was an intersection, else false.

Definition at line 168 of file triangle3d.h.

◆ getIntersectionWithLimitedLine()

template<class T >
bool saga::core::triangle3d< T >::getIntersectionWithLimitedLine ( const line3d< T > &  line,
glm::vec3 &  outIntersection 
) const
inline

Get an intersection with a 3d line.

Parameters
lineLine to intersect with.
outIntersectionPlace to store the intersection point, if there is one.
Returns
True if there was an intersection, false if not.

Definition at line 135 of file triangle3d.h.

◆ getIntersectionWithLine()

template<class T >
bool saga::core::triangle3d< T >::getIntersectionWithLine ( const glm::vec3 &  linePoint,
const glm::vec3 &  lineVect,
glm::vec3 &  outIntersection 
) const
inline

Get an intersection with a 3d line.

Please note that also points are returned as intersection which are on the line, but not between the start and end point of the line. If you want the returned point be between start and end use getIntersectionWithLimitedLine().

Parameters
linePointPoint of the line to intersect with.
lineVectVector of the line to intersect with.
outIntersectionPlace to store the intersection point, if there is one.
Returns
True if there was an intersection, false if there was not.

Definition at line 153 of file triangle3d.h.

◆ getNormal()

template<class T >
glm::vec3 saga::core::triangle3d< T >::getNormal ( ) const
inline

Get the normal of the triangle.

Please note: The normal is not always normalized.

Definition at line 198 of file triangle3d.h.

◆ getPlane()

template<class T >
plane3d<T> saga::core::triangle3d< T >::getPlane ( ) const
inline

Get the plane of this triangle.

Definition at line 217 of file triangle3d.h.

◆ isFrontFacing()

template<class T >
bool saga::core::triangle3d< T >::isFrontFacing ( const glm::vec3 &  lookDirection) const
inline

Test if the triangle would be front or backfacing from any point.

Thus, this method assumes a camera position from which the triangle is definitely visible when looking at the given direction. Do not use this method with points as it will give wrong results!

Parameters
lookDirectionLook direction.
Returns
True if the plane is front facing and false if it is backfacing.

Definition at line 209 of file triangle3d.h.

◆ isPointInside()

template<class T >
bool saga::core::triangle3d< T >::isPointInside ( const glm::vec3 &  p) const
inline

Check if a point is inside the triangle (border-points count also as inside)

Definition at line 88 of file triangle3d.h.

◆ isPointInsideFast()

template<class T >
bool saga::core::triangle3d< T >::isPointInsideFast ( const glm::vec3 &  p) const
inline

Check if a point is inside the triangle (border-points count also as inside)

This method uses a barycentric coordinate system. It is faster than isPointInside but is more susceptible to floating point rounding errors. This will especially be noticeable when the FPU is in single precision mode (which is for example set on default by Direct3D).

Parameters
pPoint to test. Assumes that this point is already on the plane of the triangle.
Returns
True if point is inside the triangle, otherwise false.

Definition at line 107 of file triangle3d.h.

◆ isTotalInsideBox()

template<class T >
bool saga::core::triangle3d< T >::isTotalInsideBox ( const aabbox3d< T > &  box) const
inline

Determines if the triangle is totally inside a bounding box.

Parameters
boxBox to check.
Returns
True if triangle is within the box, otherwise false.

Definition at line 43 of file triangle3d.h.

◆ isTotalOutsideBox()

template<class T >
bool saga::core::triangle3d< T >::isTotalOutsideBox ( const aabbox3d< T > &  box) const
inline

Determines if the triangle is totally outside a bounding box.

Parameters
boxBox to check.
Returns
True if triangle is outside the box, otherwise false.

Definition at line 53 of file triangle3d.h.

◆ operator!=()

template<class T >
bool saga::core::triangle3d< T >::operator!= ( const triangle3d< T > &  other) const
inline

Inequality operator.

Definition at line 35 of file triangle3d.h.

◆ operator==()

template<class T >
bool saga::core::triangle3d< T >::operator== ( const triangle3d< T > &  other) const
inline

Equality operator.

Definition at line 29 of file triangle3d.h.

◆ set()

template<class T >
void saga::core::triangle3d< T >::set ( const glm::vec3 &  a,
const glm::vec3 &  b,
const glm::vec3 &  c 
)
inline

sets the triangle's points

Definition at line 230 of file triangle3d.h.

Member Data Documentation

◆ pointA

template<class T >
glm::vec3 saga::core::triangle3d< T >::pointA

the three points of the triangle

Definition at line 238 of file triangle3d.h.

◆ pointB

template<class T >
glm::vec3 saga::core::triangle3d< T >::pointB

Definition at line 239 of file triangle3d.h.

◆ pointC

template<class T >
glm::vec3 saga::core::triangle3d< T >::pointC

Definition at line 240 of file triangle3d.h.


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