Unravel Engine C++ Reference
Loading...
Searching...
No Matches
bbox.h
Go to the documentation of this file.
1#pragma once
2
3//-----------------------------------------------------------------------------
4// bbox Header Includes
5//-----------------------------------------------------------------------------
6#include "bsphere.h"
7#include "math_types.h"
8#include "plane.h"
9#include "transform.hpp"
10#include <array>
11
12namespace math
13{
14using namespace glm;
15
20struct bbox
21{
25 bbox();
26
32 bbox(const vec3& minimum, const vec3& maximum);
33
43 bbox(float xMin, float yMin, float zMin, float xMax, float yMax, float zMax);
44
51
57 void get_plane_points(volume_plane::e side, vec3 points_out[]) const;
58
67 bbox& from_points(const char* point_buffer, unsigned int point_count, unsigned int point_stride, bool reset = true);
68
75 bbox& from_sphere(const vec3& center, float radius);
76
82 bool intersect(const bbox& bounds) const;
83
90 bool intersect(const bbox& bounds, bool& contained) const;
91
98 bool intersect(const bbox& bounds, bbox& intersection) const;
99
106 bool intersect(const bbox& bounds, const vec3& tolerance) const;
107
116 bool intersect(const vec3& origin, const vec3& velocity, float& t, bool restrict_range = true) const;
117
126 bool intersect(const vec3& v0, const vec3& v1, const vec3& v2, const bbox& triangle_bounds) const;
127
135 bool intersect(const vec3& v0, const vec3& v1, const vec3& v2) const;
136
142 bool contains_point(const vec3& point) const;
143
151 bool contains_point(const vec3& point, const vec3& tolerance) const;
152
160 bool contains_point(const vec3& point, float tolerance) const;
161
167 vec3 closest_point(const vec3& source_point) const;
168
172 void validate();
173
177 void reset();
178
184 bbox& mul(const transform& t);
185 bbox& mul_no_scale(const transform& t);
186
194 static bbox mul(const bbox& bounds, const transform& t);
195 static bbox mul_no_scale(const bbox& bounds, const transform& t);
196
202 bbox& add_point(const vec3& point);
203
208 vec3 get_dimensions() const;
209
214 vec3 get_center() const;
215
220 vec3 get_extents() const;
221
226 void inflate(float amount);
227
233 void inflate(const vec3& amount);
234
239 bool is_populated() const;
240
245 bool is_degenerate() const;
246
252 std::array<vec3, 8> get_corners() const;
253
259 bbox operator*(float scale) const;
260
266 bbox& operator+=(const vec3& shift);
267
273 bbox& operator-=(const vec3& shift);
274
280 bbox& operator*=(const transform& t);
281
287 bbox& operator*=(float scale);
288
294 bool operator==(const bbox& bounds) const;
295
301 bool operator!=(const bbox& bounds) const;
302
306 vec3 min;
307
311 vec3 max;
312
316 static bbox empty;
317};
318} // namespace math
General purpose transformation class designed to maintain each component of the transformation separa...
Definition transform.hpp:27
float scale
Definition hub.cpp:25
Definition bbox.cpp:5
Storage for box vector values and wraps up common functionality.
Definition bbox.h:21
bbox & add_point(const vec3 &point)
Grows the bounding box based on the point passed.
Definition bbox.cpp:924
vec3 max
The maximum vector value of the bounding box.
Definition bbox.h:311
bbox operator*(float scale) const
Scales the bounding box values by the scalar passed.
Definition bbox.cpp:1004
void reset()
Resets the bounding box values.
Definition bbox.cpp:28
bbox & operator+=(const vec3 &shift)
Moves the bounding box by the vector passed.
Definition bbox.cpp:990
bbox & from_points(const char *point_buffer, unsigned int point_count, unsigned int point_stride, bool reset=true)
Calculates the bounding box based on the points specified.
Definition bbox.cpp:190
bbox & operator-=(const vec3 &shift)
Moves the bounding box by the vector passed.
Definition bbox.cpp:997
bbox & mul(const transform &t)
Transforms an axis aligned bounding box by the specified matrix.
Definition bbox.cpp:876
void get_plane_points(volume_plane::e side, vec3 points_out[]) const
Retrieves the four points that form the boundary of the specified side of the bounding box.
Definition bbox.cpp:97
void inflate(float amount)
Grows the bounding box by the specified number of world space units on all three axes.
Definition bbox.cpp:956
bool operator==(const bbox &bounds) const
Checks for equality between this bounding box and another.
Definition bbox.cpp:1022
bbox & from_sphere(const vec3 &center, float radius)
Calculates the bounding box based on the sphere specified.
Definition bbox.cpp:213
bbox & operator*=(const transform &t)
Transforms the bounding box by the matrix passed.
Definition bbox.cpp:1016
vec3 min
The minimum vector value of the bounding box.
Definition bbox.h:306
std::array< vec3, 8 > get_corners() const
Definition bbox.cpp:976
bool is_degenerate() const
Checks if the bounding box is degenerate (empty)
Definition bbox.cpp:52
bbox & mul_no_scale(const transform &t)
Definition bbox.cpp:900
bool contains_point(const vec3 &point) const
Tests to see if a point falls within this bounding box or not.
Definition bbox.cpp:792
static bbox empty
An empty bounding box.
Definition bbox.h:316
plane get_plane(volume_plane::e side) const
Retrieves the plane for the specified side of the bounding box.
Definition bbox.cpp:59
void validate()
Ensures that the values placed in the min/max values never make the bounding box itself inverted.
Definition bbox.cpp:221
bool is_populated() const
Checks if the bounding box is populated.
Definition bbox.cpp:36
bool operator!=(const bbox &bounds) const
Checks for inequality between this bounding box and another.
Definition bbox.cpp:1027
vec3 get_dimensions() const
Returns a vector containing the dimensions of the bounding box.
Definition bbox.cpp:941
vec3 get_extents() const
Returns a vector containing the extents of the bounding box (the half-dimensions)
Definition bbox.cpp:951
vec3 closest_point(const vec3 &source_point) const
Computes the closest point on the surface of the AABB to the input point.
Definition bbox.cpp:826
vec3 get_center() const
Returns a vector containing the exact center point of the box.
Definition bbox.cpp:946
bbox()
Default Constructor.
Definition bbox.cpp:8
Storage for infinite plane.
Definition plane.h:21