summaryrefslogtreecommitdiff
path: root/src/trig.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/trig.c')
-rw-r--r--src/trig.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/trig.c b/src/trig.c
new file mode 100644
index 000000000..cd9f39cac
--- /dev/null
+++ b/src/trig.c
@@ -0,0 +1,35 @@
+#include "global.h"
+
+extern s16 gSineTable[];
+extern s16 gSineDegreeTable[];
+
+// amplitude * sin(index*(π/128))
+s16 Sin(s16 index, s16 amplitude)
+{
+ return (amplitude * gSineTable[index]) >> 8;
+}
+
+// amplitude * cos(index*(π/128))
+s16 Cos(s16 index, s16 amplitude)
+{
+ return (amplitude * gSineTable[index + 64]) >> 8;
+}
+
+// angle in degrees
+s16 Sin2(u16 angle)
+{
+ s32 angleMod = angle % 180;
+ s32 negate = ((angle / 180) & 1);
+ s16 value = gSineDegreeTable[angleMod];
+
+ if (negate)
+ return -value;
+ else
+ return value;
+}
+
+// angle in degrees
+s16 Cos2(u16 angle)
+{
+ return Sin2(angle + 90);
+}