From 984916d52065c3f4f3e262ed3ed3966892ff182c Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 2 Apr 2018 11:50:53 +0300 Subject: [PATCH 1/5] invalidate axis-aligned boundng box util --- include/cglm/box.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/cglm/box.h b/include/cglm/box.h index d7184c5..c8115a6 100644 --- a/include/cglm/box.h +++ b/include/cglm/box.h @@ -153,4 +153,16 @@ 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]); +} + #endif /* cglm_box_h */ From b0991342a65ce15f7e67e667ec2214837b64509a Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 2 Apr 2018 12:08:08 +0300 Subject: [PATCH 2/5] aabb printer function --- include/cglm/io.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/include/cglm/io.h b/include/cglm/io.h index 2ee8ee8..f38fad7 100644 --- a/include/cglm/io.h +++ b/include/cglm/io.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 */ From 86efe64b8ee3093f111b706ca17fba3a09e8a419 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 2 Apr 2018 12:35:22 +0300 Subject: [PATCH 3/5] helper for check aabb is valid or not --- include/cglm/box.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/include/cglm/box.h b/include/cglm/box.h index c8115a6..89ef5a9 100644 --- a/include/cglm/box.h +++ b/include/cglm/box.h @@ -165,4 +165,16 @@ glm_aabb_invalidate(vec3 box[2]) { 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; +} + #endif /* cglm_box_h */ From dbd1e334ea3bfa9c15afe002990605b3656dffe0 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 2 Apr 2018 16:26:14 +0300 Subject: [PATCH 4/5] aabb box size and radius --- include/cglm/box.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/cglm/box.h b/include/cglm/box.h index 89ef5a9..7032339 100644 --- a/include/cglm/box.h +++ b/include/cglm/box.h @@ -177,4 +177,26 @@ glm_aabb_isvalid(vec3 box[2]) { && 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 */ From 74f9865884ef17fc2dd72482a42aa2204ab9d4e3 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Mon, 2 Apr 2018 16:36:55 +0300 Subject: [PATCH 5/5] add docs for new aabb functions --- docs/source/box.rst | 40 ++++++++++++++++++++++++++++++++++++++++ docs/source/io.rst | 10 ++++++++++ 2 files changed, 50 insertions(+) diff --git a/docs/source/box.rst b/docs/source/box.rst index 84ba145..e6082e8 100644 --- a/docs/source/box.rst +++ b/docs/source/box.rst @@ -24,6 +24,10 @@ Functions: #. :c:func:`glm_aabb_crop` #. :c:func:`glm_aabb_crop_until` #. :c:func:`glm_aabb_frustum` +#. :c:func:`glm_aabb_invalidate` +#. :c:func:`glm_aabb_isvalid` +#. :c:func:`glm_aabb_size` +#. :c:func:`glm_aabb_radius` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -91,3 +95,39 @@ Functions documentation Parameters: | *[in]* **box** bounding box | *[out]* **planes** frustum planes + +.. c:function:: void glm_aabb_invalidate(vec3 box[2]) + + | invalidate AABB min and max values + + | It fills *max* values with -FLT_MAX and *min* values with +FLT_MAX + + Parameters: + | *[in, out]* **box** bounding box + +.. c:function:: bool check if AABB is valid or not + + | check if AABB intersects with frustum planes + + Parameters: + | *[in]* **box** bounding box + + Returns: + returns true if aabb is valid otherwise false + +.. c:function:: float glm_aabb_size(vec3 box[2]) + + | distance between of min and max + + Parameters: + | *[in]* **box** bounding box + + Returns: + distance between min - max + +.. c:function:: float glm_aabb_radius(vec3 box[2]) + + | radius of sphere which surrounds AABB + + Parameters: + | *[in]* **box** bounding box diff --git a/docs/source/io.rst b/docs/source/io.rst index 9cf8900..34fe696 100644 --- a/docs/source/io.rst +++ b/docs/source/io.rst @@ -39,6 +39,7 @@ Functions: #. :c:func:`glm_vec3_print` #. :c:func:`glm_ivec3_print` #. :c:func:`glm_versor_print` +#. :c:func:`glm_aabb_print` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -90,3 +91,12 @@ Functions documentation Parameters: | *[in]* **vec** quaternion | *[in]* **ostream** FILE to write + +.. c:function:: void glm_aabb_print(versor vec, const char * __restrict tag, FILE * __restrict ostream) + + | print aabb to given stream + + Parameters: + | *[in]* **vec** aabb (axis-aligned bounding box) + | *[in]* **tag** tag to find it more easly in logs + | *[in]* **ostream** FILE to write