summary refs log tree commit diff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorMel <einebeere@gmail.com>2022-10-06 02:48:43 +0200
committerMel <einebeere@gmail.com>2022-10-06 02:48:43 +0200
commitfdbfa8e36f85eee051fc562f1a8588970257a20f (patch)
treee861a56c50b1e8532bd71a21064d76d0c148ed3a /src/main.cpp
parent731846a0c654b39e23c26f611470e401df404c9d (diff)
downloadmeowcraft-fdbfa8e36f85eee051fc562f1a8588970257a20f.tar.zst
meowcraft-fdbfa8e36f85eee051fc562f1a8588970257a20f.zip
Rotating camera with mouse
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 63d371a..3da3d90 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -10,6 +10,7 @@
 #include "Binder.hpp"
 #include "Math/MVP.hpp"
 #include "Shader/ShaderProgram.hpp"
+#include "Mouse.hpp"
 
 #define APP_NAME "Meowcraft"
 
@@ -21,7 +22,7 @@
 
 void run();
 void render(MC::BindableMesh&);
-void process_input(MC::Window&, MC::Camera&);
+void process_input(MC::Window&, MC::Mouse&, MC::Camera&);
 void setup_gl();
 void fix_macos_render(MC::Window&);
 
@@ -42,6 +43,7 @@ int main() {
 
 void run() {
     MC::Window window(APP_NAME, WINDOW_WIDTH, WINDOW_HEIGHT);
+    MC::Mouse mouse{};
     setup_gl();
 
     glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
@@ -92,7 +94,7 @@ void run() {
         fix_macos_render(window);
 #endif
 
-        process_input(window, camera);
+        process_input(window, mouse, camera);
 
         program.bind();
 
@@ -117,24 +119,24 @@ void render(MC::BindableMesh& mesh) {
     mesh.unbind();
 }
 
-void process_input(MC::Window& window, MC::Camera& camera) {
+void process_input(MC::Window& window, MC::Mouse& mouse, MC::Camera& camera) {
     if (window.key(GLFW_KEY_ESCAPE, GLFW_PRESS)) {
         window.close();
     }
 
+    auto r = mouse.update(window);
+
     auto key = [&](int key) -> float { return window.key(key, GLFW_PRESS); };
 
     float x = key(GLFW_KEY_D) - key(GLFW_KEY_A);
     float y = key(GLFW_KEY_SPACE) - key(GLFW_KEY_LEFT_SHIFT);
     float z = key(GLFW_KEY_S) - key(GLFW_KEY_W);
 
-    float rx = key(GLFW_KEY_DOWN) - key(GLFW_KEY_UP);
-    float ry = key(GLFW_KEY_RIGHT) - key(GLFW_KEY_LEFT);
-
-    auto speed = 0.05f;
+    auto move_speed = 0.05f;
+    auto rotation_speed = 0.1f;
 
-    camera.move_relative({x * speed, y * speed, z * speed});
-    camera.rotate({rx * speed, ry * speed, 0.0f});
+    camera.move_relative({x * move_speed, y * move_speed, z * move_speed});
+    camera.rotate({r.y() * rotation_speed, r.x() * rotation_speed, 0.0f});
 }
 
 void setup_gl() {