summaryrefslogtreecommitdiff
path: root/src/utilities.c
diff options
context:
space:
mode:
authorRosyid Haryadi <rosyid_haryadi@protonmail.com>2024-01-02 22:21:38 +0700
committerRosyid Haryadi <rosyid_haryadi@protonmail.com>2024-01-02 22:21:38 +0700
commit392dc964d94c211ac6af98e02c56371d6bb8a3cd (patch)
tree22cc4da1cad8e0957a54870015cb9d242fdc8696 /src/utilities.c
parente055021f3fb031c9d8851c3237019f7f0db55f77 (diff)
refactori-dont-know
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