aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/libraries/irrlicht-1.8/include/plane3d.h
diff options
context:
space:
mode:
authorDavid Walter Seikel2013-01-13 18:54:10 +1000
committerDavid Walter Seikel2013-01-13 18:54:10 +1000
commit959831f4ef5a3e797f576c3de08cd65032c997ad (patch)
treee7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/include/plane3d.h
parentAdd info about changes to Irrlicht. (diff)
downloadSledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2
SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to 'libraries/irrlicht-1.8/include/plane3d.h')
-rw-r--r--libraries/irrlicht-1.8/include/plane3d.h490
1 files changed, 245 insertions, 245 deletions
diff --git a/libraries/irrlicht-1.8/include/plane3d.h b/libraries/irrlicht-1.8/include/plane3d.h
index 9056dcd..02c6bf9 100644
--- a/libraries/irrlicht-1.8/include/plane3d.h
+++ b/libraries/irrlicht-1.8/include/plane3d.h
@@ -1,245 +1,245 @@
1// Copyright (C) 2002-2012 Nikolaus Gebhardt 1// Copyright (C) 2002-2012 Nikolaus Gebhardt
2// This file is part of the "Irrlicht Engine". 2// This file is part of the "Irrlicht Engine".
3// For conditions of distribution and use, see copyright notice in irrlicht.h 3// For conditions of distribution and use, see copyright notice in irrlicht.h
4 4
5#ifndef __IRR_PLANE_3D_H_INCLUDED__ 5#ifndef __IRR_PLANE_3D_H_INCLUDED__
6#define __IRR_PLANE_3D_H_INCLUDED__ 6#define __IRR_PLANE_3D_H_INCLUDED__
7 7
8#include "irrMath.h" 8#include "irrMath.h"
9#include "vector3d.h" 9#include "vector3d.h"
10 10
11namespace irr 11namespace irr
12{ 12{
13namespace core 13namespace core
14{ 14{
15 15
16//! Enumeration for intersection relations of 3d objects 16//! Enumeration for intersection relations of 3d objects
17enum EIntersectionRelation3D 17enum EIntersectionRelation3D
18{ 18{
19 ISREL3D_FRONT = 0, 19 ISREL3D_FRONT = 0,
20 ISREL3D_BACK, 20 ISREL3D_BACK,
21 ISREL3D_PLANAR, 21 ISREL3D_PLANAR,
22 ISREL3D_SPANNING, 22 ISREL3D_SPANNING,
23 ISREL3D_CLIPPED 23 ISREL3D_CLIPPED
24}; 24};
25 25
26//! Template plane class with some intersection testing methods. 26//! Template plane class with some intersection testing methods.
27/** It has to be ensured, that the normal is always normalized. The constructors 27/** It has to be ensured, that the normal is always normalized. The constructors
28 and setters of this class will not ensure this automatically. So any normal 28 and setters of this class will not ensure this automatically. So any normal
29 passed in has to be normalized in advance. No change to the normal will be 29 passed in has to be normalized in advance. No change to the normal will be
30 made by any of the class methods. 30 made by any of the class methods.
31*/ 31*/
32template <class T> 32template <class T>
33class plane3d 33class plane3d
34{ 34{
35 public: 35 public:
36 36
37 // Constructors 37 // Constructors
38 38
39 plane3d(): Normal(0,1,0) { recalculateD(vector3d<T>(0,0,0)); } 39 plane3d(): Normal(0,1,0) { recalculateD(vector3d<T>(0,0,0)); }
40 40
41 plane3d(const vector3d<T>& MPoint, const vector3d<T>& Normal) : Normal(Normal) { recalculateD(MPoint); } 41 plane3d(const vector3d<T>& MPoint, const vector3d<T>& Normal) : Normal(Normal) { recalculateD(MPoint); }
42 42
43 plane3d(T px, T py, T pz, T nx, T ny, T nz) : Normal(nx, ny, nz) { recalculateD(vector3d<T>(px, py, pz)); } 43 plane3d(T px, T py, T pz, T nx, T ny, T nz) : Normal(nx, ny, nz) { recalculateD(vector3d<T>(px, py, pz)); }
44 44
45 plane3d(const vector3d<T>& point1, const vector3d<T>& point2, const vector3d<T>& point3) 45 plane3d(const vector3d<T>& point1, const vector3d<T>& point2, const vector3d<T>& point3)
46 { setPlane(point1, point2, point3); } 46 { setPlane(point1, point2, point3); }
47 47
48 plane3d(const vector3d<T> & normal, const T d) : Normal(normal), D(d) { } 48 plane3d(const vector3d<T> & normal, const T d) : Normal(normal), D(d) { }
49 49
50 // operators 50 // operators
51 51
52 inline bool operator==(const plane3d<T>& other) const { return (equals(D, other.D) && Normal==other.Normal);} 52 inline bool operator==(const plane3d<T>& other) const { return (equals(D, other.D) && Normal==other.Normal);}
53 53
54 inline bool operator!=(const plane3d<T>& other) const { return !(*this == other);} 54 inline bool operator!=(const plane3d<T>& other) const { return !(*this == other);}
55 55
56 // functions 56 // functions
57 57
58 void setPlane(const vector3d<T>& point, const vector3d<T>& nvector) 58 void setPlane(const vector3d<T>& point, const vector3d<T>& nvector)
59 { 59 {
60 Normal = nvector; 60 Normal = nvector;
61 recalculateD(point); 61 recalculateD(point);
62 } 62 }
63 63
64 void setPlane(const vector3d<T>& nvect, T d) 64 void setPlane(const vector3d<T>& nvect, T d)
65 { 65 {
66 Normal = nvect; 66 Normal = nvect;
67 D = d; 67 D = d;
68 } 68 }
69 69
70 void setPlane(const vector3d<T>& point1, const vector3d<T>& point2, const vector3d<T>& point3) 70 void setPlane(const vector3d<T>& point1, const vector3d<T>& point2, const vector3d<T>& point3)
71 { 71 {
72 // creates the plane from 3 memberpoints 72 // creates the plane from 3 memberpoints
73 Normal = (point2 - point1).crossProduct(point3 - point1); 73 Normal = (point2 - point1).crossProduct(point3 - point1);
74 Normal.normalize(); 74 Normal.normalize();
75 75
76 recalculateD(point1); 76 recalculateD(point1);
77 } 77 }
78 78
79 79
80 //! Get an intersection with a 3d line. 80 //! Get an intersection with a 3d line.
81 /** \param lineVect Vector of the line to intersect with. 81 /** \param lineVect Vector of the line to intersect with.
82 \param linePoint Point of the line to intersect with. 82 \param linePoint Point of the line to intersect with.
83 \param outIntersection Place to store the intersection point, if there is one. 83 \param outIntersection Place to store the intersection point, if there is one.
84 \return True if there was an intersection, false if there was not. 84 \return True if there was an intersection, false if there was not.
85 */ 85 */
86 bool getIntersectionWithLine(const vector3d<T>& linePoint, 86 bool getIntersectionWithLine(const vector3d<T>& linePoint,
87 const vector3d<T>& lineVect, 87 const vector3d<T>& lineVect,
88 vector3d<T>& outIntersection) const 88 vector3d<T>& outIntersection) const
89 { 89 {
90 T t2 = Normal.dotProduct(lineVect); 90 T t2 = Normal.dotProduct(lineVect);
91 91
92 if (t2 == 0) 92 if (t2 == 0)
93 return false; 93 return false;
94 94
95 T t =- (Normal.dotProduct(linePoint) + D) / t2; 95 T t =- (Normal.dotProduct(linePoint) + D) / t2;
96 outIntersection = linePoint + (lineVect * t); 96 outIntersection = linePoint + (lineVect * t);
97 return true; 97 return true;
98 } 98 }
99 99
100 //! Get percentage of line between two points where an intersection with this plane happens. 100 //! Get percentage of line between two points where an intersection with this plane happens.
101 /** Only useful if known that there is an intersection. 101 /** Only useful if known that there is an intersection.
102 \param linePoint1 Point1 of the line to intersect with. 102 \param linePoint1 Point1 of the line to intersect with.
103 \param linePoint2 Point2 of the line to intersect with. 103 \param linePoint2 Point2 of the line to intersect with.
104 \return Where on a line between two points an intersection with this plane happened. 104 \return Where on a line between two points an intersection with this plane happened.
105 For example, 0.5 is returned if the intersection happened exactly in the middle of the two points. 105 For example, 0.5 is returned if the intersection happened exactly in the middle of the two points.
106 */ 106 */
107 f32 getKnownIntersectionWithLine(const vector3d<T>& linePoint1, 107 f32 getKnownIntersectionWithLine(const vector3d<T>& linePoint1,
108 const vector3d<T>& linePoint2) const 108 const vector3d<T>& linePoint2) const
109 { 109 {
110 vector3d<T> vect = linePoint2 - linePoint1; 110 vector3d<T> vect = linePoint2 - linePoint1;
111 T t2 = (f32)Normal.dotProduct(vect); 111 T t2 = (f32)Normal.dotProduct(vect);
112 return (f32)-((Normal.dotProduct(linePoint1) + D) / t2); 112 return (f32)-((Normal.dotProduct(linePoint1) + D) / t2);
113 } 113 }
114 114
115 //! Get an intersection with a 3d line, limited between two 3d points. 115 //! Get an intersection with a 3d line, limited between two 3d points.
116 /** \param linePoint1 Point 1 of the line. 116 /** \param linePoint1 Point 1 of the line.
117 \param linePoint2 Point 2 of the line. 117 \param linePoint2 Point 2 of the line.
118 \param outIntersection Place to store the intersection point, if there is one. 118 \param outIntersection Place to store the intersection point, if there is one.
119 \return True if there was an intersection, false if there was not. 119 \return True if there was an intersection, false if there was not.
120 */ 120 */
121 bool getIntersectionWithLimitedLine( 121 bool getIntersectionWithLimitedLine(
122 const vector3d<T>& linePoint1, 122 const vector3d<T>& linePoint1,
123 const vector3d<T>& linePoint2, 123 const vector3d<T>& linePoint2,
124 vector3d<T>& outIntersection) const 124 vector3d<T>& outIntersection) const
125 { 125 {
126 return (getIntersectionWithLine(linePoint1, linePoint2 - linePoint1, outIntersection) && 126 return (getIntersectionWithLine(linePoint1, linePoint2 - linePoint1, outIntersection) &&
127 outIntersection.isBetweenPoints(linePoint1, linePoint2)); 127 outIntersection.isBetweenPoints(linePoint1, linePoint2));
128 } 128 }
129 129
130 //! Classifies the relation of a point to this plane. 130 //! Classifies the relation of a point to this plane.
131 /** \param point Point to classify its relation. 131 /** \param point Point to classify its relation.
132 \return ISREL3D_FRONT if the point is in front of the plane, 132 \return ISREL3D_FRONT if the point is in front of the plane,
133 ISREL3D_BACK if the point is behind of the plane, and 133 ISREL3D_BACK if the point is behind of the plane, and
134 ISREL3D_PLANAR if the point is within the plane. */ 134 ISREL3D_PLANAR if the point is within the plane. */
135 EIntersectionRelation3D classifyPointRelation(const vector3d<T>& point) const 135 EIntersectionRelation3D classifyPointRelation(const vector3d<T>& point) const
136 { 136 {
137 const T d = Normal.dotProduct(point) + D; 137 const T d = Normal.dotProduct(point) + D;
138 138
139 if (d < -ROUNDING_ERROR_f32) 139 if (d < -ROUNDING_ERROR_f32)
140 return ISREL3D_BACK; 140 return ISREL3D_BACK;
141 141
142 if (d > ROUNDING_ERROR_f32) 142 if (d > ROUNDING_ERROR_f32)
143 return ISREL3D_FRONT; 143 return ISREL3D_FRONT;
144 144
145 return ISREL3D_PLANAR; 145 return ISREL3D_PLANAR;
146 } 146 }
147 147
148 //! Recalculates the distance from origin by applying a new member point to the plane. 148 //! Recalculates the distance from origin by applying a new member point to the plane.
149 void recalculateD(const vector3d<T>& MPoint) 149 void recalculateD(const vector3d<T>& MPoint)
150 { 150 {
151 D = - MPoint.dotProduct(Normal); 151 D = - MPoint.dotProduct(Normal);
152 } 152 }
153 153
154 //! Gets a member point of the plane. 154 //! Gets a member point of the plane.
155 vector3d<T> getMemberPoint() const 155 vector3d<T> getMemberPoint() const
156 { 156 {
157 return Normal * -D; 157 return Normal * -D;
158 } 158 }
159 159
160 //! Tests if there is an intersection with the other plane 160 //! Tests if there is an intersection with the other plane
161 /** \return True if there is a intersection. */ 161 /** \return True if there is a intersection. */
162 bool existsIntersection(const plane3d<T>& other) const 162 bool existsIntersection(const plane3d<T>& other) const
163 { 163 {
164 vector3d<T> cross = other.Normal.crossProduct(Normal); 164 vector3d<T> cross = other.Normal.crossProduct(Normal);
165 return cross.getLength() > core::ROUNDING_ERROR_f32; 165 return cross.getLength() > core::ROUNDING_ERROR_f32;
166 } 166 }
167 167
168 //! Intersects this plane with another. 168 //! Intersects this plane with another.
169 /** \param other Other plane to intersect with. 169 /** \param other Other plane to intersect with.
170 \param outLinePoint Base point of intersection line. 170 \param outLinePoint Base point of intersection line.
171 \param outLineVect Vector of intersection. 171 \param outLineVect Vector of intersection.
172 \return True if there is a intersection, false if not. */ 172 \return True if there is a intersection, false if not. */
173 bool getIntersectionWithPlane(const plane3d<T>& other, 173 bool getIntersectionWithPlane(const plane3d<T>& other,
174 vector3d<T>& outLinePoint, 174 vector3d<T>& outLinePoint,
175 vector3d<T>& outLineVect) const 175 vector3d<T>& outLineVect) const
176 { 176 {
177 const T fn00 = Normal.getLength(); 177 const T fn00 = Normal.getLength();
178 const T fn01 = Normal.dotProduct(other.Normal); 178 const T fn01 = Normal.dotProduct(other.Normal);
179 const T fn11 = other.Normal.getLength(); 179 const T fn11 = other.Normal.getLength();
180 const f64 det = fn00*fn11 - fn01*fn01; 180 const f64 det = fn00*fn11 - fn01*fn01;
181 181
182 if (fabs(det) < ROUNDING_ERROR_f64 ) 182 if (fabs(det) < ROUNDING_ERROR_f64 )
183 return false; 183 return false;
184 184
185 const f64 invdet = 1.0 / det; 185 const f64 invdet = 1.0 / det;
186 const f64 fc0 = (fn11*-D + fn01*other.D) * invdet; 186 const f64 fc0 = (fn11*-D + fn01*other.D) * invdet;
187 const f64 fc1 = (fn00*-other.D + fn01*D) * invdet; 187 const f64 fc1 = (fn00*-other.D + fn01*D) * invdet;
188 188
189 outLineVect = Normal.crossProduct(other.Normal); 189 outLineVect = Normal.crossProduct(other.Normal);
190 outLinePoint = Normal*(T)fc0 + other.Normal*(T)fc1; 190 outLinePoint = Normal*(T)fc0 + other.Normal*(T)fc1;
191 return true; 191 return true;
192 } 192 }
193 193
194 //! Get the intersection point with two other planes if there is one. 194 //! Get the intersection point with two other planes if there is one.
195 bool getIntersectionWithPlanes(const plane3d<T>& o1, 195 bool getIntersectionWithPlanes(const plane3d<T>& o1,
196 const plane3d<T>& o2, vector3d<T>& outPoint) const 196 const plane3d<T>& o2, vector3d<T>& outPoint) const
197 { 197 {
198 vector3d<T> linePoint, lineVect; 198 vector3d<T> linePoint, lineVect;
199 if (getIntersectionWithPlane(o1, linePoint, lineVect)) 199 if (getIntersectionWithPlane(o1, linePoint, lineVect))
200 return o2.getIntersectionWithLine(linePoint, lineVect, outPoint); 200 return o2.getIntersectionWithLine(linePoint, lineVect, outPoint);
201 201
202 return false; 202 return false;
203 } 203 }
204 204
205 //! Test if the triangle would be front or backfacing from any point. 205 //! Test if the triangle would be front or backfacing from any point.
206 /** Thus, this method assumes a camera position from 206 /** Thus, this method assumes a camera position from
207 which the triangle is definitely visible when looking into 207 which the triangle is definitely visible when looking into
208 the given direction. 208 the given direction.
209 Note that this only works if the normal is Normalized. 209 Note that this only works if the normal is Normalized.
210 Do not use this method with points as it will give wrong results! 210 Do not use this method with points as it will give wrong results!
211 \param lookDirection: Look direction. 211 \param lookDirection: Look direction.
212 \return True if the plane is front facing and 212 \return True if the plane is front facing and
213 false if it is backfacing. */ 213 false if it is backfacing. */
214 bool isFrontFacing(const vector3d<T>& lookDirection) const 214 bool isFrontFacing(const vector3d<T>& lookDirection) const
215 { 215 {
216 const f32 d = Normal.dotProduct(lookDirection); 216 const f32 d = Normal.dotProduct(lookDirection);
217 return F32_LOWER_EQUAL_0 ( d ); 217 return F32_LOWER_EQUAL_0 ( d );
218 } 218 }
219 219
220 //! Get the distance to a point. 220 //! Get the distance to a point.
221 /** Note that this only works if the normal is normalized. */ 221 /** Note that this only works if the normal is normalized. */
222 T getDistanceTo(const vector3d<T>& point) const 222 T getDistanceTo(const vector3d<T>& point) const
223 { 223 {
224 return point.dotProduct(Normal) + D; 224 return point.dotProduct(Normal) + D;
225 } 225 }
226 226
227 //! Normal vector of the plane. 227 //! Normal vector of the plane.
228 vector3d<T> Normal; 228 vector3d<T> Normal;
229 229
230 //! Distance from origin. 230 //! Distance from origin.
231 T D; 231 T D;
232}; 232};
233 233
234 234
235//! Typedef for a f32 3d plane. 235//! Typedef for a f32 3d plane.
236typedef plane3d<f32> plane3df; 236typedef plane3d<f32> plane3df;
237 237
238//! Typedef for an integer 3d plane. 238//! Typedef for an integer 3d plane.
239typedef plane3d<s32> plane3di; 239typedef plane3d<s32> plane3di;
240 240
241} // end namespace core 241} // end namespace core
242} // end namespace irr 242} // end namespace irr
243 243
244#endif 244#endif
245 245