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
182 auto test_swept_sphere(const bsphere& sphere, const vec3& sweepDirection) const -> bool;
183
190 auto test_frustum(const frustum& frustum) const -> bool;
191
199 auto test_line(const vec3& v1, const vec3& v2) const -> bool;
200
207 auto mul(const transform& t) -> frustum&;
208
209 //-------------------------------------------------------------------------
210 // Public Operators
211 //-------------------------------------------------------------------------
212
219 auto operator==(const frustum& f) const -> bool;
220
221 //-------------------------------------------------------------------------
222 // Public Variables
223 //-------------------------------------------------------------------------
224
226 std::array<plane, 6> planes;
228 std::array<vec3, 8> points;
230 vec3 position = {0.0f, 0.0f, 0.0f};
231
234
235private:
236 //-------------------------------------------------------------------------
237 // Private Static Functions
238 //-------------------------------------------------------------------------
239
251 static auto swept_sphere_intersect_plane(float& t0,
252 float& t1,
253 const plane& plane,
254 const bsphere& sphere,
255 const vec3& sweepDirection) -> bool;
256};
257} // 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 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
vec3 position
Definition frustum.h:230
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:521
float far_distance_
Definition frustum.h:233
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:687
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
auto test_swept_sphere(const bsphere &sphere, const vec3 &sweepDirection) const -> bool
Determine whether or not the specified sphere, swept along the provided direction vector,...
Definition frustum.cpp:475
std::array< plane, 6 > planes
< The 6 planes of the frustum.
Definition frustum.h:226
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:581
auto test_line(const vec3 &v1, const vec3 &v2) const -> bool
Tests if a line intersects the frustum.
Definition frustum.cpp:526
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:617
auto operator==(const frustum &f) const -> bool
Equality operator.
Definition frustum.cpp:710
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:228
float near_distance_
Definition frustum.h:232
General purpose transformation class designed to maintain each component of the transformation separa...
Definition transform.hpp:27
Definition bbox.cpp:5
volume_query
Definition math_types.h:13
Storage for box vector values and wraps up common functionality.
Definition bbox.h:21
Storage for infinite plane.
Definition plane.h:21