From 6e64da3b7ad3e694abb400a2e4c54ccf4c19ff6e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20=C5=A0toura=C4=8D?= <525032@mail.muni.cz>
Date: Sat, 14 Oct 2023 00:22:50 +0200
Subject: [PATCH] added switching of orthogonal axis views

---
 src/controls/include/controls/control.hpp |  8 +++++++
 src/edit/include/edit/editor.hpp          |  7 ++++++
 src/edit/src/editor.cpp                   | 27 +++++++++++++++++++++++
 src/studio/src/simulator.cpp              |  1 +
 4 files changed, 43 insertions(+)

diff --git a/src/controls/include/controls/control.hpp b/src/controls/include/controls/control.hpp
index 56ac21a..6d15654 100644
--- a/src/controls/include/controls/control.hpp
+++ b/src/controls/include/controls/control.hpp
@@ -33,6 +33,14 @@ public:
     void setSpeed(float _speed);
 
     void teleport(glm::vec3 new_position) { bound_frame->setPosVec(new_position); }
+    void setRotation(glm::vec3 rotation) { bound_frame->setRotationQuat(rotation); }
+    void setRotation(glm::quat rotation) { bound_frame->setRotationQuat(rotation); }
+
+    void setPos(glm::vec3 position) { bound_frame->setPosVec(position); }
+    void setPos(float x, float y, float z) { bound_frame->setPosVec(glm::vec3(x, y, z)); }
+    void setPosX(float coord) { bound_frame->setPosVec(glm::vec3(coord, bound_frame->getPosition().y, bound_frame->getPosition().z)); }
+    void setPosY(float coord) { bound_frame->setPosVec(glm::vec3(bound_frame->getPosition().x, coord, bound_frame->getPosition().z)); }
+    void setPosZ(float coord) { bound_frame->setPosVec(glm::vec3(bound_frame->getPosition().x, bound_frame->getPosition().y, coord)); }    
 
     void keyboardMove(const std::unordered_set<std::string> &pressed_keys);
     void forward();
diff --git a/src/edit/include/edit/editor.hpp b/src/edit/include/edit/editor.hpp
index f10828e..bdff623 100644
--- a/src/edit/include/edit/editor.hpp
+++ b/src/edit/include/edit/editor.hpp
@@ -29,6 +29,12 @@ class Level
 public:
     std::uint8_t getActiveIndex() const { return active; }
     float getActive() const { return axes[active]; }
+    float getX() { return axes[0]; }
+    float getY() { return axes[1]; }
+    float getZ() { return axes[2]; }
+    std::array<float, 3> getAll() const { return axes; }
+
+    void setActiveIndex(std::uint8_t index) { active = index; }
     void setActiveX() { active = 0; }
     void setActiveY() { active = 1; }
     void setActiveZ() { active = 2; }
@@ -71,6 +77,7 @@ public:
     void setPrevPlaneIntersect(glm::vec3 _prev_plane_intersect) { prev_plane_intersect = _prev_plane_intersect; }
 
     void doObjectAction(scene_ptr scene, ctrlhub_ptr controls);
+    void updateCamera(scene_ptr scene, ctrlhub_ptr controls);
 
     void selectObject(scene_ptr scene, ctrlhub_ptr controls);
     void rotateObject(scene_ptr scene, ctrlhub_ptr controls);
diff --git a/src/edit/src/editor.cpp b/src/edit/src/editor.cpp
index 0c61122..44c7653 100644
--- a/src/edit/src/editor.cpp
+++ b/src/edit/src/editor.cpp
@@ -24,6 +24,33 @@ void Editor::doObjectAction(scene_ptr scene, ctrlhub_ptr controls)
     }
 }
 
+void Editor::updateCamera(scene_ptr scene, ctrlhub_ptr controls)
+{
+    if (!keyboard.just_pressed().contains("I") 
+        && !keyboard.just_pressed().contains("K") 
+        && !keyboard.just_pressed().contains("L") )
+        return;
+
+    std::array<float, 3> levels = build_level.getAll();
+    std::array<glm::vec3, 3> rotations = { glm::vec3(0.0f, 90.0f, 0.0f), // L(x-depth)
+                                           glm::vec3(-89.0f, 0.0f, 0.0f), // I (y-depth) // FIX - should be -90.0f
+                                           glm::vec3(0.0f, 00.0f, 0.0f)  }; // K (z-depth)
+    std::uint8_t new_active = 0;
+
+    if (keyboard.just_pressed().contains("I"))
+        new_active = 1;
+
+    if (keyboard.just_pressed().contains("K"))
+        new_active = 2;
+
+    if (keyboard.just_pressed().contains("L"))
+        new_active = 0;
+
+    levels[new_active] += 5.0f;
+    build_level.setActiveIndex(new_active);
+    controls->getActiveCamCtrl()->setRotation(rotations[new_active]);
+    controls->getActiveCamCtrl()->setPos(levels[0], levels[1], levels[2]);
+}
 void Editor::selectObject(scene_ptr scene, ctrlhub_ptr controls)
 {
     if (!mouse.just_released().contains("MouseLeft"))
diff --git a/src/studio/src/simulator.cpp b/src/studio/src/simulator.cpp
index 7fdb7ff..e6e3d1b 100644
--- a/src/studio/src/simulator.cpp
+++ b/src/studio/src/simulator.cpp
@@ -37,6 +37,7 @@ void Simulator::update()
     controls->processInput(scene, keyboard(), timer(), window());
     controls->processMouse(mouse(), window(), editor->getEditorRunning()); 
 
+    editor->updateCamera(scene, controls);
     editor->doObjectAction(scene, controls);
 
     /* Rotation around x-axis demo */
-- 
GitLab