GteFrustum3.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <Mathematics/GteVector3.h>
11 
12 // Orthogonal frustum. Let E be the origin, D be the direction vector, U be
13 // the up vector, and R be the right vector. Let u > 0 and r > 0 be the
14 // extents in the U and R directions, respectively. Let n and f be the
15 // extents in the D direction with 0 < n < f. The four corners of the frustum
16 // in the near plane are E + n*D + s0*u*U + s1*r*R where |s0| = |s1| = 1 (four
17 // choices). The four corners of the frustum in the far plane are
18 // E + f*D + (f/n)*(s0*u*U + s1*r*R) where |s0| = |s1| = 1 (four choices).
19 
20 namespace gte
21 {
22 
23 template <typename Real>
24 class Frustum3
25 {
26 public:
27  // Construction and destruction. The default constructor sets the
28  // following values: origin (E) to (0,0,0), dVector (D) to (0,0,1),
29  // uVector (U) to (0,1,0), rVector (R) to (1,0,0), dMin (n) to 1,
30  // dMax (f) to 2, uBound (u) to 1, and rBound (r) to 1.
31  Frustum3();
32  Frustum3(Vector3<Real> const& inOrigin, Vector3<Real> const& inDVector,
33  Vector3<Real> const& inUVector, Vector3<Real> const& inRVector,
34  Real inDMin, Real inDMax, Real inUBound, Real inRBound);
35 
36  // The Update() function must be called whenever changes are made to DMIN,
37  // DMax, UBound, or RBound. The values mDRatio, mMTwoUF, and mMTwoRF are
38  // dependent on the changes, so call the Get*() accessors only after the
39  // Update() call.
40  void Update();
41  inline Real GetDRatio() const;
42  inline Real GetMTwoUF() const;
43  inline Real GetMTwoRF() const;
44 
45  void ComputeVertices(Vector3<Real> vertex[8]) const;
46 
49 
50 public:
51  // Comparisons to support sorted containers.
52  bool operator==(Frustum3 const& frustum) const;
53  bool operator!=(Frustum3 const& frustum) const;
54  bool operator< (Frustum3 const& frustum) const;
55  bool operator<=(Frustum3 const& frustum) const;
56  bool operator> (Frustum3 const& frustum) const;
57  bool operator>=(Frustum3 const& frustum) const;
58 
59 protected:
60  // Quantities derived from the constructor inputs.
62 };
63 
64 
65 template <typename Real>
67  :
68  origin(Vector3<Real>::Zero()),
69  dVector(Vector3<Real>::Unit(2)),
70  uVector(Vector3<Real>::Unit(1)),
71  rVector(Vector3<Real>::Unit(0)),
72  dMin((Real)1),
73  dMax((Real)2),
74  uBound((Real)1),
75  rBound((Real)1)
76 {
77  Update();
78 }
79 
80 template <typename Real>
82  Vector3<Real> const& inDVector, Vector3<Real> const& inUVector,
83  Vector3<Real> const& inRVector, Real inDMin, Real inDMax, Real inUBound,
84  Real inRBound)
85  :
86  origin(inOrigin),
87  dVector(inDVector),
88  uVector(inUVector),
89  rVector(inRVector),
90  dMin(inDMin),
91  dMax(inDMax),
92  uBound(inUBound),
93  rBound(inRBound)
94 {
95  Update();
96 }
97 
98 template <typename Real>
100 {
101  mDRatio = dMax / dMin;
102  mMTwoUF = ((Real)-2) * uBound * dMax;
103  mMTwoRF = ((Real)-2) * rBound * dMax;
104 }
105 
106 template <typename Real> inline
108 {
109  return mDRatio;
110 }
111 
112 template <typename Real> inline
114 {
115  return mMTwoUF;
116 }
117 
118 template <typename Real> inline
120 {
121  return mMTwoRF;
122 }
123 
124 template <typename Real>
126 {
127  Vector3<Real> dScaled = dMin * dVector;
128  Vector3<Real> uScaled = uBound * uVector;
129  Vector3<Real> rScaled = rBound * rVector;
130 
131  vertex[0] = dScaled - uScaled - rScaled;
132  vertex[1] = dScaled - uScaled + rScaled;
133  vertex[2] = dScaled + uScaled + rScaled;
134  vertex[3] = dScaled + uScaled - rScaled;
135 
136  for (int i = 0, ip = 4; i < 4; ++i, ++ip)
137  {
138  vertex[ip] = origin + mDRatio * vertex[i];
139  vertex[i] += origin;
140  }
141 }
142 
143 template <typename Real>
144 bool Frustum3<Real>::operator==(Frustum3 const& frustum) const
145 {
146  return origin == frustum.origin
147  && dVector == frustum.dVector
148  && uVector == frustum.uVector
149  && rVector == frustum.rVector
150  && dMin == frustum.dMin
151  && dMax == frustum.dMax
152  && uBound == frustum.uBound
153  && rBound == frustum.rBound;
154 }
155 
156 template <typename Real>
157 bool Frustum3<Real>::operator!=(Frustum3 const& frustum) const
158 {
159  return !operator==(frustum);
160 }
161 
162 template <typename Real>
163 bool Frustum3<Real>::operator<(Frustum3 const& frustum) const
164 {
165  if (origin < frustum.origin)
166  {
167  return true;
168  }
169 
170  if (origin > frustum.origin)
171  {
172  return false;
173  }
174 
175  if (dVector < frustum.dVector)
176  {
177  return true;
178  }
179 
180  if (dVector > frustum.dVector)
181  {
182  return false;
183  }
184 
185  if (uVector < frustum.uVector)
186  {
187  return true;
188  }
189 
190  if (uVector > frustum.uVector)
191  {
192  return false;
193  }
194 
195  if (rVector < frustum.rVector)
196  {
197  return true;
198  }
199 
200  if (rVector > frustum.rVector)
201  {
202  return false;
203  }
204 
205  if (dMin < frustum.dMin)
206  {
207  return true;
208  }
209 
210  if (dMin > frustum.dMin)
211  {
212  return false;
213  }
214 
215  if (dMax < frustum.dMax)
216  {
217  return true;
218  }
219 
220  if (dMax > frustum.dMax)
221  {
222  return false;
223  }
224 
225  if (uBound < frustum.uBound)
226  {
227  return true;
228  }
229 
230  if (uBound > frustum.uBound)
231  {
232  return false;
233  }
234 
235  return rBound < frustum.rBound;
236 }
237 
238 template <typename Real>
239 bool Frustum3<Real>::operator<=(Frustum3 const& frustum) const
240 {
241  return operator<(frustum) || operator==(frustum);
242 }
243 
244 template <typename Real>
245 bool Frustum3<Real>::operator>(Frustum3 const& frustum) const
246 {
247  return !operator<=(frustum);
248 }
249 
250 template <typename Real>
251 bool Frustum3<Real>::operator>=(Frustum3 const& frustum) const
252 {
253  return !operator<(frustum);
254 }
255 
256 
257 }
bool operator>(Frustum3 const &frustum) const
Definition: GteFrustum3.h:245
bool operator!=(Frustum3 const &frustum) const
Definition: GteFrustum3.h:157
void Update()
Definition: GteFrustum3.h:99
Vector3< Real > uVector
Definition: GteFrustum3.h:47
Vector3< Real > origin
Definition: GteFrustum3.h:47
bool operator>=(Frustum3 const &frustum) const
Definition: GteFrustum3.h:251
Vector3< Real > rVector
Definition: GteFrustum3.h:47
bool operator<(Frustum3 const &frustum) const
Definition: GteFrustum3.h:163
bool operator<=(Frustum3 const &frustum) const
Definition: GteFrustum3.h:239
bool operator==(Frustum3 const &frustum) const
Definition: GteFrustum3.h:144
void ComputeVertices(Vector3< Real > vertex[8]) const
Definition: GteFrustum3.h:125
Real GetMTwoRF() const
Definition: GteFrustum3.h:119
Real GetDRatio() const
Definition: GteFrustum3.h:107
Vector3< Real > dVector
Definition: GteFrustum3.h:47
Real GetMTwoUF() const
Definition: GteFrustum3.h:113


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59