CUGL
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 zlib 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 "CUPlane.h"
37 #include "CUVec3.h"
38 #include "../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__ */
Frustum & set(const Mat4 &inverseView)
float x
Definition: CUVec3.h:66
Frustum(const Frustum &frustum)
Definition: CUFrustum.h:121
Side
Definition: CUFrustum.h:84
~Frustum()
Definition: CUFrustum.h:128
Region findSphere(const Vec3 &center, float radius)
Frustum & operator=(const Mat4 &inverseView)
Definition: CUFrustum.h:139
float z
Definition: CUVec3.h:70
Definition: CUFrustum.h:51
Region findSphereWithoutNearFar(float x, float y, float z, float radius)
Definition: CUFrustum.h:276
const Plane & getPlane(Side side)
Definition: CUFrustum.h:185
static const int CORNER_COUNT
Definition: CUFrustum.h:57
Region findBox(const Vec3 &center, const Vec3 &dimension)
Definition: CUFrustum.h:291
Region findSphereWithoutNearFar(const Vec3 &center, float radius)
static const int PLANE_COUNT
Definition: CUFrustum.h:55
Definition: CUPlane.h:47
Frustum()
Definition: CUFrustum.h:103
Region findSphere(float x, float y, float z, float radius)
Definition: CUFrustum.h:246
Region
Definition: CUFrustum.h:60
static const Mat4 IDENTITY
Definition: CUMat4.h:114
Region find(float x, float y, float z)
Definition: CUFrustum.h:222
Frustum & operator=(const Frustum &frustum)
Definition: CUFrustum.h:150
Region find(const Vec3 point)
Definition: CUVec3.h:61
Frustum(const Mat4 &inverseView)
Definition: CUFrustum.h:112
const Vec3 & getCorner(unsigned int index)
Definition: CUFrustum.h:197
float y
Definition: CUVec3.h:68
Definition: CUAnimationNode.h:52
Definition: CUMat4.h:92