From 5b3aabc103efa7bf2d0a4dfe057e9cc5a24e1b27 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 29 May 2018 23:19:39 +0300 Subject: [PATCH 1/8] aabb intersect functions * AABB vs AABB * AABB vs Point * AABB vs Sphere * AABB contains AABB --- include/cglm/box.h | 65 +++++++++++++++++++++++++++++++++++++++++ include/cglm/call/box.h | 16 ++++++++++ src/box.c | 24 +++++++++++++++ 3 files changed, 105 insertions(+) diff --git a/include/cglm/box.h b/include/cglm/box.h index 5ed135e..72f8b8f 100644 --- a/include/cglm/box.h +++ b/include/cglm/box.h @@ -212,4 +212,69 @@ glm_aabb_center(vec3 box[2], vec3 dest) { glm_vec_center(box[0], box[1], dest); } +/*! + * @brief check if two AABB intersects + * + * @param[in] box bounding box + * @param[in] other other bounding box + */ +CGLM_INLINE +bool +glm_aabb_aabb(vec3 box[2], vec3 other[2]) { + return (box[0][0] <= other[1][0] && box[1][0] >= other[0][0]) + && (box[0][1] <= other[1][1] && box[1][1] >= other[0][1]) + && (box[0][2] <= other[1][2] && box[1][2] >= other[0][2]); +} + +/*! + * @brief check if AABB intersects with sphere + * + * @param[in] box bounding box + * @param[in] other other bounding box + */ +CGLM_INLINE +bool +glm_aabb_sphere(vec3 box[2], vec4 sph) { + vec3 v; + float dist; + + /* get box closest point to sphere center by clamping */ + v[0] = glm_max(box[0][0], glm_min(sph[0], box[1][0])); + v[1] = glm_max(box[0][1], glm_min(sph[1], box[1][1])); + v[2] = glm_max(box[0][2], glm_min(sph[2], box[1][2])); + + /* this is the same as glm_sphere_point */ + dist = glm_vec_distance(v, sph); + + return dist < sph[3]; +} + +/*! + * @brief check if point is inside of AABB + * + * @param[in] box bounding box + * @param[in] point point + */ +CGLM_INLINE +bool +glm_aabb_point(vec3 box[2], vec3 point) { + return (point[0] >= box[0][0] && point[0] <= box[1][0]) + && (point[1] >= box[0][1] && point[1] <= box[1][1]) + && (point[2] >= box[0][2] && point[2] <= box[1][2]); +} + +/*! + * @brief check if AABB contains other AABB + * + * @param[in] box bounding box + * @param[in] other other bounding box + */ +CGLM_INLINE +bool +glm_aabb_contains(vec3 box[2], vec3 other[2]) { + return (box[0][0] <= other[0][0] && box[1][0] >= other[1][0]) + && (box[0][1] <= other[0][1] && box[1][1] >= other[1][1]) + && (box[0][2] <= other[0][2] && box[1][2] >= other[1][2]); +} + #endif /* cglm_box_h */ diff --git a/include/cglm/call/box.h b/include/cglm/call/box.h index bf25508..0d4c8c1 100644 --- a/include/cglm/call/box.h +++ b/include/cglm/call/box.h @@ -56,6 +56,22 @@ CGLM_EXPORT void glmc_aabb_center(vec3 box[2], vec3 dest); +CGLM_EXPORT +bool +glmc_aabb_aabb(vec3 box[2], vec3 other[2]); + +CGLM_EXPORT +bool +glmc_aabb_point(vec3 box[2], vec3 point); + +CGLM_EXPORT +bool +glmc_aabb_contains(vec3 box[2], vec3 other[2]); + +CGLM_EXPORT +bool +glmc_aabb_sphere(vec3 box[2], vec4 sph); + #ifdef __cplusplus } #endif diff --git a/src/box.c b/src/box.c index 0274390..1352f97 100644 --- a/src/box.c +++ b/src/box.c @@ -70,3 +70,27 @@ void glmc_aabb_center(vec3 box[2], vec3 dest) { glm_aabb_center(box, dest); } + +CGLM_EXPORT +bool +glmc_aabb_aabb(vec3 box[2], vec3 other[2]) { + return glm_aabb_aabb(box, other); +} + +CGLM_EXPORT +bool +glmc_aabb_point(vec3 box[2], vec3 point) { + return glm_aabb_point(box, point); +} + +CGLM_EXPORT +bool +glmc_aabb_contains(vec3 box[2], vec3 other[2]) { + return glm_aabb_contains(box, other); +} + +CGLM_EXPORT +bool +glmc_aabb_sphere(vec3 box[2], vec4 sph) { + return glm_aabb_sphere(box, sph); +} From c8fc460ba10e440f4b5a56e1e5931821499d6a4c Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Tue, 29 May 2018 23:29:09 +0300 Subject: [PATCH 2/8] add support for spheres --- include/cglm/cglm.h | 1 + include/cglm/sphere.h | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 include/cglm/sphere.h diff --git a/include/cglm/cglm.h b/include/cglm/cglm.h index 52c7e97..720ae08 100644 --- a/include/cglm/cglm.h +++ b/include/cglm/cglm.h @@ -24,5 +24,6 @@ #include "util.h" #include "io.h" #include "project.h" +#include "sphere.h" #endif /* cglm_h */ diff --git a/include/cglm/sphere.h b/include/cglm/sphere.h new file mode 100644 index 0000000..e837972 --- /dev/null +++ b/include/cglm/sphere.h @@ -0,0 +1,40 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglm_sphere_h +#define cglm_sphere_h + +#include "common.h" +#include "mat4.h" + +/* + Sphere Representation in cglm: [center.x, center.y, center.z, radii] + + You could use this representation or you can convert it to vec4 before call + any function + */ + +CGLM_INLINE +void +glm_sphere_transform(vec4 s, mat4 m, vec4 dest) { + glm_mat4_mulv3(m, s, 1.0f, dest); + dest[3] = s[3]; +} + +CGLM_INLINE +void +glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest) { + float dist, radii; + + dist = glm_vec_distance(s1, s2); + radii = dist + s1[3] + s2[3]; + + glm_vec_center(s1, s2, dest); + dest[3] = radii; +} + +#endif /* cglm_sphere_h */ From 6b2b4b4f120dec6427ab42835a6101b8ec0ceaa4 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 30 May 2018 23:00:18 +0300 Subject: [PATCH 3/8] implement glm_aabb_sphere as GraphicsGems Solid Box - Solid Sphere test --- CREDITS | 8 +++++--- include/cglm/box.h | 27 +++++++++++++++------------ include/cglm/call/box.h | 2 +- include/cglm/util.h | 1 - src/box.c | 4 ++-- 5 files changed, 23 insertions(+), 19 deletions(-) diff --git a/CREDITS b/CREDITS index 44e55a8..0488bad 100644 --- a/CREDITS +++ b/CREDITS @@ -1,7 +1,7 @@ This library [initially] used some [piece of] implementations (may include codes) from these open source projects/resources: -1. Affine Transforms +1. Initial Affine Transforms The original glm repo (g-truc), url: https://github.com/g-truc/glm LICENSE[S]: @@ -11,7 +11,7 @@ LICENSE[S]: FULL LICENSE: https://github.com/g-truc/glm/blob/master/copying.txt -2. Quaternions +2. Initial Quaternions Anton's OpenGL 4 Tutorials book source code: LICENSE: @@ -47,6 +47,8 @@ http://old.cescg.org/CESCG-2002/DSykoraJJelinek/ 7. Quaternions Initial mat4_quat is borrowed from Apple's simd library - 8. Vector Rotation using Quaternion https://gamedev.stackexchange.com/questions/28395/rotating-vector3-by-a-quaternion + +9. Sphere AABB intersect +https://github.com/erich666/GraphicsGems/blob/master/gems/BoxSphere.c diff --git a/include/cglm/box.h b/include/cglm/box.h index 72f8b8f..3708107 100644 --- a/include/cglm/box.h +++ b/include/cglm/box.h @@ -229,24 +229,27 @@ glm_aabb_aabb(vec3 box[2], vec3 other[2]) { /*! * @brief check if AABB intersects with sphere * - * @param[in] box bounding box - * @param[in] other other bounding box + * https://github.com/erich666/GraphicsGems/blob/master/gems/BoxSphere.c + * Solid Box - Solid Sphere test. + * + * @param[in] box solid bounding box + * @param[in] s solid sphere */ CGLM_INLINE bool -glm_aabb_sphere(vec3 box[2], vec4 sph) { - vec3 v; - float dist; +glm_aabb_sphere(vec3 box[2], vec4 s) { + float dmin; + int a, b, c; - /* get box closest point to sphere center by clamping */ - v[0] = glm_max(box[0][0], glm_min(sph[0], box[1][0])); - v[1] = glm_max(box[0][1], glm_min(sph[1], box[1][1])); - v[2] = glm_max(box[0][2], glm_min(sph[2], box[1][2])); + a = s[0] >= box[0][0]; + b = s[1] >= box[0][1]; + c = s[2] >= box[0][2]; - /* this is the same as glm_sphere_point */ - dist = glm_vec_distance(v, sph); + dmin = glm_pow2(s[0] - box[a][0]) + + glm_pow2(s[1] - box[b][1]) + + glm_pow2(s[2] - box[c][2]); - return dist < sph[3]; + return dmin <= glm_pow2(s[3]); } /*! diff --git a/include/cglm/call/box.h b/include/cglm/call/box.h index 0d4c8c1..afb7558 100644 --- a/include/cglm/call/box.h +++ b/include/cglm/call/box.h @@ -70,7 +70,7 @@ glmc_aabb_contains(vec3 box[2], vec3 other[2]); CGLM_EXPORT bool -glmc_aabb_sphere(vec3 box[2], vec4 sph); +glmc_aabb_sphere(vec3 box[2], vec4 s); #ifdef __cplusplus } diff --git a/include/cglm/util.h b/include/cglm/util.h index b272d44..af7514c 100644 --- a/include/cglm/util.h +++ b/include/cglm/util.h @@ -98,7 +98,6 @@ glm_make_deg(float *rad) { CGLM_INLINE float glm_pow2(float x) { - return x * x; } diff --git a/src/box.c b/src/box.c index 1352f97..fd639ea 100644 --- a/src/box.c +++ b/src/box.c @@ -91,6 +91,6 @@ glmc_aabb_contains(vec3 box[2], vec3 other[2]) { CGLM_EXPORT bool -glmc_aabb_sphere(vec3 box[2], vec4 sph) { - return glm_aabb_sphere(box, sph); +glmc_aabb_sphere(vec3 box[2], vec4 s) { + return glm_aabb_sphere(box, s); } From 3dc9070909208a9214b36766f3772a9de526cef3 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 30 May 2018 23:35:59 +0300 Subject: [PATCH 4/8] squared distance for vec3 --- docs/source/vec3.rst | 12 ++++++++++++ include/cglm/call/vec3.h | 4 ++++ include/cglm/vec3.h | 19 ++++++++++++++++--- src/vec3.c | 6 ++++++ 4 files changed, 38 insertions(+), 3 deletions(-) diff --git a/docs/source/vec3.rst b/docs/source/vec3.rst index fcbfbfb..e4a2746 100644 --- a/docs/source/vec3.rst +++ b/docs/source/vec3.rst @@ -56,6 +56,7 @@ Functions: #. :c:func:`glm_vec_inv_to` #. :c:func:`glm_vec_normalize` #. :c:func:`glm_vec_normalize_to` +#. :c:func:`glm_vec_distance2` #. :c:func:`glm_vec_distance` #. :c:func:`glm_vec_angle` #. :c:func:`glm_vec_rotate` @@ -366,6 +367,17 @@ Functions documentation | *[in]* **v2** vector2 | *[out]* **dest** center point +.. c:function:: float glm_vec_distance2(vec3 v1, vec3 v2) + + squared distance between two vectors + + Parameters: + | *[in]* **mat** vector1 + | *[in]* **row1** vector2 + + Returns: + | squared distance (distance * distance) + .. c:function:: float glm_vec_distance(vec3 v1, vec3 v2) distance between two vectors diff --git a/include/cglm/call/vec3.h b/include/cglm/call/vec3.h index 50a6b22..ae21620 100644 --- a/include/cglm/call/vec3.h +++ b/include/cglm/call/vec3.h @@ -148,6 +148,10 @@ CGLM_EXPORT void glmc_vec_center(vec3 v1, vec3 v2, vec3 dest); +CGLM_EXPORT +float +glmc_vec_distance2(vec3 v1, vec3 v2); + CGLM_EXPORT float glmc_vec_distance(vec3 v1, vec3 v2); diff --git a/include/cglm/vec3.h b/include/cglm/vec3.h index 34a910c..18d8a7b 100644 --- a/include/cglm/vec3.h +++ b/include/cglm/vec3.h @@ -633,6 +633,21 @@ glm_vec_center(vec3 v1, vec3 v2, vec3 dest) { glm_vec_scale(dest, 0.5f, dest); } +/** + * @brief squared distance between two vectors + * + * @param[in] v1 vector1 + * @param[in] v2 vector2 + * @return returns squared distance (distance * distance) + */ +CGLM_INLINE +float +glm_vec_distance2(vec3 v1, vec3 v2) { + return glm_pow2(v2[0] - v1[0]) + + glm_pow2(v2[1] - v1[1]) + + glm_pow2(v2[2] - v1[2]); +} + /** * @brief distance between two vectors * @@ -643,9 +658,7 @@ glm_vec_center(vec3 v1, vec3 v2, vec3 dest) { CGLM_INLINE float glm_vec_distance(vec3 v1, vec3 v2) { - return sqrtf(glm_pow2(v2[0] - v1[0]) - + glm_pow2(v2[1] - v1[1]) - + glm_pow2(v2[2] - v1[2])); + return sqrtf(glm_vec_distance2(v1, v2)); } /*! diff --git a/src/vec3.c b/src/vec3.c index 401b983..a2ab499 100644 --- a/src/vec3.c +++ b/src/vec3.c @@ -206,6 +206,12 @@ glmc_vec_center(vec3 v1, vec3 v2, vec3 dest) { glm_vec_center(v1, v2, dest); } +CGLM_EXPORT +float +glmc_vec_distance2(vec3 v1, vec3 v2) { + return glm_vec_distance2(v1, v2); +} + CGLM_EXPORT float glmc_vec_distance(vec3 v1, vec3 v2) { From 720b617ee06ff544695ef4241864b4045e4bb57f Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Wed, 30 May 2018 23:42:22 +0300 Subject: [PATCH 5/8] sphere and aabb --- docs/source/api.rst | 1 + docs/source/box.rst | 41 +++++++++++++++++++++++- docs/source/sphere.rst | 65 ++++++++++++++++++++++++++++++++++++++ include/cglm/call.h | 1 + include/cglm/call/sphere.h | 32 +++++++++++++++++++ include/cglm/sphere.h | 45 ++++++++++++++++++++++++++ makefile.am | 9 ++++-- src/sphere.c | 33 +++++++++++++++++++ win/cglm.vcxproj | 3 ++ win/cglm.vcxproj.filters | 9 ++++++ 10 files changed, 235 insertions(+), 4 deletions(-) create mode 100644 docs/source/sphere.rst create mode 100644 include/cglm/call/sphere.h create mode 100644 src/sphere.c diff --git a/docs/source/api.rst b/docs/source/api.rst index c61365b..d0e4721 100644 --- a/docs/source/api.rst +++ b/docs/source/api.rst @@ -45,3 +45,4 @@ Follow the :doc:`build` documentation for this util io call + sphere diff --git a/docs/source/box.rst b/docs/source/box.rst index 6430c64..7a388e2 100644 --- a/docs/source/box.rst +++ b/docs/source/box.rst @@ -29,6 +29,10 @@ Functions: #. :c:func:`glm_aabb_size` #. :c:func:`glm_aabb_radius` #. :c:func:`glm_aabb_center` +#. :c:func:`glm_aabb_aabb` +#. :c:func:`glm_aabb_sphere` +#. :c:func:`glm_aabb_point` +#. :c:func:`glm_aabb_contains` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -137,6 +141,41 @@ Functions documentation | computes center point of AABB + Parameters: + | *[in]* **box** bounding box + | *[out]* **dest** center of bounding box + +.. c:function:: bool glm_aabb_aabb(vec3 box[2], vec3 other[2]) + + | check if two AABB intersects + Parameters: | *[in]* **box** bounding box - | *[out]* **box** center of bounding box + | *[out]* **other** other bounding box + +.. c:function:: bool glm_aabb_sphere(vec3 box[2], vec4 s) + + | check if AABB intersects with sphere + + | https://github.com/erich666/GraphicsGems/blob/master/gems/BoxSphere.c + | Solid Box - Solid Sphere test. + + Parameters: + | *[in]* **box** solid bounding box + | *[out]* **s** solid sphere + +.. c:function:: bool glm_aabb_point(vec3 box[2], vec3 point) + + | check if point is inside of AABB + + Parameters: + | *[in]* **box** bounding box + | *[out]* **point** point + +.. c:function:: bool glm_aabb_contains(vec3 box[2], vec3 other[2]) + + | check if AABB contains other AABB + + Parameters: + | *[in]* **box** bounding box + | *[out]* **other** other bounding box diff --git a/docs/source/sphere.rst b/docs/source/sphere.rst new file mode 100644 index 0000000..427200e --- /dev/null +++ b/docs/source/sphere.rst @@ -0,0 +1,65 @@ +.. default-domain:: C + +Sphere +================================================================================ + +Header: cglm/sphere.h + +**Definition of sphere:** + +Sphere Representation in cglm is *vec4*: **[center.x, center.y, center.z, radii]** + +You can call any vec3 function by pasing sphere. Because first three elements +defines center of sphere. + +Table of contents (click to go): +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Functions: + +1. :c:func:`glm_sphere_radii` +#. :c:func:`glm_sphere_transform` +#. :c:func:`glm_sphere_merge` +#. :c:func:`glm_sphere_sphere` + +Functions documentation +~~~~~~~~~~~~~~~~~~~~~~~ + +.. c:function:: float glm_sphere_radii(vec4 s) + + | helper for getting sphere radius + + Parameters: + | *[in]* **s** sphere + + Returns: + returns radii + +.. c:function:: void glm_sphere_transform(vec4 s, mat4 m, vec4 dest) + + | apply transform to sphere, it is just wrapper for glm_mat4_mulv3 + + Parameters: + | *[in]* **s** sphere + | *[in]* **m** transform matrix + | *[out]* **dest** transformed sphere + +.. c:function:: void glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest) + + | merges two spheres and creates a new one + + two sphere must be in same space, for instance if one in world space then + the other must be in world space too, not in local space. + + Parameters: + | *[in]* **s1** sphere 1 + | *[in]* **s2** sphere 2 + | *[out]* **dest** merged/extended sphere + +.. c:function:: bool glm_sphere_sphere(vec4 s1, vec4 s2) + + | check if two sphere intersects + + Parameters: + | *[in]* **s1** sphere + | *[in]* **s2** other sphere diff --git a/include/cglm/call.h b/include/cglm/call.h index ce08b78..77148ac 100644 --- a/include/cglm/call.h +++ b/include/cglm/call.h @@ -25,6 +25,7 @@ extern "C" { #include "call/box.h" #include "call/io.h" #include "call/project.h" +#include "call/sphere.h" #ifdef __cplusplus } diff --git a/include/cglm/call/sphere.h b/include/cglm/call/sphere.h new file mode 100644 index 0000000..9a9a59f --- /dev/null +++ b/include/cglm/call/sphere.h @@ -0,0 +1,32 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#ifndef cglmc_sphere_h +#define cglmc_sphere_h +#ifdef __cplusplus +extern "C" { +#endif + +#include "../cglm.h" + +CGLM_EXPORT +float +glmc_sphere_radii(vec4 s); + +CGLM_EXPORT +void +glmc_sphere_transform(vec4 s, mat4 m, vec4 dest); + +CGLM_EXPORT +void +glmc_sphere_merge(vec4 s1, vec4 s2, vec4 dest); + +CGLM_EXPORT +bool +glmc_sphere_sphere(vec4 s1, vec4 s2); + +#endif /* cglmc_sphere_h */ diff --git a/include/cglm/sphere.h b/include/cglm/sphere.h index e837972..4c9d79b 100644 --- a/include/cglm/sphere.h +++ b/include/cglm/sphere.h @@ -18,6 +18,26 @@ any function */ +/*! + * @brief helper for getting sphere radius + * + * @param[in] s sphere + * + * @return returns radii + */ +CGLM_INLINE +float +glm_sphere_radii(vec4 s) { + return s[3]; +} + +/*! + * @brief apply transform to sphere, it is just wrapper for glm_mat4_mulv3 + * + * @param[in] s sphere + * @param[in] m transform matrix + * @param[out] dest transformed sphere + */ CGLM_INLINE void glm_sphere_transform(vec4 s, mat4 m, vec4 dest) { @@ -25,6 +45,16 @@ glm_sphere_transform(vec4 s, mat4 m, vec4 dest) { dest[3] = s[3]; } +/*! + * @brief merges two spheres and creates a new one + * + * two sphere must be in same space, for instance if one in world space then + * the other must be in world space too, not in local space. + * + * @param[in] s1 sphere 1 + * @param[in] s2 sphere 2 + * @param[out] dest merged/extended sphere + */ CGLM_INLINE void glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest) { @@ -33,8 +63,23 @@ glm_sphere_merge(vec4 s1, vec4 s2, vec4 dest) { dist = glm_vec_distance(s1, s2); radii = dist + s1[3] + s2[3]; + radii = glm_max(radii, s1[3]); + radii = glm_max(radii, s2[3]); + glm_vec_center(s1, s2, dest); dest[3] = radii; } +/*! + * @brief check if two sphere intersects + * + * @param[in] s1 sphere + * @param[in] s2 other sphere + */ +CGLM_INLINE +bool +glm_sphere_sphere(vec4 s1, vec4 s2) { + return glm_vec_distance2(s1, s2) <= glm_pow2(s1[3] + s2[3]); +} + #endif /* cglm_sphere_h */ diff --git a/makefile.am b/makefile.am index 1999b3d..7ee0904 100644 --- a/makefile.am +++ b/makefile.am @@ -55,7 +55,8 @@ cglm_HEADERS = include/cglm/version.h \ include/cglm/frustum.h \ include/cglm/box.h \ include/cglm/color.h \ - include/cglm/project.h + include/cglm/project.h \ + include/cglm/sphere.h cglm_calldir=$(includedir)/cglm/call cglm_call_HEADERS = include/cglm/call/mat4.h \ @@ -70,7 +71,8 @@ cglm_call_HEADERS = include/cglm/call/mat4.h \ include/cglm/call/plane.h \ include/cglm/call/frustum.h \ include/cglm/call/box.h \ - include/cglm/call/project.h + include/cglm/call/project.h \ + include/cglm/call/sphere.h cglm_simddir=$(includedir)/cglm/simd cglm_simd_HEADERS = include/cglm/simd/intrin.h @@ -101,7 +103,8 @@ libcglm_la_SOURCES=\ src/plane.c \ src/frustum.c \ src/box.c \ - src/project.c + src/project.c \ + src/sphere.c test_tests_SOURCES=\ test/src/test_common.c \ diff --git a/src/sphere.c b/src/sphere.c new file mode 100644 index 0000000..e6b46fc --- /dev/null +++ b/src/sphere.c @@ -0,0 +1,33 @@ +/* + * Copyright (c), Recep Aslantas. + * + * MIT License (MIT), http://opensource.org/licenses/MIT + * Full license can be found in the LICENSE file + */ + +#include "../include/cglm/cglm.h" +#include "../include/cglm/call.h" + +CGLM_EXPORT +float +glmc_sphere_radii(vec4 s) { + return glm_sphere_radii(s); +} + +CGLM_EXPORT +void +glmc_sphere_transform(vec4 s, mat4 m, vec4 dest) { + glm_sphere_transform(s, m, dest); +} + +CGLM_EXPORT +void +glmc_sphere_merge(vec4 s1, vec4 s2, vec4 dest) { + glm_sphere_merge(s1, s2, dest); +} + +CGLM_EXPORT +bool +glmc_sphere_sphere(vec4 s1, vec4 s2) { + return glm_sphere_sphere(s1, s2); +} diff --git a/win/cglm.vcxproj b/win/cglm.vcxproj index 415a87d..556a24e 100644 --- a/win/cglm.vcxproj +++ b/win/cglm.vcxproj @@ -31,6 +31,7 @@ + @@ -50,6 +51,7 @@ + @@ -72,6 +74,7 @@ + diff --git a/win/cglm.vcxproj.filters b/win/cglm.vcxproj.filters index 3090d72..cf7634b 100644 --- a/win/cglm.vcxproj.filters +++ b/win/cglm.vcxproj.filters @@ -78,6 +78,9 @@ src + + src + @@ -215,5 +218,11 @@ include\cglm\call + + include\cglm\call + + + include\cglm + \ No newline at end of file From 7a8017835703838bca6de519805245dea48ca3a8 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 9 Jun 2018 18:10:44 +0300 Subject: [PATCH 6/8] improve quat_look --- include/cglm/quat.h | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/include/cglm/quat.h b/include/cglm/quat.h index fd4f25f..aa303ca 100644 --- a/include/cglm/quat.h +++ b/include/cglm/quat.h @@ -646,15 +646,12 @@ glm_quat_slerp(versor from, versor to, float t, versor dest) { CGLM_INLINE void glm_quat_look(vec3 eye, versor ori, mat4 dest) { - CGLM_ALIGN(16) vec4 t; - /* orientation */ glm_quat_mat4t(ori, dest); /* translate */ - glm_vec4(eye, 1.0f, t); - glm_mat4_mulv(dest, t, t); - glm_vec_flipsign_to(t, dest[3]); + glm_mat4_mulv3(dest, eye, 1.0f, dest[3]); + glm_vec_flipsign(dest[3]); } /*! From fc14cedf89a1ce45b47fed6cb772d6e6fe9e2b86 Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 9 Jun 2018 18:10:54 +0300 Subject: [PATCH 7/8] update version --- configure.ac | 2 +- docs/source/conf.py | 4 ++-- include/cglm/version.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure.ac b/configure.ac index 6e9c00c..af3a0d9 100644 --- a/configure.ac +++ b/configure.ac @@ -7,7 +7,7 @@ #***************************************************************************** AC_PREREQ([2.69]) -AC_INIT([cglm], [0.4.6], [info@recp.me]) +AC_INIT([cglm], [0.4.7], [info@recp.me]) AM_INIT_AUTOMAKE([-Wall -Werror foreign subdir-objects]) AC_CONFIG_MACRO_DIR([m4]) diff --git a/docs/source/conf.py b/docs/source/conf.py index 995e5a2..8bfd1b1 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -62,9 +62,9 @@ author = u'Recep Aslantas' # built documents. # # The short X.Y version. -version = u'0.4.6' +version = u'0.4.7' # The full version, including alpha/beta/rc tags. -release = u'0.4.6' +release = u'0.4.7' # The language for content autogenerated by Sphinx. Refer to documentation # for a list of supported languages. diff --git a/include/cglm/version.h b/include/cglm/version.h index 370a6a0..6eee580 100644 --- a/include/cglm/version.h +++ b/include/cglm/version.h @@ -10,6 +10,6 @@ #define CGLM_VERSION_MAJOR 0 #define CGLM_VERSION_MINOR 4 -#define CGLM_VERSION_PATCH 6 +#define CGLM_VERSION_PATCH 7 #endif /* cglm_version_h */ From 857265b89230fb8a50e23684fc9618e629b2c15a Mon Sep 17 00:00:00 2001 From: Recep Aslantas Date: Sat, 9 Jun 2018 18:21:29 +0300 Subject: [PATCH 8/8] sphere point intersection --- docs/source/sphere.rst | 9 +++++++++ include/cglm/call/sphere.h | 4 ++++ include/cglm/sphere.h | 14 ++++++++++++++ src/sphere.c | 6 ++++++ 4 files changed, 33 insertions(+) diff --git a/docs/source/sphere.rst b/docs/source/sphere.rst index 427200e..db238f4 100644 --- a/docs/source/sphere.rst +++ b/docs/source/sphere.rst @@ -21,6 +21,7 @@ Functions: #. :c:func:`glm_sphere_transform` #. :c:func:`glm_sphere_merge` #. :c:func:`glm_sphere_sphere` +#. :c:func:`glm_sphere_point` Functions documentation ~~~~~~~~~~~~~~~~~~~~~~~ @@ -63,3 +64,11 @@ Functions documentation Parameters: | *[in]* **s1** sphere | *[in]* **s2** other sphere + +.. c:function:: bool glm_sphere_point(vec4 s, vec3 point) + + | check if sphere intersects with point + + Parameters: + | *[in]* **s** sphere + | *[in]* **point** point diff --git a/include/cglm/call/sphere.h b/include/cglm/call/sphere.h index 9a9a59f..02c3d55 100644 --- a/include/cglm/call/sphere.h +++ b/include/cglm/call/sphere.h @@ -29,4 +29,8 @@ CGLM_EXPORT bool glmc_sphere_sphere(vec4 s1, vec4 s2); +CGLM_EXPORT +bool +glmc_sphere_point(vec4 s, vec3 point); + #endif /* cglmc_sphere_h */ diff --git a/include/cglm/sphere.h b/include/cglm/sphere.h index 4c9d79b..a7501b9 100644 --- a/include/cglm/sphere.h +++ b/include/cglm/sphere.h @@ -82,4 +82,18 @@ glm_sphere_sphere(vec4 s1, vec4 s2) { return glm_vec_distance2(s1, s2) <= glm_pow2(s1[3] + s2[3]); } +/*! + * @brief check if sphere intersects with point + * + * @param[in] s sphere + * @param[in] point point + */ +CGLM_INLINE +bool +glm_sphere_point(vec4 s, vec3 point) { + float rr; + rr = s[3] * s[3]; + return glm_vec_distance2(point, s) <= rr; +} + #endif /* cglm_sphere_h */ diff --git a/src/sphere.c b/src/sphere.c index e6b46fc..003ef87 100644 --- a/src/sphere.c +++ b/src/sphere.c @@ -31,3 +31,9 @@ bool glmc_sphere_sphere(vec4 s1, vec4 s2) { return glm_sphere_sphere(s1, s2); } + +CGLM_EXPORT +bool +glmc_sphere_point(vec4 s, vec3 point) { + return glm_sphere_point(s, point); +}