summaryrefslogtreecommitdiff
path: root/src/utilities.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/utilities.c')
-rw-r--r--src/utilities.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/utilities.c b/src/utilities.c
new file mode 100644
index 0000000..4823644
--- /dev/null
+++ b/src/utilities.c
@@ -0,0 +1,30 @@
+//
+// Created by sid on 1/2/24.
+//
+#include "raymath.h"
+#include "utilities.h"
+#include "config.h"
+
+Vector2 toCenter(Vector2 vector) {
+ // Used only for drawing, any other calculation using raylib style coordinate (0, 0) top left. x = left-right, y = top-bottom
+ return (Vector2) {
+ vector.x + (float)config.ORIGIN_X,
+ (-1 * vector.y) + (float)config.ORIGIN_Y
+ };
+}
+
+Vector2 toTopLeft(Vector2 vector) {
+ return (Vector2) {
+ vector.x - (float)config.ORIGIN_X,
+ (-1 * vector.y) - (float)config.ORIGIN_Y
+ };
+}
+
+Vector2 angle2HeadingVector(float angle) {
+ // angle in degree
+ angle = angle * (float)M_PI / 180;
+ return (Vector2) {
+ cosf(angle),
+ sinf(angle)
+ };
+} \ No newline at end of file