diff options
Diffstat (limited to 'src/gyroscope.c')
-rw-r--r-- | src/gyroscope.c | 35 |
1 files changed, 23 insertions, 12 deletions
diff --git a/src/gyroscope.c b/src/gyroscope.c index dba5d8d..980345c 100644 --- a/src/gyroscope.c +++ b/src/gyroscope.c @@ -3,17 +3,6 @@ #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); @@ -35,9 +24,32 @@ void closeGyroscope(Gyroscope * gyroscope) { UnloadRenderTexture(gyroscope->texture); } +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 updateGyroscopeRotation(Entity * player, Gyroscope * gyroscope) { + // Instead of rotation the gyroscope ball we rotate the camera around it. + gyroscope->camera.position = Vector3Scale( + Vector3RotateByQuaternion((Vector3){0.0, 0.0, 1.0}, player->rotation), + GYROSCOPE_CAMERA_DISTANCE + ); + + gyroscope->camera.up = Vector3RotateByQuaternion((Vector3){0.0, 1.0, 0.0}, player->rotation); +} + void drawGyroscope(Game * game, Gyroscope * gyroscope) { Entity * player = getEntityFromWorld(game->world, 0); + updateGyroscopeRotation(player, gyroscope); + // Get model Model model = game->assets.models[GYROSCOPE_ASSET]; @@ -47,7 +59,6 @@ void drawGyroscope(Game * game, Gyroscope * gyroscope) { BeginMode3D(gyroscope->camera); // Set transform and draw. - model.transform = QuaternionToMatrix(player->rotation); DrawModel(model, Vector3Zero(), 1, WHITE); EndMode3D(); |