summary refs log tree commit diff
path: root/src/Mouse.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/Mouse.cpp
parent731846a0c654b39e23c26f611470e401df404c9d (diff)
downloadmeowcraft-fdbfa8e36f85eee051fc562f1a8588970257a20f.tar.zst
meowcraft-fdbfa8e36f85eee051fc562f1a8588970257a20f.zip
Rotating camera with mouse
Diffstat (limited to 'src/Mouse.cpp')
-rw-r--r--src/Mouse.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/Mouse.cpp b/src/Mouse.cpp
new file mode 100644
index 0000000..4715362
--- /dev/null
+++ b/src/Mouse.cpp
@@ -0,0 +1,25 @@
+#include "Mouse.hpp"
+#include "Window.hpp"
+
+namespace MC {
+
+Vector<2> Mouse::update(Window& window) {
+    double x, y;
+    glfwGetCursorPos(window.get(), &x, &y);
+
+    if (m_first_event) {
+        m_last_x = x;
+        m_last_y = y;
+
+        m_first_event = false;
+    }
+
+    Vector<2> movement{static_cast<float>(x) - m_last_x,  static_cast<float>(y) - m_last_y};
+
+    m_last_x = x;
+    m_last_y = y;
+
+    return movement;
+}
+
+}
\ No newline at end of file