Can update mouse mode from lua
This commit is contained in:
@@ -14,10 +14,26 @@ Input *Input::GetInstance() {
|
||||
}
|
||||
|
||||
|
||||
void Input::Use(Window window){
|
||||
glfwSetInputMode(window.glfwWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
glfwSetKeyCallback(window.glfwWindow, (GLFWkeyfun)HandleKeys);
|
||||
glfwSetCursorPosCallback(window.glfwWindow, (GLFWcursorposfun)HandleMousePosition);
|
||||
void Input::Use(Window *window){
|
||||
this->window = window;
|
||||
glfwSetKeyCallback(window->glfwWindow, (GLFWkeyfun)HandleKeys);
|
||||
glfwSetCursorPosCallback(window->glfwWindow, (GLFWcursorposfun)HandleMousePosition);
|
||||
}
|
||||
|
||||
void Input::SetMouseMode(MouseMode mouseMode) {
|
||||
this->mouseMode = mouseMode;
|
||||
|
||||
switch(mouseMode) {
|
||||
case MouseMode::VISIBLE:
|
||||
glfwSetInputMode(window->glfwWindow, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||
break;
|
||||
case MouseMode::CAPTURED:
|
||||
glfwSetInputMode(window->glfwWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
||||
break;
|
||||
case MouseMode::HIDDEN:
|
||||
glfwSetInputMode(window->glfwWindow, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Input::HandleKeys(GLFWwindow *_, int keys, int code, int action, int mods) {
|
||||
|
||||
@@ -13,13 +13,20 @@ typedef void (*MousePositionHandler)(double xpos, double ypos, double xrel, doub
|
||||
|
||||
class Input {
|
||||
public:
|
||||
enum MouseMode {
|
||||
VISIBLE, HIDDEN, CAPTURED
|
||||
};
|
||||
|
||||
static Input *GetInstance();
|
||||
void Use(Window window);
|
||||
void Use(Window *window);
|
||||
void SetMouseMode(MouseMode mouseMode);
|
||||
std::vector<KeyHandler> keyHandlers;
|
||||
std::vector<MousePositionHandler> mousePositionHandlers;
|
||||
private:
|
||||
bool firstMousePositionUpdate = true;
|
||||
double lastx, lasty;
|
||||
MouseMode mouseMode;
|
||||
Window *window;
|
||||
Input();
|
||||
static void HandleKeys(GLFWwindow *_, int key, int code, int action, int mods);
|
||||
static void HandleMousePosition(GLFWwindow *_, double xpos, double ypos);
|
||||
|
||||
@@ -69,7 +69,7 @@ int main(int argc, char *argv[]) {
|
||||
root = Node::GetRoot();
|
||||
|
||||
Input *input = Input::GetInstance();
|
||||
input->Use(window);
|
||||
input->Use(&window);
|
||||
|
||||
Camera defaultCamera;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user