From d47eb8c94355a794058b66e70809528db037f056 Mon Sep 17 00:00:00 2001 From: MrLetsplay2003 Date: Wed, 13 Sep 2023 17:14:17 +0200 Subject: [PATCH] Fix cursor pos, Add convenience constructor --- src/kekengine/cpp/common/defaults.cpp | 21 +++++++++++---------- src/kekengine/include/utils.h | 2 ++ 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/src/kekengine/cpp/common/defaults.cpp b/src/kekengine/cpp/common/defaults.cpp index 0f20cda..7637d2c 100644 --- a/src/kekengine/cpp/common/defaults.cpp +++ b/src/kekengine/cpp/common/defaults.cpp @@ -109,21 +109,19 @@ static void defaultKeyCallback(GLFWwindow *window, int key, int scancode, int ac } static void defaultMouseCallback(GLFWwindow *window, double x, double y, void *data) { + static bool firstMouse = true; + static double lastX = 0, lastY = 0; + if(firstMouse) { + lastX = x; + lastY = y; + firstMouse = false; + } + switch(Input::getCursorMode()) { case GLFWCursorMode::CAPTURE: { - static bool firstMouse = true; - static double lastX = 0, lastY = 0; - if(firstMouse) { - lastX = x; - lastY = y; - firstMouse = false; - } - float xoff = lastX - x; float yoff = lastY - y; - lastX = x; - lastY = y; xoff *= 0.1f; yoff *= 0.1f; @@ -139,6 +137,9 @@ static void defaultMouseCallback(GLFWwindow *window, double x, double y, void *d break; } } + + lastX = x; + lastY = y; } static void defaultMouseButtonCallback(GLFWwindow* window, int button, int action, int mods, void *data) { diff --git a/src/kekengine/include/utils.h b/src/kekengine/include/utils.h index cd41868..8217201 100644 --- a/src/kekengine/include/utils.h +++ b/src/kekengine/include/utils.h @@ -18,6 +18,8 @@ struct GenericCallable { GenericCallable(): function(nullptr), data(nullptr) {} + GenericCallable(GenericFunction function): function(function), data(nullptr) {}; + GenericCallable(GenericFunction function, void *data): function(function), data(data) {} void operator()(Args... args) {