18 #include <glm/glm.hpp>
23 #include "GeometryUtil.h"
24 #include "StreamUtils.h"
33 AABox(
const AACube& other);
34 AABox(
const Extents& other);
35 AABox(
const glm::vec3& corner,
float size);
36 AABox(
const glm::vec3& corner,
const glm::vec3& dimensions);
40 void setBox(
const glm::vec3& corner,
const glm::vec3& scale);
42 void setBox(
const glm::vec3& corner,
float scale);
43 glm::vec3 getFarthestVertex(
const glm::vec3& normal)
const;
44 glm::vec3 getNearestVertex(
const glm::vec3& normal)
const;
46 const glm::vec3& getCorner()
const {
return _corner; }
47 const glm::vec3& getScale()
const {
return _scale; }
48 const glm::vec3& getDimensions()
const {
return _scale; }
49 float getLargestDimension()
const {
return glm::max(_scale.x, glm::max(_scale.y, _scale.z)); }
51 glm::vec3 calcCenter()
const;
52 glm::vec3 calcTopFarLeft()
const {
return _corner + _scale; }
54 const glm::vec3& getMinimum()
const {
return _corner; }
55 glm::vec3 getMaximum()
const {
return _corner + _scale; }
57 glm::vec3 getVertex(BoxVertex vertex)
const;
59 const glm::vec3& getMinimumPoint()
const {
return _corner; }
60 glm::vec3 getMaximumPoint()
const {
return calcTopFarLeft(); }
62 bool contains(
const Triangle& triangle)
const;
63 bool contains(
const glm::vec3& point)
const;
64 bool contains(
const AABox& otherBox)
const;
65 bool touches(
const AABox& otherBox)
const;
67 bool contains(
const AACube& otherCube)
const;
68 bool touches(
const AACube& otherCube)
const;
70 bool expandedContains(
const glm::vec3& point,
float expansion)
const;
71 bool expandedIntersectsSegment(
const glm::vec3& start,
const glm::vec3& end,
float expansion)
const;
72 bool findRayIntersection(
const glm::vec3& origin,
const glm::vec3& direction,
const glm::vec3& invDirection,
float& distance,
73 BoxFace& face, glm::vec3& surfaceNormal)
const;
74 bool findParabolaIntersection(
const glm::vec3& origin,
const glm::vec3& velocity,
const glm::vec3& acceleration,
75 float& parabolicDistance, BoxFace& face, glm::vec3& surfaceNormal)
const;
76 bool rayHitsBoundingSphere(
const glm::vec3& origin,
const glm::vec3& direction)
const;
77 bool parabolaPlaneIntersectsBoundingSphere(
const glm::vec3& origin,
const glm::vec3& velocity,
const glm::vec3& acceleration,
const glm::vec3& normal)
const;
78 bool touchesSphere(
const glm::vec3& center,
float radius)
const;
79 bool touchesAAEllipsoid(
const glm::vec3& center,
const glm::vec3& radials)
const;
80 bool findSpherePenetration(
const glm::vec3& center,
float radius, glm::vec3& penetration)
const;
81 bool findCapsulePenetration(
const glm::vec3& start,
const glm::vec3& end,
float radius, glm::vec3& penetration)
const;
83 bool isNull()
const {
return _scale == glm::vec3(0.0f, 0.0f, 0.0f); }
85 AABox clamp(
const glm::vec3& min,
const glm::vec3& max)
const;
86 AABox clamp(
float min,
float max)
const;
88 inline AABox& operator+=(
const glm::vec3& point) {
89 bool valid = !isInvalid();
90 glm::vec3 maximum = glm::max(_corner + _scale, point);
91 _corner = glm::min(_corner, point);
93 _scale = maximum - _corner;
98 inline AABox& operator+=(
const AABox& box) {
99 if (!box.isInvalid()) {
100 (*this) += box._corner;
101 (*this) += box.calcTopFarLeft();
107 void translate(
const glm::vec3& translation) { _corner += translation; }
111 void rotate(
const glm::quat& rotation);
114 void scale(
float scale);
115 void scale(
const glm::vec3& scale);
118 void embiggen(
float scale);
119 void embiggen(
const glm::vec3& scale);
122 void setScaleStayCentered(
const glm::vec3& scale);
125 void transform(
const Transform& transform);
128 void transform(
const glm::mat4& matrix);
130 static const glm::vec3 INFINITY_VECTOR;
132 bool isInvalid()
const {
return _corner.x == std::numeric_limits<float>::infinity(); }
134 void clear() { _corner = INFINITY_VECTOR; _scale = glm::vec3(0.0f); }
147 AABox getOctreeChild(OctreeChild child)
const;
149 glm::vec4 getPlane(BoxFace face)
const;
152 glm::vec3 getClosestPointOnFace(
const glm::vec3& point, BoxFace face)
const;
153 glm::vec3 getClosestPointOnFace(
const glm::vec4& origin,
const glm::vec4& direction, BoxFace face)
const;
155 static BoxFace getOppositeFace(BoxFace face);
157 void checkPossibleParabolicIntersection(
float t,
int i,
float& minDistance,
158 const glm::vec3& origin,
const glm::vec3& velocity,
const glm::vec3& acceleration,
bool& hit)
const;
164 inline bool operator==(
const AABox& a,
const AABox& b) {
165 return a.getCorner() == b.getCorner() && a.getDimensions() == b.getDimensions();
168 inline QDebug operator<<(QDebug debug,
const AABox& box) {
170 << box.getCorner().x <<
"," << box.getCorner().y <<
"," << box.getCorner().z <<
" ) to ("
171 << box.calcTopFarLeft().x <<
"," << box.calcTopFarLeft().y <<
"," << box.calcTopFarLeft().z <<
") size: ("
172 << box.getDimensions().x <<
"," << box.getDimensions().y <<
"," << box.getDimensions().z <<
")"