diff options
author | nathansmithsmith <nathansmith7@mailfence.com> | 2023-09-22 20:09:37 -0600 |
---|---|---|
committer | nathansmithsmith <nathansmith7@mailfence.com> | 2023-09-22 20:09:37 -0600 |
commit | 2dca93d13705ddabfb198680039b839ae15852d8 (patch) | |
tree | af9cc6f334e519007667d6070a33001f6c46dcef | |
parent | 7224002dcf90a2c12db9b031fdeb71bc29414e71 (diff) |
Forgot some filees for the last commit
-rw-r--r-- | src/gyroscope.c | 91 | ||||
-rw-r--r-- | src/gyroscope.h | 23 |
2 files changed, 114 insertions, 0 deletions
diff --git a/src/gyroscope.c b/src/gyroscope.c new file mode 100644 index 0000000..dba5d8d --- /dev/null +++ b/src/gyroscope.c @@ -0,0 +1,91 @@ +#include "gyroscope.h" +#include "game.h" +#include "assets.h" +#include "world.h" + +void resetGyroscopePosition(Gyroscope * gyroscope) { + float width = GetScreenWidth(); + float height = GetScreenHeight(); + + // Set position on screen. + gyroscope->position = (Vector2){ + (width / 2.0) - (GYROSCOPE_TEXTURE_SIZE / 2.0), + height / 1.8 + }; +} + +void initGyroscope(Gyroscope * gyroscope) { + resetGyroscopePosition(gyroscope); + + gyroscope->camera = (Camera3D){ + .fovy = 45, + .projection = CAMERA_PERSPECTIVE, + .position = (Vector3){0.0, 0.0, 3.0}, + .target = Vector3Zero(), + .up = (Vector3){0.0, 1.0, 0.0} + }; + + gyroscope->texture = LoadRenderTexture( + GYROSCOPE_TEXTURE_SIZE, + GYROSCOPE_TEXTURE_SIZE + ); +} + +void closeGyroscope(Gyroscope * gyroscope) { + UnloadRenderTexture(gyroscope->texture); +} + +void drawGyroscope(Game * game, Gyroscope * gyroscope) { + Entity * player = getEntityFromWorld(game->world, 0); + + // Get model + Model model = game->assets.models[GYROSCOPE_ASSET]; + + // Draw this mother fucker. + BeginTextureMode(gyroscope->texture); + ClearBackground(BLACK); + BeginMode3D(gyroscope->camera); + + // Set transform and draw. + model.transform = QuaternionToMatrix(player->rotation); + DrawModel(model, Vector3Zero(), 1, WHITE); + + EndMode3D(); + EndTextureMode(); + + // Draw render texture. + DrawTexture( + gyroscope->texture.texture, + gyroscope->position.x, + gyroscope->position.y, + WHITE + ); + + // Top to bottom. + DrawLineEx( + (Vector2){ + gyroscope->position.x + (GYROSCOPE_TEXTURE_SIZE / 2.0), + gyroscope->position.y, + }, + (Vector2){ + gyroscope->position.x + (GYROSCOPE_TEXTURE_SIZE / 2.0), + gyroscope->position.y + GYROSCOPE_TEXTURE_SIZE, + }, + GYROSCOPE_LINE_THICKNESS, + SKYBLUE + ); + + // Left to right. + DrawLineEx( + (Vector2){ + gyroscope->position.x, + gyroscope->position.y + (GYROSCOPE_TEXTURE_SIZE / 2.0), + }, + (Vector2){ + gyroscope->position.x + GYROSCOPE_TEXTURE_SIZE, + gyroscope->position.y + (GYROSCOPE_TEXTURE_SIZE / 2.0), + }, + GYROSCOPE_LINE_THICKNESS, + YELLOW + ); +} diff --git a/src/gyroscope.h b/src/gyroscope.h new file mode 100644 index 0000000..c8156cc --- /dev/null +++ b/src/gyroscope.h @@ -0,0 +1,23 @@ +#include "gameCommon.h" + +#ifndef GYROSCOPE_H +#define GYROSCOPE_H + +#define GYROSCOPE_LINE_THICKNESS 2.0 +#define GYROSCOPE_TEXTURE_SIZE 80 + +// The gyroscope is rended in 3d but not in the main scene. +// We use a render texture to get the gyroscope render onto the screen. +typedef struct Gyroscope { + Vector2 position; + Camera3D camera; + RenderTexture texture; +} Gyroscope; + +void initGyroscope(Gyroscope * gyroscope); +void closeGyroscope(Gyroscope * gyroscope); + +void resetGyroscopePosition(Gyroscope * gyroscope); +void drawGyroscope(Game * game, Gyroscope * gyroscope); + +#endif |