CUGL 1.3
Cornell University Game Library
All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends
CUFrustum.h
1 //
2 // CUFrustum.h
3 // Cornell University Game Library (CUGL)
4 //
5 // This module provides support for a 3d viewing frustrum. This is a bit
6 // heavy-weight for our cameras, so we pulled it out..
7 //
8 // Because math objects are intended to be on the stack, we do not provide
9 // any shared pointer support in this class.
10 //
11 // CUGL MIT License:
12 // This software is provided 'as-is', without any express or implied
13 // warranty. In no event will the authors be held liable for any damages
14 // arising from the use of this software.
15 //
16 // Permission is granted to anyone to use this software for any purpose,
17 // including commercial applications, and to alter it and redistribute it
18 // freely, subject to the following restrictions:
19 //
20 // 1. The origin of this software must not be misrepresented; you must not
21 // claim that you wrote the original software. If you use this software
22 // in a product, an acknowledgment in the product documentation would be
23 // appreciated but is not required.
24 //
25 // 2. Altered source versions must be plainly marked as such, and must not
26 // be misrepresented as being the original software.
27 //
28 // 3. This notice may not be removed or altered from any source distribution.
29 //
30 // Author: Walker White
31 // Version: 6/20/16
32 
33 #ifndef __CU_FRUSTRUM_H__
34 #define __CU_FRUSTRUM_H__
35 
36 #include <cugl/math/CUPlane.h>
37 #include <cugl/math/CUVec3.h>
38 #include <cugl/util/CUDebug.h>
39 
40 namespace cugl {
41 
42 
51 class Frustum {
52 #pragma mark Values
53 public:
55  static const int PLANE_COUNT = 6;
57  static const int CORNER_COUNT = 8;
58 
60  enum class Region {
62  INSIDE,
64  OUTSIDE,
66  INTERSECT
67  };
68 
69 
70 private:
72  Plane _planes[6];
73 
79  Vec3 _points[8];
80 
81 
82 public:
84  enum class Side : unsigned int {
86  CLOSE = 0,
88  AWAY = 1,
90  LEFT = 2,
92  RIGHT = 3,
94  TOP = 4,
96  BOTTOM = 5
97  };
98 
99 #pragma mark Constructors
100 
103  Frustum () {
105  }
106 
112  Frustum (const Mat4& inverseView) {
113  set(inverseView);
114  }
115 
121  Frustum (const Frustum& frustum) {
122  set(frustum);
123  }
124 
128  ~Frustum() {}
129 
130 #pragma mark -
131 #pragma mark Setters
132 
139  Frustum& operator=(const Mat4& inverseView) {
140  return set(inverseView);
141  }
142 
150  Frustum& operator=(const Frustum& frustum) {
151  return set(frustum);
152  }
153 
161  Frustum& set(const Mat4& inverseView);
162 
170  Frustum& set(const Frustum& frustum);
171 
172 
173 #pragma mark -
174 #pragma mark Attributes
175 
185  const Plane& getPlane(Side side) {
186  CUAssertLog((unsigned int)side < PLANE_COUNT, "Side is not valid");
187  return _planes[(unsigned int)side];
188  }
189 
197  const Vec3& getCorner(unsigned int index) {
198  CUAssertLog(index < CORNER_COUNT, "Index is not valid");
199  return _points[index];
200  }
201 
202 #pragma mark -
203 #pragma mark Containment Methods
204 
211  Region find(const Vec3 point);
212 
222  Region find(float x, float y, float z) {
223  return find(Vec3(x,y,z));
224  }
225 
234  Region findSphere(const Vec3& center, float radius);
235 
246  Region findSphere(float x, float y, float z, float radius) {
247  return findSphere(Vec3(x,y,z),radius);
248  }
249 
261  Region findSphereWithoutNearFar(const Vec3& center, float radius);
262 
276  Region findSphereWithoutNearFar(float x, float y, float z, float radius) {
277  return findSphereWithoutNearFar(Vec3(x,y,z),radius);
278  }
279 
291  Region findBox(const Vec3& center, const Vec3& dimension) {
292  return findBox(center.x, center.y, center.z, dimension.x / 2, dimension.y / 2, dimension.z / 2);
293  }
294 
310  Region findBox(float x, float y, float z, float halfWidth, float halfHeight, float halfDepth);
311 
312 };
313 
314 }
315 #endif /* __CU_FRUSTRUM_H__ */
cugl::Frustum::findSphereWithoutNearFar
Region findSphereWithoutNearFar(const Vec3 &center, float radius)
cugl::Frustum::operator=
Frustum & operator=(const Frustum &frustum)
Definition: CUFrustum.h:150
cugl::Frustum::find
Region find(const Vec3 point)
cugl::Frustum::Side::TOP
cugl::Vec3::x
float x
Definition: CUVec3.h:66
cugl::Plane
Definition: CUPlane.h:47
cugl::Vec3::z
float z
Definition: CUVec3.h:70
cugl::Frustum::Region::INSIDE
cugl::Frustum::findSphere
Region findSphere(float x, float y, float z, float radius)
Definition: CUFrustum.h:246
cugl::Frustum::Side
Side
Definition: CUFrustum.h:84
cugl::Frustum::set
Frustum & set(const Mat4 &inverseView)
cugl::Frustum
Definition: CUFrustum.h:51
cugl::Mat4::IDENTITY
static const Mat4 IDENTITY
Definition: CUMat4.h:106
cugl::Frustum::operator=
Frustum & operator=(const Mat4 &inverseView)
Definition: CUFrustum.h:139
cugl::Frustum::Frustum
Frustum()
Definition: CUFrustum.h:103
cugl::Frustum::Side::BOTTOM
cugl::Frustum::getPlane
const Plane & getPlane(Side side)
Definition: CUFrustum.h:185
cugl::Frustum::findSphere
Region findSphere(const Vec3 &center, float radius)
cugl::Frustum::Region::INTERSECT
cugl::Frustum::PLANE_COUNT
static const int PLANE_COUNT
Definition: CUFrustum.h:55
cugl::Frustum::findBox
Region findBox(const Vec3 &center, const Vec3 &dimension)
Definition: CUFrustum.h:291
cugl::Mat4
Definition: CUMat4.h:83
cugl::Frustum::Region::OUTSIDE
cugl::Frustum::Frustum
Frustum(const Frustum &frustum)
Definition: CUFrustum.h:121
cugl::Frustum::find
Region find(float x, float y, float z)
Definition: CUFrustum.h:222
cugl::Frustum::Side::AWAY
cugl::Frustum::~Frustum
~Frustum()
Definition: CUFrustum.h:128
cugl::Frustum::Frustum
Frustum(const Mat4 &inverseView)
Definition: CUFrustum.h:112
cugl::Frustum::Side::RIGHT
cugl::Vec3::y
float y
Definition: CUVec3.h:68
cugl::Frustum::CORNER_COUNT
static const int CORNER_COUNT
Definition: CUFrustum.h:57
cugl::Frustum::getCorner
const Vec3 & getCorner(unsigned int index)
Definition: CUFrustum.h:197
cugl::Frustum::Side::CLOSE
cugl::Frustum::Region
Region
Definition: CUFrustum.h:60
cugl::Vec3
Definition: CUVec3.h:61
cugl::Frustum::findSphereWithoutNearFar
Region findSphereWithoutNearFar(float x, float y, float z, float radius)
Definition: CUFrustum.h:276
cugl::Frustum::Side::LEFT