circle fix, new copy func

This commit is contained in:
duarm
2023-12-02 21:00:21 -03:00
parent 056b28e4da
commit 2a975a7d0a
5 changed files with 52 additions and 23 deletions

View File

@@ -13,6 +13,19 @@
#include "vec4.h"
#include "util.h"
/*!
* @brief copy all members of [aabb] to [dest]
*
* @param[in] aabb source
* @param[out] dest destination
*/
CGLM_INLINE
void
glm_aabb2d_copy(vec2 aabb[2], vec2 dest[2]) {
glm_vec2_copy(aabb[0], dest[0]);
glm_vec2_copy(aabb[1], dest[1]);
}
/*!
* @brief apply transform to Axis-Aligned Bounding aabb
*
@@ -216,27 +229,24 @@ glm_aabb2d_aabb(vec2 aabb[2], vec2 other[2]) {
/*!
* @brief check if AABB intersects with sphere
*
* https://github.com/erich666/GraphicsGems/blob/master/gems/aabbSphere.c
* Solid aabb - Solid Sphere test.
* Circle Representation in cglm: [center.x, center.y, radii]
*
* Sphere Representation in cglm: [center.x, center.y, center.z, radii]
*
* @param[in] aabb solid bounding aabb
* @param[in] s solid sphere
* @param[in] aabb solid bounding aabb
* @param[in] c solid circle
*/
CGLM_INLINE
bool
glm_aabb2d_sphere(vec2 aabb[2], vec4 s) {
glm_aabb2d_circle(vec2 aabb[2], vec3 c) {
float dmin;
int a, b;
a = (s[0] < aabb[0][0]) + (s[0] > aabb[1][0]);
b = (s[1] < aabb[0][1]) + (s[1] > aabb[1][1]);
a = (c[0] < aabb[0][0]) + (c[0] > aabb[1][0]);
b = (c[1] < aabb[0][1]) + (c[1] > aabb[1][1]);
dmin = glm_pow2((s[0] - aabb[!(a - 1)][0]) * (a != 0))
+ glm_pow2((s[1] - aabb[!(b - 1)][1]) * (b != 0));
dmin = glm_pow2((c[0] - aabb[!(a - 1)][0]) * (a != 0))
+ glm_pow2((c[1] - aabb[!(b - 1)][1]) * (b != 0));
return dmin <= glm_pow2(s[3]);
return dmin <= glm_pow2(c[2]);
}
/*!

View File

@@ -13,6 +13,10 @@ extern "C" {
#include "../cglm.h"
CGLM_EXPORT
void
glmc_aabb2d_copy(vec2 aabb[2], vec2 dest[2]);
CGLM_EXPORT
void
glmc_aabb2d_transform(vec2 aabb[2], mat4 m, vec2 dest[2]);
@@ -70,7 +74,7 @@ glmc_aabb2d_contains(vec2 aabb[2], vec2 other[2]);
CGLM_EXPORT
bool
glmc_aabb2d_sphere(vec2 aabb[2], vec4 s);
glmc_aabb2d_circle(vec2 aabb[2], vec3 s);
#ifdef __cplusplus
}

View File

@@ -221,7 +221,7 @@ glms_aabb2d_(sphere)(vec2s aabb[2], vec4s s) {
vec2 rawAabb[2];
glms_vec2_(unpack)(rawAabb, aabb, 2);
return glm_aabb2d_sphere(rawAabb, s.raw);
return glm_aabb2d_circle(rawAabb, s.raw);
}
/*!