fix aabb-sphere test
@@ -228,6 +228,8 @@ glm_aabb_aabb(vec3 box[2], vec3 other[2]) {
* https://github.com/erich666/GraphicsGems/blob/master/gems/BoxSphere.c
* Solid Box - Solid Sphere test.
*
+ * Sphere Representation in cglm: [center.x, center.y, center.z, radii]
+ *
* @param[in] box solid bounding box
* @param[in] s solid sphere
*/
@@ -237,13 +239,13 @@ glm_aabb_sphere(vec3 box[2], vec4 s) {
float dmin;
int a, b, c;
- a = s[0] >= box[0][0];
- b = s[1] >= box[0][1];
- c = s[2] >= box[0][2];
+ a = (s[0] < box[0][0]) + (s[0] > box[1][0]);
+ b = (s[1] < box[0][1]) + (s[1] > box[1][1]);
+ c = (s[2] < box[0][2]) + (s[2] > box[1][2]);
- dmin = glm_pow2(s[0] - box[a][0])
- + glm_pow2(s[1] - box[b][1])
- + glm_pow2(s[2] - box[c][2]);
+ dmin = glm_pow2((s[0] - box[!(a - 1)][0]) * (a != 0))
+ + glm_pow2((s[1] - box[!(b - 1)][1]) * (b != 0))
+ + glm_pow2((s[2] - box[!(c - 1)][2]) * (c != 0));
return dmin <= glm_pow2(s[3]);
}
