Unravel Engine C++ Reference
Loading...
Searching...
No Matches
frustum.h
Go to the documentation of this file.
1#pragma once
2
3#include "bbox.h"
4#include "bsphere.h"
5#include "math_types.h"
6#include "plane.h"
7#include "transform.hpp"
8#include <array>
9
10namespace math
11{
12using namespace glm;
13
18{
19public:
20 //-------------------------------------------------------------------------
21 // Constructors & Destructors
22 //-------------------------------------------------------------------------
23
27 frustum();
28
37 frustum(const transform& view, const transform& proj, bool homogeneousDepth);
38
44 frustum(const bbox& sourceBounds);
45
46 //-------------------------------------------------------------------------
47 // Public Methods
48 //-------------------------------------------------------------------------
49
57 void update(const transform& view, const transform& proj, bool _oglNDC);
58
64 void set_planes(const std::array<plane, 6>& new_planes);
65
69 void recompute_points();
70
78 auto classify_vertices(const vec3* vertices, size_t count) const -> volume_query;
79
86 auto classify_aabb(const bbox& bounds) const -> volume_query;
87
96 auto classify_aabb(const bbox& bounds, unsigned int& frustumBits, int& lastOutside) const -> volume_query;
97
105 auto classify_obb(const bbox& bounds, const transform& t) const -> volume_query;
106
113 auto classify_sphere(const bsphere& sphere) const -> volume_query;
114
121 auto classify_plane(const plane& plane) const -> volume_query;
122
130 auto test_vertices(const vec3* vertices, size_t count) const -> bool;
131
138 auto test_point(const vec3& point) const -> bool;
139
146 auto test_aabb(const bbox& bounds) const -> bool;
147
155 auto test_obb(const bbox& bounds, const transform& t) const -> bool;
156
163 auto test_sphere(const bsphere& sphere) const -> bool;
164
172 auto test_sphere(const bsphere& sphere, const transform& t) const -> bool;
173
183 auto test_swept_sphere(const bsphere& sphere, const vec3& sweepDirection, float max_distance = -1.0f) const -> bool;
184
194 auto test_swept_aabb(const bbox& box, const vec3& sweepDirection, float max_distance = -1.0f) const -> bool;
195
202 auto test_frustum(const frustum& frustum) const -> bool;
203
211 auto test_line(const vec3& v1, const vec3& v2) const -> bool;
212
219 auto mul(const transform& t) -> frustum&;
220
221 //-------------------------------------------------------------------------
222 // Public Operators
223 //-------------------------------------------------------------------------
224
231 auto operator==(const frustum& f) const -> bool;
232
233 //-------------------------------------------------------------------------
234 // Public Variables
235 //-------------------------------------------------------------------------
236
238 std::array<plane, 6> planes;
240 std::array<vec3, 8> points;
242 vec3 position = {0.0f, 0.0f, 0.0f};
243
246
247private:
248 //-------------------------------------------------------------------------
249 // Private Static Functions
250 //-------------------------------------------------------------------------
251
263 static auto swept_sphere_intersect_plane(float& t0,
264 float& t1,
265 const plane& plane,
266 const bsphere& sphere,
267 const vec3& sweepDirection) -> bool;
268};
269} // namespace math
Provides storage for common representation of spherical bounding volume, and wraps up common function...
Definition bsphere.h:18
Storage for frustum planes / values and wraps up common functionality.
Definition frustum.h:18
auto test_swept_sphere(const bsphere &sphere, const vec3 &sweepDirection, float max_distance=-1.0f) const -> bool
Determine whether or not the specified sphere, swept along the provided direction vector,...
Definition frustum.cpp:475
auto classify_aabb(const bbox &bounds) const -> volume_query
Classifies an axis-aligned bounding box (AABB) with respect to the frustum.
Definition frustum.cpp:227
auto classify_sphere(const bsphere &sphere) const -> volume_query
Classifies a sphere with respect to the frustum.
Definition frustum.cpp:390
auto test_swept_aabb(const bbox &box, const vec3 &sweepDirection, float max_distance=-1.0f) const -> bool
Determine whether or not the specified axis-aligned bounding box, swept along the provided direction ...
Definition frustum.cpp:535
vec3 position
Definition frustum.h:242
void recompute_points()
Recomputes the frustum's corner points based on its planes.
Definition frustum.cpp:153
frustum()
Default constructor.
Definition frustum.cpp:29
auto test_aabb(const bbox &bounds) const -> bool
Tests if an axis-aligned bounding box (AABB) is inside or intersecting the frustum.
Definition frustum.cpp:334
auto test_point(const vec3 &point) const -> bool
Tests if a point is inside or intersecting the frustum.
Definition frustum.cpp:602
float far_distance_
Definition frustum.h:245
auto test_sphere(const bsphere &sphere) const -> bool
Tests if a sphere is inside or intersecting the frustum.
Definition frustum.cpp:417
auto mul(const transform &t) -> frustum &
Multiplies the frustum by a transform.
Definition frustum.cpp:768
void update(const transform &view, const transform &proj, bool _oglNDC)
Updates the frustum based on the specified view and projection matrices.
Definition frustum.cpp:66
std::array< plane, 6 > planes
< The 6 planes of the frustum.
Definition frustum.h:238
auto test_vertices(const vec3 *vertices, size_t count) const -> bool
Tests if vertices are inside or intersect the frustum.
Definition frustum.cpp:357
void set_planes(const std::array< plane, 6 > &new_planes)
Sets the frustum planes.
Definition frustum.cpp:140
auto classify_plane(const plane &plane) const -> volume_query
Classifies a plane with respect to the frustum.
Definition frustum.cpp:662
auto test_line(const vec3 &v1, const vec3 &v2) const -> bool
Tests if a line intersects the frustum.
Definition frustum.cpp:607
auto classify_vertices(const vec3 *vertices, size_t count) const -> volume_query
Classifies vertices with respect to the frustum.
Definition frustum.cpp:184
auto classify_obb(const bbox &bounds, const transform &t) const -> volume_query
Classifies an oriented bounding box (OBB) with respect to the frustum.
Definition frustum.cpp:257
auto test_frustum(const frustum &frustum) const -> bool
Tests if another frustum intersects this frustum.
Definition frustum.cpp:698
auto operator==(const frustum &f) const -> bool
Equality operator.
Definition frustum.cpp:791
auto test_obb(const bbox &bounds, const transform &t) const -> bool
Tests if an oriented bounding box (OBB) is inside or intersecting the frustum.
Definition frustum.cpp:384
std::array< vec3, 8 > points
The originating position of the frustum.
Definition frustum.h:240
float near_distance_
Definition frustum.h:244
General purpose transformation class designed to maintain each component of the transformation separa...
Definition transform.hpp:27
uint16_t view
Definition bbox.cpp:5
volume_query
Definition math_types.h:13
uint32_t count
Storage for box vector values and wraps up common functionality.
Definition bbox.h:21
Storage for infinite plane.
Definition plane.h:21