aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornathansmithsmith <nathansmith7@mailfence.com>2023-09-22 20:09:11 -0600
committernathansmithsmith <nathansmith7@mailfence.com>2023-09-22 20:09:11 -0600
commit7224002dcf90a2c12db9b031fdeb71bc29414e71 (patch)
treed0747ce287ffa7d0b1c472e9a3e456b3e904d5de /src
parent31e39555f6625ec7c2b9f8dd99b4bf19872e40c0 (diff)
Moved gyroscope code to its own file
Diffstat (limited to 'src')
-rw-r--r--src/gameScreen.c82
-rw-r--r--src/gameScreen.h9
2 files changed, 6 insertions, 85 deletions
diff --git a/src/gameScreen.c b/src/gameScreen.c
index 3dbb6ac..24f34d1 100644
--- a/src/gameScreen.c
+++ b/src/gameScreen.c
@@ -11,32 +11,16 @@ void initGameScreenGui(GameScreen * gameScreen) {
// It is kind of terrible but works.
gameScreen->infoText = (Vector2){0.0, height / 1.5};
- gameScreen->gyroscopePosition = (Vector2){
- (width / 2.0) - (GYROSCOPE_TEXTURE_SIZE / 2.0),
- height / 1.8
- };
+ // Gyroscope indeed
+ initGyroscope(&gameScreen->gyroscope);
}
void initGameScreen(GameScreen * gameScreen) {
initGameScreenGui(gameScreen);
-
- // The gyroscope is rendered is 3d but not in the main scene.
- gameScreen->gyroscopeCamaera = (Camera3D){
- .fovy = 45,
- .projection = CAMERA_PERSPECTIVE,
- .position = (Vector3){0.0, 0.0, 3.0},
- .target = Vector3Zero(),
- .up = (Vector3){0.0, 1.0, 0.0}
- };
-
- gameScreen->gyroscopeTexture = LoadRenderTexture(
- GYROSCOPE_TEXTURE_SIZE,
- GYROSCOPE_TEXTURE_SIZE
- );
}
void freeGameScreen(GameScreen * gameScreen) {
- UnloadRenderTexture(gameScreen->gyroscopeTexture);
+ closeGyroscope(&gameScreen->gyroscope);
}
void drawCrossHair(float size, float thick, Color color) {
@@ -59,64 +43,6 @@ void drawCrossHair(float size, float thick, Color color) {
);
}
-void drawGyroscope(Game * game) {
- GameScreen * gameScreen = &game->gameScreen;
- Entity * player = getEntityFromWorld(game->world, 0);
- Vector2 gyroscopePosition = gameScreen->gyroscopePosition;
-
- // Get texture and model.
- Texture2D texture = game->assets.textures[GYROSCOPE_TEXTURE_ASSET];
- Model model = game->assets.models[GYROSCOPE_ASSET];
-
- // Draw this mother fucker.
- BeginTextureMode(gameScreen->gyroscopeTexture);
- ClearBackground(BLACK);
- BeginMode3D(gameScreen->gyroscopeCamaera);
-
- // Set transform and draw.
- model.transform = QuaternionToMatrix(player->rotation);
- DrawModel(model, Vector3Zero(), 1, WHITE);
-
- EndMode3D();
- EndTextureMode();
-
- // Draw render texture.
- DrawTexture(
- gameScreen->gyroscopeTexture.texture,
- gyroscopePosition.x,
- gyroscopePosition.y,
- WHITE
- );
-
- // Top to bottom.
- DrawLineEx(
- (Vector2){
- gyroscopePosition.x + (GYROSCOPE_TEXTURE_SIZE / 2.0),
- gyroscopePosition.y,
- },
- (Vector2){
- gyroscopePosition.x + (GYROSCOPE_TEXTURE_SIZE / 2.0),
- gyroscopePosition.y + GYROSCOPE_TEXTURE_SIZE,
- },
- GYROSCOPE_LINE_THICKNESS,
- SKYBLUE
- );
-
- // Left to right.
- DrawLineEx(
- (Vector2){
- gyroscopePosition.x,
- gyroscopePosition.y + (GYROSCOPE_TEXTURE_SIZE / 2.0),
- },
- (Vector2){
- gyroscopePosition.x + GYROSCOPE_TEXTURE_SIZE,
- gyroscopePosition.y + (GYROSCOPE_TEXTURE_SIZE / 2.0),
- },
- GYROSCOPE_LINE_THICKNESS,
- YELLOW
- );
-}
-
void drawGameScreenGui(Game * game) {
GameScreen * gameScreen = &game->gameScreen;
Entity * player = getEntityFromWorld(game->world, 0);
@@ -152,7 +78,7 @@ void drawGameScreenGui(Game * game) {
GREEN
);
- drawGyroscope(game);
+ drawGyroscope(game, &gameScreen->gyroscope);
}
void updateGameScreen(Game * game) {
diff --git a/src/gameScreen.h b/src/gameScreen.h
index 698b044..42591a4 100644
--- a/src/gameScreen.h
+++ b/src/gameScreen.h
@@ -1,20 +1,15 @@
#include "gameCommon.h"
+#include "gyroscope.h"
#ifndef GAME_SCREEN_H
#define GAME_SCREEN_H
#define GAME_SCREEN_TEXT_SIZE 20.0
-#define GYROSCOPE_LINE_THICKNESS 2.0
-#define GYROSCOPE_TEXTURE_SIZE 80
-
// Gui stuff and shit.
typedef struct GameScreen {
Vector2 infoText;
-
- Vector2 gyroscopePosition;
- Camera3D gyroscopeCamaera;
- RenderTexture gyroscopeTexture;
+ Gyroscope gyroscope;
} GameScreen;
void initGameScreen(GameScreen * gameScreen);