summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorXANTRONIX Development2022-02-22 23:01:33 -0500
committerXANTRONIX Development2022-02-22 23:01:33 -0500
commitb87df0764dfe36e3ecd9fa1c3c105758c8c28e05 (patch)
tree45c466a3f37b7014e085d2ddc579cd7e6d60fce6
parent0b54991356e07f456012627131531a8abf6b44f9 (diff)
downloadxas-b87df0764dfe36e3ecd9fa1c3c105758c8c28e05.tar.gz
xas-b87df0764dfe36e3ecd9fa1c3c105758c8c28e05.tar.bz2
xas-b87df0764dfe36e3ecd9fa1c3c105758c8c28e05.zip
Use cone rotation, not point of base, for vectors
-rw-r--r--include/xas/spatial.h2
-rw-r--r--src/spatial.c38
2 files changed, 24 insertions, 16 deletions
diff --git a/include/xas/spatial.h b/include/xas/spatial.h
index 6ad2675..db04ceb 100644
--- a/include/xas/spatial.h
+++ b/include/xas/spatial.h
@@ -14,7 +14,7 @@ typedef struct _xas_spatial_coord {
typedef struct _xas_spatial_cone {
xas_spatial_coord apex,
- base;
+ rotation;
float angle;
} xas_spatial_cone;
diff --git a/src/spatial.c b/src/spatial.c
index 9885418..654ef0b 100644
--- a/src/spatial.c
+++ b/src/spatial.c
@@ -78,15 +78,23 @@ static void rotate(xas_spatial_coord rotation,
static int within_cone(xas_spatial_coord coord,
xas_spatial_cone cone) {
- xas_spatial_coord apex_to_x_vect,
- axis_vect;
-
- diff(&apex_to_x_vect, cone.apex, coord);
- diff(&axis_vect, cone.apex, cone.base);
-
- return dotf(apex_to_x_vect, axis_vect)
- / magnf(apex_to_x_vect)
- / magnf(axis_vect) > cosf(cone.angle / 2.0f);
+ xas_spatial_coord apex_to_point_vect,
+ axis_vect,
+ rotated = cone.apex,
+ opposite = {
+ .x = cone.rotation.x * -2.0f,
+ .y = cone.rotation.y * -2.0f,
+ .z = cone.rotation.z * -2.0f
+ };
+
+ rotate(opposite, &rotated);
+
+ diff(&apex_to_point_vect, cone.apex, coord);
+ diff(&axis_vect, cone.apex, rotated);
+
+ return dotf(apex_to_point_vect, axis_vect)
+ / magnf(apex_to_point_vect)
+ / magnf(axis_vect) <= cosf(cone.angle / 2.0f);
}
static int buffer_realloc(xas_spatial_scene *scene,
@@ -178,13 +186,13 @@ ssize_t scene_fill(xas_spatial_scene *scene,
int16_t *dest = (int16_t *)(scene->buffer + 1);
xas_spatial_cone cone_l = {
- .apex = scene->speaker_l,
- .base = { scene->speaker_l.x - 20.0f, scene->speaker_l.y, scene->speaker_l.z },
- .angle = M_PI / 4.0f
+ .apex = scene->speaker_l,
+ .rotation = { 0.0f, M_PI * 1.5f, 0.0f },
+ .angle = M_PI / 4.0f
}, cone_r = {
- .apex = scene->speaker_r,
- .base = { scene->speaker_r.x + 20.0f, scene->speaker_r.y, scene->speaker_r.z },
- .angle = M_PI / 4.0f
+ .apex = scene->speaker_r,
+ .rotation = { 0.0f, M_PI * 0.5f, 0.0f },
+ .angle = M_PI / 4.0f
};
buffer_zero(buffer, count);