From c664ddaf47e078219b848b9e2d9c3c4241420261 Mon Sep 17 00:00:00 2001 From: ilotterytea Date: Tue, 10 Dec 2024 19:50:26 +0500 Subject: feat: render stars! --- src/star.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/star.c (limited to 'src/star.c') diff --git a/src/star.c b/src/star.c new file mode 100644 index 0000000..6251e03 --- /dev/null +++ b/src/star.c @@ -0,0 +1,43 @@ +#include "star.h" + +#include +#include +#include + +#include "constants.h" +#include "raylib.h" + +Vector3 Generate3DPosition() { + srand(time(0)); + double random = (double)rand() / RAND_MAX; + + double angle = random * 2.0 * M_PI; + double radius = + (GetScreenHeight() / SPACE_SIZE) + (random * GetScreenHeight()); + + float x = radius * sin(angle); + float y = radius * cos(angle); + + Vector3 v = {x, y, STAR_START_POS_Z}; + return v; +} + +Star StarCreate() { + return (Star){Generate3DPosition(), {1, 1}, {0, 0}, 0.25f, BLACK}; +} + +void StarUpdate(Star *star) { + float screen_center_x = GetScreenWidth() / 2.0; + float screen_center_y = GetScreenHeight() / 2.0; + + float x = star->position.x / star->position.z + screen_center_x; + float y = star->position.y / star->position.z + screen_center_y; + + star->renderPosition.x = x; + star->renderPosition.y = y; + + float size = (STAR_START_POS_Z - star->position.z) / (0.2 * star->position.z); + + star->size.x = size; + star->size.y = size; +} -- cgit v1.2.3