aboutsummaryrefslogtreecommitdiff
path: root/src/util.c
diff options
context:
space:
mode:
authornathansmithsmith <thenathansmithsmith@gmail.com>2023-07-09 00:53:10 -0600
committernathansmithsmith <thenathansmithsmith@gmail.com>2023-07-09 00:53:10 -0600
commit3f0be672f9c5a07a98be0dc703b95f1bbe73f33e (patch)
treeaeb7776878e3460f7ba1f33cf2c0d195eb45f2c5 /src/util.c
parentb92adb44b618db0272819cb77e5727441c566838 (diff)
Mouse control working
Diffstat (limited to 'src/util.c')
-rw-r--r--src/util.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c
index 63cc9ab..10d4c09 100644
--- a/src/util.c
+++ b/src/util.c
@@ -3,3 +3,23 @@
AxisAngle AxisAngleIdentity() {
return (AxisAngle){Vector3Zero(), 0.0};
}
+
+float signum(float n) {
+ if (n > 0.0)
+ return 1.0;
+ else if (n < 0.0)
+ return -1.0;
+ else
+ return 0.0;
+}
+
+float closestAngle(float a1, float a2) {
+ float a = fmodf(a1, PI);
+ float b = fmodf(a2, PI);
+ float dir = b - a;
+
+ if (fabsf(dir) > (PI/2))
+ dir = -(signum(dir) * PI) + dir;
+
+ return dir;
+}