diff options
author | Rosyid Haryadi <rosyid_haryadi@protonmail.com> | 2023-12-25 22:32:17 +0700 |
---|---|---|
committer | Rosyid Haryadi <rosyid_haryadi@protonmail.com> | 2023-12-25 22:32:17 +0700 |
commit | 00f129fc21f94293e2b2f9aaff417fddf3363cae (patch) | |
tree | 8c04aa03935175613d7bee94e9cbac2cde431884 | |
parent | 295f1f8ad7baa1398c743c19d1c074ef76d9bb3d (diff) |
fix coordinate transformation
-rw-r--r-- | src/main.c | 31 |
1 files changed, 23 insertions, 8 deletions
@@ -24,17 +24,30 @@ Vector2 toCenter(Vector2 vector); Vector2 toTopLeft(Vector2 vector); Vector2 angle2HeadingVector(float angle); -void doDrawing(); -void doUpdate(); +typedef struct Object { + Vector2 pos; + float radius; + Color color; + float headingAngle; +} Object; + +void doDrawing(Object *object); +void doUpdate(Object *object); int main(void) { doInitialization(); + Object object = { + .pos = (Vector2) {0, 0}, + .radius = 20.0f, + .color = BLUE, + .headingAngle = 90 + }; while (!WindowShouldClose()) { - doUpdate(); - doDrawing(); + doUpdate(&object); + doDrawing(&object); } CloseWindow(); @@ -48,16 +61,17 @@ void doInitialization() { } 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) + (-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) + (-1 * vector.y) - (float)config.ORIGIN_Y }; } @@ -70,14 +84,15 @@ Vector2 angle2HeadingVector(float angle) { }; } -void doUpdate() { +void doUpdate(Object *object) { float dt = GetFrameTime(); } -void doDrawing() { +void doDrawing(Object *object) { BeginDrawing(); ClearBackground(BLACK); + DrawCircleV(toCenter(object->pos), object->radius, object->color); EndDrawing(); }
\ No newline at end of file |