From d73275f04ca0f8c861fa60a073f2ce69a28272d3 Mon Sep 17 00:00:00 2001 From: Abdelrahman Date: Wed, 24 Jan 2024 23:43:14 +0000 Subject: [PATCH] Add line_from_origin function --- src/ui.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/ui.c b/src/ui.c index 91d18c8..4af99db 100644 --- a/src/ui.c +++ b/src/ui.c @@ -8,8 +8,10 @@ #include #define NOODLE_HALF_WIDTH 2 +#define DEFAULT_NOODLE_LENGTH 60 INTERNAL bool aabb(rect rec, i32 x, i32 y); +INTERNAL line line_from_origin(point origin, f64 angle, i32 line_length); void init_ui_ctx(ui_ctx *ctx) { *ctx = (ui_ctx){0}; @@ -239,3 +241,16 @@ INTERNAL bool aabb(rect rec, i32 x, i32 y) { return x > rec.topleft.x && x <= rec.topleft.x + rec.w && y > rec.topleft.y && y <= rec.topleft.y + rec.h; } + +INTERNAL line line_from_origin(point origin, f64 angle, i32 line_length) { + f64 rad = radians(angle); + f64 direction = angle / absolute(angle) * -1; + + i32 adjacent = line_length * cos(rad) * direction; // dx + i32 opposite = line_length * sin(rad) * direction; // dy + + return (line){ + (point){origin.x + adjacent, origin.y + opposite}, + origin, + }; +}