aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornathansmithsmith <thenathansmithsmith@gmail.com>2023-12-22 15:36:56 -0700
committernathansmithsmith <thenathansmithsmith@gmail.com>2023-12-22 15:36:56 -0700
commit4fa5a5374ae5062d9070b136bf873a50b7d8546f (patch)
treec8729c98d024b8603e9f036934a3be386943e05d /src
parent5c9ab091b5556180c645c0981093a95b2eb61c25 (diff)
Got a somewhat working preview
Diffstat (limited to 'src')
-rw-r--r--src/screens/infoScreen.c83
-rw-r--r--src/screens/infoScreen.h7
-rw-r--r--src/settings.c3
-rw-r--r--src/settings.h3
4 files changed, 83 insertions, 13 deletions
diff --git a/src/screens/infoScreen.c b/src/screens/infoScreen.c
index 98af36f..512ea42 100644
--- a/src/screens/infoScreen.c
+++ b/src/screens/infoScreen.c
@@ -7,44 +7,44 @@ const EntityUserInfo infoScreenEntityInfo[INFO_SCREEN_ENTITY_COUNT] = {
(EntityUserInfo){
.type = ENTITY_ANTIFA,
.assetId = ANTIFA_SHIP_ASSET,
- .cameraPosition = (Vector3){10.0, 10.0, 10.0},
+ .cameraDistance = 15.0,
.msg = "The player ship. Its a anti fascist ship and is completely bad ass."
},
(EntityUserInfo){
.type = ENTITY_SOLDATO,
.assetId = SOLDATO_ASSET,
- .cameraPosition = (Vector3){10.0, 10.0, 10.0},
+ .cameraDistance = 15.0,
.msg = "A wippy little ship. It follows the other ships like ants."
},
(EntityUserInfo){
.type = ENTITY_CAPORALE,
.assetId = CAPORATE_ASSET,
- .cameraPosition = (Vector3){10.0, 10.0, 10.0},
+ .cameraDistance = 15.0,
.msg = "A pretty normal space ship. Often acts as a leader for the soldato."
},
(EntityUserInfo){
.type = ENTITY_SERGENTE,
.assetId = SERGENTE_ASSET,
- .cameraPosition = (Vector3){10.0, 10.0, 10.0},
+ .cameraDistance = 15.0,
.msg = "A funny little dude that packs a lot of power"
},
(EntityUserInfo){
.type = ENTITY_MARESCIALLO,
.assetId = MARESCIALLO_ASSET,
- .cameraPosition = (Vector3){10.0, 10.0, 10.0},
+ .cameraDistance = 15.0,
.msg = "A sneaky little ship based on a stealth jet."
},
(EntityUserInfo)
{
.type = ENTITY_GENERALE,
.assetId = GENERALE_ASSET,
- .cameraPosition = (Vector3){10.0, 10.0, 10.0},
+ .cameraDistance = 15.0,
.msg = "A ufo that goes zig zag and shoots its epic deadly laser.",
},
(EntityUserInfo){
.type = ENTITY_MUSSOLINI,
.assetId = MUSSOLINI_ASSET,
- .cameraPosition = (Vector3){100.0, 100.0, 100.0},
+ .cameraDistance = 100.0,
.msg = "A deadly mother fucker named after the Italian fascist dictator"
}
};
@@ -55,7 +55,7 @@ void initInfoScreen(Game * game) {
infoScreen->goBackButton = (Rectangle){0.0, 25.0, 100.0, 50.0};
infoScreen->camera = (Camera3D){
- .position = infoScreenEntityInfo[0].cameraPosition,
+ .position = (Vector3){0.0, 0.0, infoScreenEntityInfo[0].cameraDistance},
.target = Vector3Zero(),
.up = (Vector3){0.0, 1.0, 0.0},
.fovy = 90.0,
@@ -63,22 +63,83 @@ void initInfoScreen(Game * game) {
};
infoScreen->currentEntity = 0;
+
+ infoScreen->rotation = QuaternionIdentity();
+ infoScreen->resetMouse = true;
+ infoScreen->distance = infoScreenEntityInfo[0].cameraDistance;
+}
+
+void updateInfoScreenCamera(Game * game, InfoScreen * infoScreen) {
+ double t = GetFrameTime();
+ Camera3D * camera = &infoScreen->camera;
+
+ if (infoScreen->resetMouse) {
+ infoScreen->resetMouse = false;
+ SetMousePosition(0, 0);
+ infoScreen->lastMouse = Vector2Zero();
+ }
+
+ // Get mouse.
+ Vector2 mousePosition = GetMousePosition();
+ Vector2 mouseSpeed = Vector2Subtract(mousePosition, infoScreen->lastMouse);
+ mouseSpeed = Vector2Scale(mouseSpeed, 1.0 / t);
+ mouseSpeed = Vector2Scale(mouseSpeed, game->settings.previewMouseSensitivity);
+ infoScreen->lastMouse = mousePosition;
+
+ // Get mouse axis angle.
+ AxisAngle angle = AxisAngleIdentity();
+ angle.axis = (Vector3){mouseSpeed.y, mouseSpeed.x, 0.0};
+ angle.angle = Vector3Length(angle.axis);
+
+ if (IsMouseButtonDown(MOUSE_MIDDLE_BUTTON)) {
+ angle.axis.z = mouseSpeed.x;
+ angle.axis.y = 0.0;
+ }
+
+ // Apply rotation.
+ Quaternion rotationSpeed = QuaternionFromAxisAngle(angle.axis, angle.angle * t);
+ infoScreen->rotation = QuaternionMultiply(infoScreen->rotation, rotationSpeed);
+ infoScreen->rotation = QuaternionNormalize(infoScreen->rotation);
+
+ camera->position = (Vector3){0.0, 0.0, infoScreenEntityInfo[infoScreen->currentEntity].cameraDistance};
}
void updateInfoScreen(Game * game) {
InfoScreen * infoScreen = &game->infoScreen;
ClearBackground(BLACK);
- if (GuiButton(infoScreen->goBackButton, "Back"))
- game->screenId = SCREEN_MAIN_MENU;
+ // Reset.
+ if (IsKeyPressed(KEY_R)) {
+ infoScreen->resetMouse = true;
+ infoScreen->rotation = QuaternionIdentity();
+ }
+
+ // Handling hidding cursor and shit.
+ if (IsMouseButtonPressed(MOUSE_RIGHT_BUTTON)) {
+ DisableCursor();
+ } else if (IsMouseButtonReleased(MOUSE_RIGHT_BUTTON)) {
+ infoScreen->resetMouse = true;
+ EnableCursor();
+ }
+
+ // Switching modes.
+ if (IsMouseButtonDown(MOUSE_RIGHT_BUTTON)) {
+ updateInfoScreenCamera(game, infoScreen);
+ } else {
+ // Back button.
+ if (GuiButton(infoScreen->goBackButton, "Back"))
+ game->screenId = SCREEN_MAIN_MENU;
+ }
EntityUserInfo info = infoScreenEntityInfo[infoScreen->currentEntity];
+ // Draw shit.
BeginMode3D(infoScreen->camera);
+ game->assets.models[info.assetId].transform = QuaternionToMatrix(infoScreen->rotation);
DrawModelWires(game->assets.models[info.assetId], Vector3Zero(), 1.0, GREEN);
- DrawGrid(32, 5.0);
+ //DrawGrid(32, 5.0);
EndMode3D();
}
diff --git a/src/screens/infoScreen.h b/src/screens/infoScreen.h
index 128033a..4113420 100644
--- a/src/screens/infoScreen.h
+++ b/src/screens/infoScreen.h
@@ -11,7 +11,7 @@
typedef struct EntityUserInfo {
EntityType type;
AssetId assetId;
- Vector3 cameraPosition;
+ float cameraDistance;
char msg[ENTITY_USER_INFO_MSG_MAX];
} EntityUserInfo;
@@ -21,6 +21,11 @@ typedef struct InfoScreen {
Rectangle goBackButton;
Camera3D camera;
int currentEntity;
+
+ Vector2 lastMouse;
+ Quaternion rotation;
+ bool resetMouse;
+ float distance;
} InfoScreen;
void initInfoScreen(Game * game);
diff --git a/src/settings.c b/src/settings.c
index 5d1a7fa..268505e 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -17,7 +17,8 @@ void initSettings(Settings * settings) {
.drawFps = true,
.renderWidth = 640,
.renderHeight = 360,
- .useWorldRenderTexture = true
+ .useWorldRenderTexture = true,
+ .previewMouseSensitivity = 0.01
};
}
diff --git a/src/settings.h b/src/settings.h
index b5d703d..e638471 100644
--- a/src/settings.h
+++ b/src/settings.h
@@ -35,6 +35,9 @@ typedef struct Settings {
int renderWidth;
int renderHeight;
bool useWorldRenderTexture;
+
+ // Preview.
+ float previewMouseSensitivity;
} Settings;
void initSettings(Settings * settings);