Ocular Engine
Frustum.hpp
1 
17 #pragma once
18 #ifndef __H__OCULAR_MATH_FRUSTUM__H__
19 #define __H__OCULAR_MATH_FRUSTUM__H__
20 
21 #include "Math/Matrix4x4.hpp"
22 #include "Math/Geometry/Plane.hpp"
23 #include <array>
24 
25 //------------------------------------------------------------------------------------------
26 
31 namespace Ocular
32 {
37  namespace Math
38  {
39  class BoundsAABB;
40  class BoundsOBB;
41  class BoundsSphere;
42 
57  class Frustum
58  {
59  public:
60 
61  Frustum();
62  ~Frustum();
63 
64  //------------------------------------------------------------
65  // View and Projection matrix setting
66  //------------------------------------------------------------
67 
71  void rebuild();
72 
77  void setViewMatrix(Math::Matrix4x4 const& viewMatrix);
78 
83  void setProjectionMatrix(Math::Matrix4x4 const& projMatrix);
84 
85  Math::Matrix4x4 getViewMatrix() const;
86 
87  Math::Matrix4x4 getProjectionMatrix() const;
88 
89  //------------------------------------------------------------
90  // Misc Getters
91  //------------------------------------------------------------
92 
96  Vector3f const& getOrigin() const;
97 
107  std::array<Vector3f, 4> const& getNearClipCorners() const;
108 
118  std::array<Vector3f, 4> const& getFarClipCorners() const;
119 
120  //------------------------------------------------------------
121  // Containment Testing
122  //------------------------------------------------------------
123 
130  bool contains(Point3f const& point) const;
131 
138  bool contains(BoundsSphere const& bounds) const;
139 
146  bool contains(BoundsAABB const& bounds) const;
147 
154  bool contains(BoundsOBB const& bounds) const;
155 
156  //------------------------------------------------------------
157  // Property Retrieval
158  //------------------------------------------------------------
159 
164  float getNearClipDistance() const;
165 
170  float getFarClipDistance() const;
171 
175  Plane const& getLeftPlane() const;
176 
180  Plane const& getRightPlane() const;
181 
185  Plane const& getTopPlane() const;
186 
190  Plane const& getBottomPlane() const;
191 
195  Plane const& getNearPlane() const;
196 
200  Plane const& getFarPlane() const;
201 
205  float getFieldOfView() const;
206 
210  float getAspectRatio() const;
211 
215  float getXMin() const;
216 
220  float getXMax() const;
221 
225  float getYMin() const;
226 
230  float getYMax() const;
231 
232  protected:
233 
234  private:
235 
236  Math::Matrix4x4 m_ViewMatrix;
237  Math::Matrix4x4 m_ProjMatrix;
238 
239  float m_MinX;
240  float m_MaxX;
241  float m_MinY;
242  float m_MaxY;
243  float m_NearClip;
244  float m_FarClip;
245 
246  // Perspective-specific variables saved for user querying
247 
248  float m_FieldOfView;
249  float m_AspectRatio;
250 
251  Vector3f m_Origin;
252 
253  std::array<Vector3f, 4> m_NearCorners;
254  std::array<Vector3f, 4> m_FarCorners;
255 
256  Plane m_LeftPlane;
257  Plane m_RightPlane;
258  Plane m_TopPlane;
259  Plane m_BottomPlane;
260  Plane m_NearPlane;
261  Plane m_FarPlane;
262  };
263  }
267 }
272 //------------------------------------------------------------------------------------------
273 
274 #endif
float getXMin() const
Definition: Frustum.cpp:291
Plane const & getNearPlane() const
Definition: Frustum.cpp:271
void rebuild()
Definition: Frustum.cpp:52
float getAspectRatio() const
Definition: Frustum.cpp:286
void setProjectionMatrix(Math::Matrix4x4 const &projMatrix)
Definition: Frustum.cpp:132
void setViewMatrix(Math::Matrix4x4 const &viewMatrix)
Definition: Frustum.cpp:126
Definition: Euler.hpp:39
Definition: Frustum.hpp:57
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70
Definition: BoundsOBB.hpp:56
float getNearClipDistance() const
Definition: Frustum.cpp:241
Definition: Plane.hpp:50
std::array< Vector3f, 4 > const & getFarClipCorners() const
Definition: Frustum.cpp:161
bool contains(Point3f const &point) const
Definition: Frustum.cpp:170
Plane const & getTopPlane() const
Definition: Frustum.cpp:261
Plane const & getLeftPlane() const
Definition: Frustum.cpp:251
float getFieldOfView() const
Definition: Frustum.cpp:281
float getXMax() const
Definition: Frustum.cpp:296
Plane const & getFarPlane() const
Definition: Frustum.cpp:276
Plane const & getRightPlane() const
Definition: Frustum.cpp:256
float getYMax() const
Definition: Frustum.cpp:306
Vector3f const & getOrigin() const
Definition: Frustum.cpp:151
Plane const & getBottomPlane() const
Definition: Frustum.cpp:266
std::array< Vector3f, 4 > const & getNearClipCorners() const
Definition: Frustum.cpp:156
A 4x4 column-major float matrix.
Definition: Matrix4x4.hpp:64
float getFarClipDistance() const
Definition: Frustum.cpp:246
Definition: BoundsAABB.hpp:63
float getYMin() const
Definition: Frustum.cpp:301
Definition: BoundsSphere.hpp:52