From fdbfa8e36f85eee051fc562f1a8588970257a20f Mon Sep 17 00:00:00 2001 From: Mel Date: Thu, 6 Oct 2022 02:48:43 +0200 Subject: Rotating camera with mouse --- src/Mouse.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/Mouse.cpp (limited to 'src/Mouse.cpp') 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(x) - m_last_x, static_cast(y) - m_last_y}; + + m_last_x = x; + m_last_y = y; + + return movement; +} + +} \ No newline at end of file -- cgit 1.4.1