mirror of
https://github.com/recp/cglm.git
synced 2025-12-25 12:55:04 +00:00
Merge pull request #40 from recp/aabb-ext
Axis-Aligned Bounding Box (AABB) Extensions
This commit is contained in:
@@ -153,4 +153,50 @@ glm_aabb_frustum(vec3 box[2], vec4 planes[6]) {
|
||||
return true;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief invalidate AABB min and max values
|
||||
*
|
||||
* @param[in, out] box bounding box
|
||||
*/
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_aabb_invalidate(vec3 box[2]) {
|
||||
glm_vec_broadcast(FLT_MAX, box[0]);
|
||||
glm_vec_broadcast(-FLT_MAX, box[1]);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief check if AABB is valid or not
|
||||
*
|
||||
* @param[in] box bounding box
|
||||
*/
|
||||
CGLM_INLINE
|
||||
bool
|
||||
glm_aabb_isvalid(vec3 box[2]) {
|
||||
return glm_vec_max(box[0]) != FLT_MAX
|
||||
&& glm_vec_min(box[1]) != -FLT_MAX;
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief distance between of min and max
|
||||
*
|
||||
* @param[in] box bounding box
|
||||
*/
|
||||
CGLM_INLINE
|
||||
float
|
||||
glm_aabb_size(vec3 box[2]) {
|
||||
return glm_vec_distance(box[0], box[1]);
|
||||
}
|
||||
|
||||
/*!
|
||||
* @brief radius of sphere which surrounds AABB
|
||||
*
|
||||
* @param[in] box bounding box
|
||||
*/
|
||||
CGLM_INLINE
|
||||
float
|
||||
glm_aabb_radius(vec3 box[2]) {
|
||||
return glm_aabb_size(box) * 0.5f;
|
||||
}
|
||||
|
||||
#endif /* cglm_box_h */
|
||||
|
||||
@@ -171,4 +171,33 @@ glm_versor_print(versor vec,
|
||||
#undef m
|
||||
}
|
||||
|
||||
CGLM_INLINE
|
||||
void
|
||||
glm_aabb_print(vec3 bbox[2],
|
||||
const char * __restrict tag,
|
||||
FILE * __restrict ostream) {
|
||||
int i, j;
|
||||
|
||||
#define m 3
|
||||
|
||||
fprintf(ostream, "AABB (%s):\n", tag ? tag: "float");
|
||||
|
||||
for (i = 0; i < 2; i++) {
|
||||
fprintf(ostream, "\t|");
|
||||
|
||||
for (j = 0; j < m; j++) {
|
||||
fprintf(ostream, "%0.4f", bbox[i][j]);
|
||||
|
||||
if (j != m - 1)
|
||||
fprintf(ostream, "\t");
|
||||
}
|
||||
|
||||
fprintf(ostream, "|\n");
|
||||
}
|
||||
|
||||
fprintf(ostream, "\n");
|
||||
|
||||
#undef m
|
||||
}
|
||||
|
||||
#endif /* cglm_io_h */
|
||||
|
||||
Reference in New Issue
Block a user