]> git.localhorst.tv Git - blank.git/commitdiff
runtime-selectable camera mode
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 13 Nov 2015 15:38:23 +0000 (16:38 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Fri, 13 Nov 2015 15:38:49 +0000 (16:38 +0100)
currently only first person and view local -5Z

doc/running
src/client/InteractiveState.hpp
src/client/client.cpp
src/graphics/Viewport.hpp
src/graphics/viewport.cpp
src/standalone/MasterState.cpp
src/standalone/MasterState.hpp
src/ui/ClientController.hpp
src/ui/Keymap.hpp
src/ui/ui.cpp

index 6c3a2f4e884cadc9fe9e0321f2bfdc318b2536b9..7ec93374a5b9ac0784ad1babc37fe2e7c079c48c 100644 (file)
@@ -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
index ac8f87b054bf4bf98fc382b5924f1ec57a33b8f8..f371c8ca837aeb094c7ef5dc719b3f1b84c494f7 100644 (file)
@@ -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;
index 232ba250eaa9236ff4fd9a4603a85ab9449536f9..44d2156538f641991b96ee2c7f07d020ddae4f4b 100644 (file)
@@ -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();
index 96fbaa4deae54840efb53a1bb7fa2474a17d1b21..47302733d1f01c71e34de70ffceddff870f2d624 100644 (file)
@@ -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;
index c46ef28c76fa91bbc6da470615319f69ad75bc73..30b1c3c9d04c422dc8753a696790a4a00578819c 100644 (file)
@@ -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());
index 665f8d4708dcd99b042fd71cffd4444172a7da51..6d457385d3f6d5074a2757bdbf4d2088db766980 100644 (file)
@@ -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 <SDL.h>
@@ -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);
index 9cb095ac1eb8d7d048bc12481e25227ca3feb287..610f13a128665ed615ce41435d436a53562662f4 100644 (file)
@@ -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;
index 56bb78b349dadde69291d21a5fd0150f29b42a3b..fe3f761879a0a48ca3ee0ba79d75ebf1d1bf2f13 100644 (file)
@@ -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;
 
 };
index a3e1d436766b62d828d88d341c449da6cd28ed29..c74308018de5add44c923416b8782dbefa761b3a 100644 (file)
@@ -42,6 +42,7 @@ public:
                TOGGLE_VIDEO,
                TOGGLE_HUD,
                TOGGLE_DEBUG,
+               CAMERA_NEXT,
 
                EXIT,
        };
index 02f2781c5e8f9cdb2326c1933092fd9105569ff1..774b18d3f7179d8510a22b8a3906cdc70e68a549 100644 (file)
@@ -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<std::string, Keymap::Action> 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 },
 };