Saga3D API Documentation
1.0-RC4
|
Go to the documentation of this file.
5 #ifndef __IRR_TRIANGLE_3D_H_INCLUDED__
6 #define __IRR_TRIANGLE_3D_H_INCLUDED__
37 return !(*
this==other);
73 const T d1 = glm::distance(rab, p);
74 const T d2 = glm::distance(rbc, p);
75 const T d3 = glm::distance(rca, p);
78 return d1 < d3 ? rab : rca;
80 return d2 < d3 ? rbc : rca;
93 glm::vec3 pdouble((
double)p.x, (
double)p.y, (
double)p.z);
94 return (isOnSameSide(pdouble, adouble, bdouble, cdouble) &&
95 isOnSameSide(pdouble, bdouble, adouble, cdouble) &&
96 isOnSameSide(pdouble, cdouble, adouble, bdouble));
111 const glm::vec3 c = p -
pointA;
113 const double dotAA = glm::dot(a, a);
114 const double dotAB = glm::dot(b, b);
115 const double dotAC = glm::dot(a, c);
116 const double dotBB = glm::dot(b, b);
117 const double dotBC = glm::dot(b, c);
120 const double invDenom = 1/(dotAA * dotBB - dotAB * dotAB);
121 const double u = (dotBB * dotAC - dotAB * dotBC) * invDenom;
122 const double v = (dotAA * dotBC - dotAB * dotAC) * invDenom;
136 glm::vec3& outIntersection)
const
154 const glm::vec3& lineVect, glm::vec3& outIntersection)
const
169 const glm::vec3& lineVect, glm::vec3& outIntersection)
const
172 const glm::vec3 linePointdouble(linePoint.x, linePoint.y, linePoint.z);
173 const glm::vec3 lineVectdouble(lineVect.x, lineVect.y, lineVect.z);
174 glm::vec3 outIntersectiondouble;
179 const glm::vec3 normaldouble = glm::normalize(triangledouble.
getNormal());
182 if (
core::iszero (t2 = glm::dot(normaldouble, lineVectdouble)))
185 double d = glm::dot(triangledouble.
pointA, normaldouble);
186 double t = -(glm::dot(normaldouble, linePointdouble) - d) / t2;
187 outIntersectiondouble = linePointdouble + (lineVectdouble * float(t));
189 outIntersection.x = (T)outIntersectiondouble.x;
190 outIntersection.y = (T)outIntersectiondouble.y;
191 outIntersection.z = (T)outIntersectiondouble.z;
211 const glm::vec3 n =
getNormal().normalize();
212 const float d = (float) glm::dot(n, lookDirection);
230 void set(
const glm::vec3& a,
const glm::vec3& b,
const glm::vec3& c)
244 bool isOnSameSide(
const glm::vec3& p1,
const glm::vec3& p2,
245 const glm::vec3& a,
const glm::vec3& b)
const
247 glm::vec3 bminusa = b - a;
248 glm::vec3 cp1 = glm::cross(bminusa, p1 - a);
249 glm::vec3 cp2 = glm::cross(bminusa, p2 - a);
250 double res = glm::dot(cp1, cp2);
255 glm::vec3 cp1 = glm::cross(glm::normalize(bminusa), (p1 - a));
256 cp1 = glm::normalize(cp1);
264 return (res >= 0.0f);
glm::vec3 getClosestPoint(const glm::vec3 &point) const
Get the closest point on this line to a point.
Template plane class with some intersection testing methods.
void set(const glm::vec3 &a, const glm::vec3 &b, const glm::vec3 &c)
sets the triangle's points
triangle3d< std::int32_t > triangle3di
Typedef for an integer 3d triangle.
bool isPointInside(const glm::vec3 &p) const
Determines if a point is within this box.
bool getIntersectionWithLimitedLine(const line3d< T > &line, glm::vec3 &outIntersection) const
Get an intersection with a 3d line.
bool operator!=(const triangle3d< T > &other) const
Inequality operator.
triangle3d< float > triangle3df
Typedef for a float 3d triangle.
T getArea() const
Get the area of the triangle.
glm::vec3 MinEdge
The near edge.
3D line between two points with intersection methods.
bool isTotalOutsideBox(const aabbox3d< T > &box) const
Determines if the triangle is totally outside a bounding box.
bool isFrontFacing(const glm::vec3 &lookDirection) const
Test if the triangle would be front or backfacing from any point.
Axis aligned bounding box in 3d dimensional space.
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.
bool isBetweenPoints(const glm::vec3 &point, const glm::vec3 &begin, const glm::vec3 &end)
const float ROUNDING_ERROR_float
bool isPointInside(const glm::vec3 &p) const
Check if a point is inside the triangle (border-points count also as inside)
glm::vec3 end
End point of line.
glm::vec3 getVector() const
Get vector of line.
glm::vec3 start
Start point of line.
#define F32_LOWER_EQUAL_0(n)
bool getIntersectionWithLine(const glm::vec3 &linePoint, const glm::vec3 &lineVect, glm::vec3 &outIntersection) const
Get an intersection with a 3d line.
glm::vec3 closestPointOnTriangle(const glm::vec3 &p) const
Get the closest point on a triangle to a point on the same plane.
glm::vec3 getNormal() const
Get the normal of the triangle.
triangle3d(const glm::vec3 &v1, const glm::vec3 &v2, const glm::vec3 &v3)
Constructor for triangle with given three vertices.
bool isTotalInsideBox(const aabbox3d< T > &box) const
Determines if the triangle is totally inside a bounding box.
glm::vec3 MaxEdge
The far edge.
plane3d< T > getPlane() const
Get the plane of this triangle.
bool iszero(const double a, const double tolerance=ROUNDING_ERROR_double)
returns if a equals zero, taking rounding errors into account
3d triangle template class for doing collision detection and other things.
glm::vec3 pointA
the three points of the triangle
bool isPointInsideFast(const glm::vec3 &p) const
Check if a point is inside the triangle (border-points count also as inside)
bool operator==(const triangle3d< T > &other) const
Equality operator.
triangle3d()
Constructor for an all 0 triangle.