diff options
| author | ilotterytea <iltsu@alright.party> | 2024-12-11 11:50:06 +0500 |
|---|---|---|
| committer | ilotterytea <iltsu@alright.party> | 2024-12-11 11:50:06 +0500 |
| commit | 80c74c80615693cf4b8a5090121dad8d14ccfb0f (patch) | |
| tree | 35eded3126e68e182b51314ed80407da099352e5 | |
| parent | cbeb0314a90edb5ce28df2a8892160c0023320cb (diff) | |
feat: mouse can control the world view
| -rw-r--r-- | src/main.c | 17 | ||||
| -rw-r--r-- | src/star.c | 5 | ||||
| -rw-r--r-- | src/star.h | 2 |
3 files changed, 18 insertions, 6 deletions
@@ -5,6 +5,7 @@ #include "time.h" int main(int argc, char *argv[]) { + bool mouse_control = false; srand(time(0)); InitWindow(800, 600, "hyperspace (demo)"); @@ -31,13 +32,27 @@ int main(int argc, char *argv[]) { star->position = Generate3DPosition(); } - StarUpdate(star); + float screen_center_x = + mouse_control ? GetMouseX() : GetScreenWidth() / 2.0; + float screen_center_y = + mouse_control ? GetMouseY() : GetScreenHeight() / 2.0; + + StarUpdate(star, screen_center_x, screen_center_y); DrawRectangle(star->renderPosition.x, star->renderPosition.y, star->size.x, star->size.y, star->color); } EndDrawing(); + + // Listening for input + if (IsMouseButtonPressed(MOUSE_BUTTON_LEFT)) { + mouse_control = !mouse_control; + if (mouse_control) + HideCursor(); + else + ShowCursor(); + } } return 0; @@ -31,10 +31,7 @@ Star StarCreate() { return (Star){Generate3DPosition(), {1, 1}, {0, 0}, velocity, BLACK}; } -void StarUpdate(Star *star) { - float screen_center_x = GetScreenWidth() / 2.0; - float screen_center_y = GetScreenHeight() / 2.0; - +void StarUpdate(Star *star, float screen_center_x, float screen_center_y) { float x = star->position.x / star->position.z + screen_center_x; float y = star->position.y / star->position.z + screen_center_y; @@ -8,6 +8,6 @@ typedef struct Star { } Star; Star StarCreate(); -void StarUpdate(Star *star); +void StarUpdate(Star *star, float screen_center_x, float screen_center_y); Vector3 Generate3DPosition(); |
