Irrlicht 3D Engine
 
Loading...
Searching...
No Matches
plane3d.h
Go to the documentation of this file.
1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h
4
5#ifndef __IRR_PLANE_3D_H_INCLUDED__
6#define __IRR_PLANE_3D_H_INCLUDED__
7
8#include "irrMath.h"
9#include "vector3d.h"
10
11namespace irr
12{
13namespace core
14{
15
25
27
32template <class T>
34{
35 public:
36
37 // Constructors
38
39 plane3d(): Normal(0,1,0) { recalculateD(vector3d<T>(0,0,0)); }
40
42
44
47
48 plane3d(const vector3d<T> & normal, const T d) : Normal(normal), D(d) { }
49
50 // operators
51
52 inline bool operator==(const plane3d<T>& other) const { return (equals(D, other.D) && Normal==other.Normal);}
53
54 inline bool operator!=(const plane3d<T>& other) const { return !(*this == other);}
55
56 // functions
57
59 {
62 }
63
65 {
66 Normal = nvect;
67 D = d;
68 }
69
71 {
72 // creates the plane from 3 memberpoints
73 Normal = (point2 - point1).crossProduct(point3 - point1);
74 Normal.normalize();
75
77 }
78
79
81
87 const vector3d<T>& lineVect,
89 {
90 T t2 = Normal.dotProduct(lineVect);
91
92 if (t2 == 0)
93 return false;
94
95 T t =- (Normal.dotProduct(linePoint) + D) / t2;
97 return true;
98 }
99
101
108 const vector3d<T>& linePoint2) const
109 {
111 T t2 = (f32)Normal.dotProduct(vect);
112 return (f32)-((Normal.dotProduct(linePoint1) + D) / t2);
113 }
114
116
129
131
136 {
137 const T d = Normal.dotProduct(point) + D;
138
139 if (d < -ROUNDING_ERROR_f32)
140 return ISREL3D_BACK;
141
142 if (d > ROUNDING_ERROR_f32)
143 return ISREL3D_FRONT;
144
145 return ISREL3D_PLANAR;
146 }
147
150 {
151 D = - MPoint.dotProduct(Normal);
152 }
153
156 {
157 return Normal * -D;
158 }
159
161
163 {
164 vector3d<T> cross = other.Normal.crossProduct(Normal);
165 return cross.getLength() > core::ROUNDING_ERROR_f32;
166 }
167
169
176 {
177 const T fn00 = Normal.getLength();
178 const T fn01 = Normal.dotProduct(other.Normal);
179 const T fn11 = other.Normal.getLength();
180 const f64 det = fn00*fn11 - fn01*fn01;
181
183 return false;
184
185 const f64 invdet = 1.0 / det;
186 const f64 fc0 = (fn11*-D + fn01*other.D) * invdet;
187 const f64 fc1 = (fn00*-other.D + fn01*D) * invdet;
188
189 outLineVect = Normal.crossProduct(other.Normal);
190 outLinePoint = Normal*(T)fc0 + other.Normal*(T)fc1;
191 return true;
192 }
193
196 const plane3d<T>& o2, vector3d<T>& outPoint) const
197 {
200 return o2.getIntersectionWithLine(linePoint, lineVect, outPoint);
201
202 return false;
203 }
204
206
215 {
216 const f32 d = Normal.dotProduct(lookDirection);
217 return F32_LOWER_EQUAL_0 ( d );
218 }
219
221
223 {
224 return point.dotProduct(Normal) + D;
225 }
226
229
232};
233
234
237
240
241} // end namespace core
242} // end namespace irr
243
244#endif
245
Axis aligned bounding box in 3d dimensional space.
Definition aabbox3d.h:22
Template plane class with some intersection testing methods.
Definition plane3d.h:34
EIntersectionRelation3D classifyPointRelation(const vector3d< T > &point) const
Classifies the relation of a point to this plane.
Definition plane3d.h:135
void setPlane(const vector3d< T > &nvect, T d)
Definition plane3d.h:64
vector3d< T > getMemberPoint() const
Gets a member point of the plane.
Definition plane3d.h:155
void setPlane(const vector3d< T > &point1, const vector3d< T > &point2, const vector3d< T > &point3)
Definition plane3d.h:70
plane3d(const vector3d< T > &normal, const T d)
Definition plane3d.h:48
f32 getKnownIntersectionWithLine(const vector3d< T > &linePoint1, const vector3d< T > &linePoint2) const
Get percentage of line between two points where an intersection with this plane happens.
Definition plane3d.h:107
bool existsIntersection(const plane3d< T > &other) const
Tests if there is an intersection with the other plane.
Definition plane3d.h:162
void recalculateD(const vector3d< T > &MPoint)
Recalculates the distance from origin by applying a new member point to the plane.
Definition plane3d.h:149
bool getIntersectionWithLimitedLine(const vector3d< T > &linePoint1, const vector3d< T > &linePoint2, vector3d< T > &outIntersection) const
Get an intersection with a 3d line, limited between two 3d points.
Definition plane3d.h:121
void setPlane(const vector3d< T > &point, const vector3d< T > &nvector)
Definition plane3d.h:58
plane3d(const vector3d< T > &point1, const vector3d< T > &point2, const vector3d< T > &point3)
Definition plane3d.h:45
plane3d(const vector3d< T > &MPoint, const vector3d< T > &Normal)
Definition plane3d.h:41
vector3d< T > Normal
Normal vector of the plane.
Definition plane3d.h:228
bool getIntersectionWithPlanes(const plane3d< T > &o1, const plane3d< T > &o2, vector3d< T > &outPoint) const
Get the intersection point with two other planes if there is one.
Definition plane3d.h:195
bool getIntersectionWithPlane(const plane3d< T > &other, vector3d< T > &outLinePoint, vector3d< T > &outLineVect) const
Intersects this plane with another.
Definition plane3d.h:173
T getDistanceTo(const vector3d< T > &point) const
Get the distance to a point.
Definition plane3d.h:222
bool isFrontFacing(const vector3d< T > &lookDirection) const
Test if the triangle would be front or backfacing from any point.
Definition plane3d.h:214
bool operator==(const plane3d< T > &other) const
Definition plane3d.h:52
bool operator!=(const plane3d< T > &other) const
Definition plane3d.h:54
bool getIntersectionWithLine(const vector3d< T > &linePoint, const vector3d< T > &lineVect, vector3d< T > &outIntersection) const
Get an intersection with a 3d line.
Definition plane3d.h:86
plane3d(T px, T py, T pz, T nx, T ny, T nz)
Definition plane3d.h:43
T D
Distance from origin.
Definition plane3d.h:231
#define F32_LOWER_EQUAL_0(n)
Definition irrMath.h:386
const f64 ROUNDING_ERROR_f64
Definition irrMath.h:50
EIntersectionRelation3D
Enumeration for intersection relations of 3d objects.
Definition plane3d.h:18
@ ISREL3D_SPANNING
Definition plane3d.h:22
@ ISREL3D_FRONT
Definition plane3d.h:19
@ ISREL3D_CLIPPED
Definition plane3d.h:23
@ ISREL3D_PLANAR
Definition plane3d.h:21
@ ISREL3D_BACK
Definition plane3d.h:20
const f32 ROUNDING_ERROR_f32
Definition irrMath.h:49
bool equals(const f64 a, const f64 b, const f64 tolerance=ROUNDING_ERROR_f64)
returns if a equals b, taking possible rounding errors into account
Definition irrMath.h:185
plane3d< f32 > plane3df
Typedef for a f32 3d plane.
Definition plane3d.h:236
plane3d< s32 > plane3di
Typedef for an integer 3d plane.
Definition plane3d.h:239
Everything in the Irrlicht Engine can be found in this namespace.
Definition aabbox3d.h:13
float f32
32 bit floating point variable.
Definition irrTypes.h:104
double f64
64 bit floating point variable.
Definition irrTypes.h:108