mirror of
https://github.com/recp/cglm.git
synced 2026-02-17 03:39:05 +00:00
implement glm_aabb_sphere as GraphicsGems Solid Box - Solid Sphere test
This commit is contained in:
8
CREDITS
8
CREDITS
@@ -1,7 +1,7 @@
|
|||||||
This library [initially] used some [piece of] implementations
|
This library [initially] used some [piece of] implementations
|
||||||
(may include codes) from these open source projects/resources:
|
(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
|
The original glm repo (g-truc), url: https://github.com/g-truc/glm
|
||||||
|
|
||||||
LICENSE[S]:
|
LICENSE[S]:
|
||||||
@@ -11,7 +11,7 @@ LICENSE[S]:
|
|||||||
|
|
||||||
FULL LICENSE: https://github.com/g-truc/glm/blob/master/copying.txt
|
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:
|
Anton's OpenGL 4 Tutorials book source code:
|
||||||
|
|
||||||
LICENSE:
|
LICENSE:
|
||||||
@@ -47,6 +47,8 @@ http://old.cescg.org/CESCG-2002/DSykoraJJelinek/
|
|||||||
7. Quaternions
|
7. Quaternions
|
||||||
Initial mat4_quat is borrowed from Apple's simd library
|
Initial mat4_quat is borrowed from Apple's simd library
|
||||||
|
|
||||||
|
|
||||||
8. Vector Rotation using Quaternion
|
8. Vector Rotation using Quaternion
|
||||||
https://gamedev.stackexchange.com/questions/28395/rotating-vector3-by-a-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
|
||||||
|
|||||||
@@ -229,24 +229,27 @@ glm_aabb_aabb(vec3 box[2], vec3 other[2]) {
|
|||||||
/*!
|
/*!
|
||||||
* @brief check if AABB intersects with sphere
|
* @brief check if AABB intersects with sphere
|
||||||
*
|
*
|
||||||
* @param[in] box bounding box
|
* https://github.com/erich666/GraphicsGems/blob/master/gems/BoxSphere.c
|
||||||
* @param[in] other other bounding box
|
* Solid Box - Solid Sphere test.
|
||||||
|
*
|
||||||
|
* @param[in] box solid bounding box
|
||||||
|
* @param[in] s solid sphere
|
||||||
*/
|
*/
|
||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
bool
|
bool
|
||||||
glm_aabb_sphere(vec3 box[2], vec4 sph) {
|
glm_aabb_sphere(vec3 box[2], vec4 s) {
|
||||||
vec3 v;
|
float dmin;
|
||||||
float dist;
|
int a, b, c;
|
||||||
|
|
||||||
/* get box closest point to sphere center by clamping */
|
a = s[0] >= box[0][0];
|
||||||
v[0] = glm_max(box[0][0], glm_min(sph[0], box[1][0]));
|
b = s[1] >= box[0][1];
|
||||||
v[1] = glm_max(box[0][1], glm_min(sph[1], box[1][1]));
|
c = s[2] >= box[0][2];
|
||||||
v[2] = glm_max(box[0][2], glm_min(sph[2], box[1][2]));
|
|
||||||
|
|
||||||
/* this is the same as glm_sphere_point */
|
dmin = glm_pow2(s[0] - box[a][0])
|
||||||
dist = glm_vec_distance(v, sph);
|
+ glm_pow2(s[1] - box[b][1])
|
||||||
|
+ glm_pow2(s[2] - box[c][2]);
|
||||||
|
|
||||||
return dist < sph[3];
|
return dmin <= glm_pow2(s[3]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ glmc_aabb_contains(vec3 box[2], vec3 other[2]);
|
|||||||
|
|
||||||
CGLM_EXPORT
|
CGLM_EXPORT
|
||||||
bool
|
bool
|
||||||
glmc_aabb_sphere(vec3 box[2], vec4 sph);
|
glmc_aabb_sphere(vec3 box[2], vec4 s);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -98,7 +98,6 @@ glm_make_deg(float *rad) {
|
|||||||
CGLM_INLINE
|
CGLM_INLINE
|
||||||
float
|
float
|
||||||
glm_pow2(float x) {
|
glm_pow2(float x) {
|
||||||
|
|
||||||
return x * x;
|
return x * x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user