From 8a3be441021b006c5e913141daf9c20b8ade9450 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Mon, 21 Feb 2022 19:15:22 -0500 Subject: cats,,, --- src/spatial.c | 80 +++++++++++++++++++++-------------------------------------- 1 file changed, 28 insertions(+), 52 deletions(-) (limited to 'src') diff --git a/src/spatial.c b/src/spatial.c index 74a0cad..791c6f9 100644 --- a/src/spatial.c +++ b/src/spatial.c @@ -12,29 +12,37 @@ static inline float dist(xas_spatial_coord a, xas_spatial_coord b) { + powf(b.z - a.z, 2.0f), 0.5f); } -static float dotf(float *sets, size_t count, size_t len) { - float ret = 0.0f; - - size_t x, y; +static float dotf(xas_spatial_coord a, xas_spatial_coord b) { + return a.x * b.x + + a.y * b.y + + a.z * b.z; +} - if (count == 0 || len == 0) { - return 0.0f; - } +static void diff(xas_spatial_coord *ret, + xas_spatial_coord a, + xas_spatial_coord b) { + ret->x = a.x - b.x; + ret->y = a.y - b.y; + ret->z = a.z - b.z; +} - for (x=0; x= 360.0f) { + ret -= 360.0f; } return ret; } -static void rotate(xas_spatial_rotation rotation, +static void rotate(xas_spatial_coord rotation, xas_spatial_coord *coord) { double cosY = cos(rotation.y), sinY = sin(rotation.y), @@ -68,48 +76,16 @@ static void rotate(xas_spatial_rotation rotation, coord->z = Yz; } -static inline float degf(float rad) { - float ret = (rad / M_PI) * 180.0f; - - while (ret >= 360.0f) { - ret -= 360.0f; - } - - return ret; -} - static int within_cone(xas_spatial_coord coord, xas_spatial_cone cone) { - xas_spatial_rotation rotation = { - .x = (M_PI * 2.0f) - cone.rotation.x, - .y = (M_PI * 2.0f) - cone.rotation.y, - .z = (M_PI * 2.0f) - cone.rotation.z - }; - - float radius; + xas_spatial_coord apex_to_x; - coord.x -= cone.coord.x; - coord.y -= cone.coord.y; - coord.z -= cone.coord.z; + float cosf_angle = cosf(cone.angle / 2.0f); - cone.coord.x = 0.0f; - cone.coord.y = 0.0f; - cone.coord.z = 0.0f; - - rotate(rotation, &coord); - - - radius = tanf(cone.angle / 2.0f) * coord.x; - - /* - * If the given point is outside the cone radius at its X coordinate, then - * it is outside of the cone. - */ - if (fabs(coord.y) > radius || fabs(coord.z) > radius) { - return 0; - } + diff(&apex_to_x, cone.coord, coord); - return 1; + return dotf(apex_to_x, cone.rotation) / magnf(apex_to_x) / magnf(cone.rotation) + > cosf_angle; } static int buffer_realloc(xas_spatial_scene *scene, @@ -347,7 +323,7 @@ void xas_spatial_scene_destroy(xas_spatial_scene *scene) { void xas_spatial_scene_set_observer(xas_spatial_scene *scene, xas_spatial_coord coord, - xas_spatial_rotation rotation, + xas_spatial_coord rotation, float width) { scene->observer.coord = coord; scene->observer.rotation = rotation; -- cgit v1.2.3