From afc50302943e4000a8621c23960d63b208c8a400 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Fri, 13 Nov 2015 16:38:23 +0100 Subject: [PATCH] runtime-selectable camera mode currently only first person and view local -5Z --- doc/running | 1 + src/client/InteractiveState.hpp | 1 + src/client/client.cpp | 9 +++++++++ src/graphics/Viewport.hpp | 5 +++++ src/graphics/viewport.cpp | 5 ++--- src/standalone/MasterState.cpp | 9 +++++++++ src/standalone/MasterState.hpp | 1 + src/ui/ClientController.hpp | 8 ++++++++ src/ui/Keymap.hpp | 1 + src/ui/ui.cpp | 17 +++++++++-------- 10 files changed, 46 insertions(+), 11 deletions(-) diff --git a/doc/running b/doc/running index 6c3a2f4..7ec9337 100644 --- a/doc/running +++ b/doc/running @@ -103,6 +103,7 @@ F1 toggles UI rendering. F2 toggles world rendering. F3 toggles the debug overlay. F4 toggles audio. +F5 toggles camera mode. Controls are interpreted by scancode, meaning you don't have to break your fingers when you're on an AZERTY. WSAD will be ZSQD there and the above diff --git a/src/client/InteractiveState.hpp b/src/client/InteractiveState.hpp index ac8f87b..f371c8c 100644 --- a/src/client/InteractiveState.hpp +++ b/src/client/InteractiveState.hpp @@ -64,6 +64,7 @@ public: void SetVideo(bool) override; void SetHUD(bool) override; void SetDebug(bool) override; + void NextCamera() override; void Exit() override; void OnLineSubmit(const std::string &) override; diff --git a/src/client/client.cpp b/src/client/client.cpp index 232ba25..44d2156 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -4,6 +4,7 @@ #include "../app/Environment.hpp" #include "../app/init.hpp" +#include "../geometry/distance.hpp" #include "../model/Model.hpp" #include "../io/WorldSave.hpp" #include "../world/ChunkIndex.hpp" @@ -350,6 +351,14 @@ void InteractiveState::SetDebug(bool b) { } } +void InteractiveState::NextCamera() { + if (iszero(master.GetEnv().viewport.CameraOffset())) { + master.GetEnv().viewport.OffsetCamera(glm::vec3(0.0f, 0.0f, -5.0f)); + } else { + master.GetEnv().viewport.OffsetCamera(glm::vec3(0.0f, 0.0f, 0.0f)); + } +} + void InteractiveState::Exit() { save.Write(player); master.Quit(); diff --git a/src/graphics/Viewport.hpp b/src/graphics/Viewport.hpp index 96fbaa4..4730273 100644 --- a/src/graphics/Viewport.hpp +++ b/src/graphics/Viewport.hpp @@ -51,6 +51,9 @@ public: void MoveCursor(const glm::vec3 &) noexcept; const glm::mat4 &Cursor() const noexcept { return cursor; } + void OffsetCamera(const glm::vec3 &o) noexcept { cam_offset = o; } + const glm::vec3 &CameraOffset() const noexcept { return cam_offset; } + BlockLighting &ChunkProgram() noexcept; DirectionalLighting &EntityProgram() noexcept; DirectionalLighting &HUDProgram() noexcept; @@ -70,6 +73,8 @@ private: glm::mat4 cursor; + glm::vec3 cam_offset; + BlockLighting chunk_prog; DirectionalLighting entity_prog; PlainColor color_prog; diff --git a/src/graphics/viewport.cpp b/src/graphics/viewport.cpp index c46ef28..30b1c3c 100644 --- a/src/graphics/viewport.cpp +++ b/src/graphics/viewport.cpp @@ -94,6 +94,7 @@ Viewport::Viewport() : cam() , canv() , cursor(1.0f) +, cam_offset(0.0f) , chunk_prog() , entity_prog() , sky_prog() @@ -263,9 +264,7 @@ BlendedSprite &Viewport::SpriteProgram() noexcept { void Viewport::WorldPosition(const glm::mat4 &t) noexcept { - const glm::vec3 offset(0.0f, 0.0f, 0.0f); - //const glm::vec3 offset(0.0f, 0.0f, -5.0f); - cam.View(glm::translate(glm::inverse(t), glm::vec3(t * glm::vec4(offset, 0.0f)))); + cam.View(glm::translate(glm::inverse(t), glm::vec3(t * glm::vec4(cam_offset, 0.0f)))); ChunkProgram().SetView(cam.View()); sky_prog.Activate(); SkyBoxProgram().SetView(cam.View()); diff --git a/src/standalone/MasterState.cpp b/src/standalone/MasterState.cpp index 665f8d4..6d45738 100644 --- a/src/standalone/MasterState.cpp +++ b/src/standalone/MasterState.cpp @@ -3,6 +3,7 @@ #include "../app/Config.hpp" #include "../app/Environment.hpp" #include "../app/init.hpp" +#include "../geometry/distance.hpp" #include "../io/WorldSave.hpp" #include @@ -205,6 +206,14 @@ void MasterState::SetDebug(bool b) { } } +void MasterState::NextCamera() { + if (iszero(env.viewport.CameraOffset())) { + env.viewport.OffsetCamera(glm::vec3(0.0f, 0.0f, -5.0f)); + } else { + env.viewport.OffsetCamera(glm::vec3(0.0f, 0.0f, 0.0f)); + } +} + void MasterState::Exit() { save.Write(player); env.state.Switch(&unload); diff --git a/src/standalone/MasterState.hpp b/src/standalone/MasterState.hpp index 9cb095a..610f13a 100644 --- a/src/standalone/MasterState.hpp +++ b/src/standalone/MasterState.hpp @@ -63,6 +63,7 @@ public: void SetVideo(bool) override; void SetHUD(bool) override; void SetDebug(bool) override; + void NextCamera() override; void Exit() override; void OnLineSubmit(const std::string &) override; diff --git a/src/ui/ClientController.hpp b/src/ui/ClientController.hpp index 56bb78b..fe3f761 100644 --- a/src/ui/ClientController.hpp +++ b/src/ui/ClientController.hpp @@ -6,11 +6,19 @@ namespace blank { struct ClientController { + /// enable or disable audio output virtual void SetAudio(bool) = 0; + /// enable or disable world rendering virtual void SetVideo(bool) = 0; + /// enable or disable HUD rendering virtual void SetHUD(bool) = 0; + /// enable or disable debug rendering virtual void SetDebug(bool) = 0; + /// change camera mode of world rendering + virtual void NextCamera() = 0; + + /// terminate the application virtual void Exit() = 0; }; diff --git a/src/ui/Keymap.hpp b/src/ui/Keymap.hpp index a3e1d43..c743080 100644 --- a/src/ui/Keymap.hpp +++ b/src/ui/Keymap.hpp @@ -42,6 +42,7 @@ public: TOGGLE_VIDEO, TOGGLE_HUD, TOGGLE_DEBUG, + CAMERA_NEXT, EXIT, }; diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index 02f2781..774b18d 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -597,20 +597,19 @@ void Interface::HandlePress(const SDL_KeyboardEvent &event) { break; case Keymap::TOGGLE_AUDIO: - config.audio.enabled = !config.audio.enabled; - client_ctrl.SetAudio(config.audio.enabled); + client_ctrl.SetAudio(!config.audio.enabled); break; case Keymap::TOGGLE_VIDEO: - config.video.world = !config.video.world; - client_ctrl.SetVideo(config.video.world); + client_ctrl.SetVideo(!config.video.world); break; case Keymap::TOGGLE_HUD: - config.video.hud = !config.video.hud; - client_ctrl.SetHUD(config.video.hud); + client_ctrl.SetHUD(!config.video.hud); break; case Keymap::TOGGLE_DEBUG: - config.video.debug = !config.video.debug; - client_ctrl.SetDebug(config.video.debug); + client_ctrl.SetDebug(!config.video.debug); + break; + case Keymap::CAMERA_NEXT: + client_ctrl.NextCamera(); break; default: @@ -789,6 +788,7 @@ void Keymap::LoadDefault() { Map(SDL_SCANCODE_F2, TOGGLE_VIDEO); Map(SDL_SCANCODE_F3, TOGGLE_DEBUG); Map(SDL_SCANCODE_F4, TOGGLE_AUDIO); + Map(SDL_SCANCODE_F5, CAMERA_NEXT); Map(SDL_SCANCODE_ESCAPE, EXIT); } @@ -874,6 +874,7 @@ std::map action_map = { { "toggle_video", Keymap::TOGGLE_VIDEO }, { "toggle_hud", Keymap::TOGGLE_HUD }, { "toggle_debug", Keymap::TOGGLE_DEBUG }, + { "camera_next", Keymap::CAMERA_NEXT }, { "exit", Keymap::EXIT }, }; -- 2.39.2