implement glm_aabb_sphere as GraphicsGems Solid Box - Solid Sphere test

This commit is contained in:
Recep Aslantas
2018-05-30 23:00:18 +03:00
parent c8fc460ba1
commit 6b2b4b4f12
5 changed files with 23 additions and 19 deletions

View File

@@ -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

View File

@@ -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]);
}
/*!

View File

@@ -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
}

View File

@@ -98,7 +98,6 @@ glm_make_deg(float *rad) {
CGLM_INLINE
float
glm_pow2(float x) {
return x * x;
}

View File

@@ -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);
}