5#ifndef __IRR_TRIANGLE_3D_H_INCLUDED__
6#define __IRR_TRIANGLE_3D_H_INCLUDED__
18 #define INLINE_CROSSPRODUCT(ret, a, b) ret.X = a.Y * b.Z - a.Z * b.Y; ret.Y = a.Z * b.X - a.X * b.Z; ret.Z = a.X * b.Y - a.Y * b.X
34 return other.
pointA==
pointA && other.pointB==pointB && other.pointC==pointC;
40 return !(*
this==other);
81 return d1 < d3 ? rab : rca;
83 return d2 < d3 ? rbc : rca;
99 bf64.
X = (
f64)pointB.X;
100 bf64.
Y = (
f64)pointB.Y;
101 bf64.
Z = (
f64)pointB.Z;
104 cf64.
X = (
f64)pointC.X;
105 cf64.
Y = (
f64)pointC.Y;
106 cf64.
Z = (
f64)pointC.Z;
113 return (isOnSameSide(pf64, af64, bf64, cf64) &&
114 isOnSameSide(pf64, bf64, af64, cf64) &&
115 isOnSameSide(pf64, cf64, af64, bf64));
139 const f64 invDenom = 1/(dotAA * dotBB - dotAB * dotAB);
140 const f64 u = (dotBB * dotAC - dotAB * dotBC) * invDenom;
141 const f64 v = (dotAA * dotBC - dotAB * dotAC ) * invDenom;
145 return (u > -ROUNDING_ERROR_f32) && (v >= 0) && (u + v < 1+ROUNDING_ERROR_f32);
192 linePointf64.
X = linePoint.
X;
193 linePointf64.
Y = linePoint.
Y;
194 linePointf64.
Z = linePoint.
Z;
199 lineVectf64.
X = lineVect.
X;
200 lineVectf64.
Y = lineVect.
Y;
201 lineVectf64.
Z = lineVect.
Z;
211 trianglef64.pointB.X = (
f64)pointB.X;
212 trianglef64.pointB.Y = (
f64)pointB.Y;
213 trianglef64.pointB.Z = (
f64)pointB.Z;
215 trianglef64.pointC.X = (
f64)pointC.X;
216 trianglef64.pointC.Y = (
f64)pointC.Y;
217 trianglef64.pointC.Z = (
f64)pointC.Z;
225 f64 d = trianglef64.
pointA.dotProduct(normalf64);
228 outIntersectionf64.
X = linePointf64.
X + (lineVectf64.
X * t);
229 outIntersectionf64.
Y = linePointf64.
Y + (lineVectf64.
Y * t);
230 outIntersectionf64.
Z = linePointf64.
Z + (lineVectf64.
Z * t);
232 outIntersection.
X = (T)outIntersectionf64.
X;
233 outIntersection.
Y = (T)outIntersectionf64.
Y;
234 outIntersection.
Z = (T)outIntersectionf64.
Z;
257 return F32_LOWER_EQUAL_0(d);
269 return (pointB -
pointA).crossProduct(pointC -
pointA).getLength() * 0.5f;
292 bminusa.
X = b.
X - a.
X;
293 bminusa.
Y = b.
Y - a.
Y;
294 bminusa.
Z = b.
Z - a.
Z;
297 p1minusa.
X = p1.
X - a.
X;
298 p1minusa.
Y = p1.
Y - a.
Y;
299 p1minusa.
Z = p1.
Z - a.
Z;
302 p2minusa.
X = p2.
X - a.
X;
303 p2minusa.
Y = p2.
Y - a.
Y;
304 p2minusa.
Z = p2.
Z - a.
Z;
307 INLINE_CROSSPRODUCT(cp1, bminusa, p1minusa);
310 INLINE_CROSSPRODUCT(cp2, bminusa, p2minusa);
320 INLINE_CROSSPRODUCT(cp1, bminusa, p1minusa);
329 return (res >= 0.0f);
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.h:22
vector3d< T > MaxEdge
The far edge.
Definition aabbox3d.h:347
vector3d< T > MinEdge
The near edge.
Definition aabbox3d.h:344
bool isPointInside(const vector3d< T > &p) const
Determines if a point is within this box.
Definition aabbox3d.h:209
3D line between two points with intersection methods.
Definition line3d.h:19
vector3d< T > start
Start point of line.
Definition line3d.h:130
vector3d< T > getClosestPoint(const vector3d< T > &point) const
Get the closest point on this line to a point.
Definition line3d.h:89
vector3d< T > getVector() const
Get vector of line.
Definition line3d.h:71
vector3d< T > end
End point of line.
Definition line3d.h:132
Template plane class with some intersection testing methods.
Definition plane3d.h:34
3d triangle template class for doing collision detection and other things.
Definition triangle3d.h:23
bool getIntersectionWithLimitedLine(const line3d< T > &line, vector3d< T > &outIntersection) const
Get an intersection with a 3d line.
Definition triangle3d.h:154
triangle3d()
Constructor for an all 0 triangle.
Definition triangle3d.h:27
triangle3d(vector3d< T > v1, vector3d< T > v2, vector3d< T > v3)
Constructor for triangle with given three vertices.
Definition triangle3d.h:29
plane3d< T > getPlane() const
Get the plane of this triangle.
Definition triangle3d.h:261
bool getIntersectionWithLine(const vector3d< T > &linePoint, const vector3d< T > &lineVect, vector3d< T > &outIntersection) const
Get an intersection with a 3d line.
Definition triangle3d.h:172
bool getIntersectionOfPlaneWithLine(const vector3d< T > &linePoint, const vector3d< T > &lineVect, vector3d< T > &outIntersection) const
Calculates the intersection between a 3d line and the plane the triangle is on.
Definition triangle3d.h:187
bool isPointInsideFast(const vector3d< T > &p) const
Check if a point is inside the triangle (border-points count also as inside).
Definition triangle3d.h:126
bool operator!=(const triangle3d< T > &other) const
Inequality operator.
Definition triangle3d.h:38
bool isTotalInsideBox(const aabbox3d< T > &box) const
Determines if the triangle is totally inside a bounding box.
Definition triangle3d.h:46
bool isFrontFacing(const vector3d< T > &lookDirection) const
Test if the triangle would be front or backfacing from any point.
Definition triangle3d.h:253
core::vector3d< T > closestPointOnTriangle(const core::vector3d< T > &p) const
Get the closest point on a triangle to a point on the same plane.
Definition triangle3d.h:70
bool operator==(const triangle3d< T > &other) const
Equality operator.
Definition triangle3d.h:32
bool isPointInside(const vector3d< T > &p) const
Check if a point is inside the triangle (border-points count also as inside).
Definition triangle3d.h:91
bool isTotalOutsideBox(const aabbox3d< T > &box) const
Determines if the triangle is totally outside a bounding box.
Definition triangle3d.h:56
vector3d< f32 > pointA
Definition triangle3d.h:282
vector3d< T > getNormal() const
Get the normal of the triangle.
Definition triangle3d.h:242
void set(const core::vector3d< T > &a, const core::vector3d< T > &b, const core::vector3d< T > &c)
sets the triangle's points
Definition triangle3d.h:274
T getArea() const
Get the area of the triangle.
Definition triangle3d.h:267
3d vector template class with lots of operators and methods.
Definition vector3d.h:23
vector3d< T > crossProduct(const vector3d< T > &p) const
Calculates the cross product with another vector.
Definition vector3d.h:147
T X
X coordinate of the vector.
Definition vector3d.h:408
vector3d< T > & normalize()
Normalizes the vector.
Definition vector3d.h:168
T getDistanceFrom(const vector3d< T > &other) const
Get distance from another point.
Definition vector3d.h:132
bool isBetweenPoints(const vector3d< T > &begin, const vector3d< T > &end) const
Returns if this vector interpreted as a point is on a line between two other points.
Definition vector3d.h:157
T Z
Z coordinate of the vector.
Definition vector3d.h:414
T dotProduct(const vector3d< T > &other) const
Get the dot product with another vector.
Definition vector3d.h:125
T Y
Y coordinate of the vector.
Definition vector3d.h:411
Basic classes such as vectors, planes, arrays, lists, and so on can be found in this namespace.
Definition aabbox3d.h:15
triangle3d< f32 > triangle3df
Typedef for a f32 3d triangle.
Definition triangle3d.h:335
triangle3d< s32 > triangle3di
Typedef for an integer 3d triangle.
Definition triangle3d.h:338
bool iszero(const f64 a, const f64 tolerance=ROUNDING_ERROR_f64)
returns if a equals zero, taking rounding errors into account
Definition irrMath.h:270
Everything in the Irrlicht Engine can be found in this namespace.
Definition Skylicht.h:33
float f32
32 bit floating point variable.
Definition irrTypes.h:104
double f64
64 bit floating point variable.
Definition irrTypes.h:108