From 392dc964d94c211ac6af98e02c56371d6bb8a3cd Mon Sep 17 00:00:00 2001 From: Rosyid Haryadi Date: Tue, 2 Jan 2024 22:21:38 +0700 Subject: refactor --- src/utilities.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 src/utilities.c (limited to 'src/utilities.c') 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 -- cgit v1.2.3-70-g09d2