25 #include "glm/gtc/matrix_transform.hpp" 77 min = glm::translate(min, glm::vec3(
_min[0],
_min[1],
_min[2]));
80 max = glm::translate(max, glm::vec3(
_max[0],
_max[1],
_max[2]));
82 x =
MIN(min[3][0], max[3][0]);
83 y =
MIN(min[3][1], max[3][1]);
84 z =
MIN(min[3][2], max[3][2]);
96 min = glm::translate(min, glm::vec3(
_min[0],
_min[1],
_min[2]));
99 max = glm::translate(max, glm::vec3(
_max[0],
_max[1],
_max[2]));
101 x =
MAX(min[3][0], max[3][0]);
102 y =
MAX(min[3][1], max[3][1]);
103 z =
MAX(min[3][2], max[3][2]);
122 float minX, minY, minZ;
125 float maxX, maxY, maxZ;
128 if ((x < minX) || (x > maxX))
130 if ((y < minY) || (y > maxY))
140 float minX, minY, minZ;
143 float maxX, maxY, maxZ;
146 if ((x < minX) || (x > maxX))
148 if ((y < minY) || (y > maxY))
150 if ((z < minZ) || (z > maxZ))
157 float x1,
float y1,
float z1,
158 float x2,
float y2,
float z2,
159 float &x,
float &y,
float &z)
const {
161 if ((fDst1 * fDst2) >= 0.0f)
166 x = x1 + ((x2 - x1) * (-fDst1 / (fDst2 - fDst1)));
167 y = y1 + ((y2 - y1) * (-fDst1 / (fDst2 - fDst1)));
168 z = z1 + ((z2 - z1) * (-fDst1 / (fDst2 - fDst1)));
174 float maxX,
float maxY,
float maxZ,
int axis)
const {
176 if (((axis == 1) && (z > minZ) && (z < maxZ) && (y > minY) && (y < maxY)) ||
177 ((axis == 2) && (z > minZ) && (z < maxZ) && (x > minX) && (x < maxX)) ||
178 ((axis == 3) && (x > minX) && (x < maxX) && (y > minY) && (y < maxY)))
188 float minX, minY, minZ;
191 float maxX, maxY, maxZ;
194 if ((x2 < minX) && (x1 < minX))
return false;
195 if ((x2 > maxX) && (x1 > maxX))
return false;
196 if ((y2 < minY) && (y1 < minY))
return false;
197 if ((y2 > maxY) && (y1 > maxY))
return false;
198 if ((z2 < minZ) && (z1 < minZ))
return false;
199 if ((z2 > maxZ) && (z1 > maxZ))
return false;
201 if ((x1 > minX) && (x1 < maxX) &&
202 (y1 > minY) && (y1 < maxY) &&
203 (z1 > minZ) && (z1 < maxZ))
208 if (
getIntersection(x1 - minX, x2 - minX, x1, y1, z1, x2, y2, z2, x, y, z) &&
209 inBox(x, y, z, minX, minY, minZ, maxX, maxY, maxZ, 1))
211 if (
getIntersection(y1 - minY, y2 - minY, x1, y1, z1, x2, y2, z2, x, y, z) &&
212 inBox(x, y, z, minX, minY, minZ, maxX, maxY, maxZ, 2))
214 if (
getIntersection(z1 - minZ, z2 - minZ, x1, y1, z1, x2, y2, z2, x, y, z) &&
215 inBox(x, y, z, minX, minY, minZ, maxX, maxY, maxZ, 3))
217 if (
getIntersection(x1 - maxX, x2 - maxX, x1, y1, z1, x2, y2, z2, x, y, z) &&
218 inBox(x, y, z, minX, minY, minZ, maxX, maxY, maxZ, 1))
220 if (
getIntersection(y1 - maxY, y2 - maxY, x1, y1, z1, x2, y2, z2, x, y, z) &&
221 inBox(x, y, z, minX, minY, minZ, maxX, maxY, maxZ, 2))
223 if (
getIntersection(z1 - maxZ, z2 - maxZ, x1, y1, z1, x2, y2, z2, x, y, z) &&
224 inBox(x, y, z, minX, minY, minZ, maxX, maxY, maxZ, 3))
240 for (
int i = 0; i < 3; i++) {
256 for (
int i = 0; i < 8; i++)
271 if (x == 0 && y == 0 && z == 0)
311 for (
int i = 0; i < 8; i++) {
315 coords[i][0] = c[3][0];
316 coords[i][1] = c[3][1];
317 coords[i][2] = c[3][2];
322 for (
int i = 0; i < 8; i++)
323 add(coords[i][0], coords[i][1], coords[i][2]);
bool isIn(float x, float y) const
float getDepth() const
Get the depth of the bounding box.
void scale(float x, float y, float z)
A bounding box around 3D points.
const glm::mat4 & getOrigin() const
float getHeight() const
Get the height of the bounding box.
void getMin(float &x, float &y, float &z) const
float getCoordMin(int i) const
Utility templates and functions.
void getMax(float &x, float &y, float &z) const
float getWidth() const
Get the width of the bounding box.
void transform(const glm::mat4 &m)
float getCoordMax(int i) const
void absolutize()
Apply the origin transformations directly to the coordinates.
void rotate(float angle, float x, float y, float z)
bool inBox(float x, float y, float z, float minX, float minY, float minZ, float maxX, float maxY, float maxZ, int axis) const
void add(float x, float y, float z)
BoundingBox getAbsolute() const
Return a copy with the origin transformations directly applied to the coordinates.
bool getIntersection(float fDst1, float fDst2, float x1, float y1, float z1, float x2, float y2, float z2, float &x, float &y, float &z) const
static float deg2rad(float deg)
void translate(float x, float y, float z)