Can update mouse mode from lua
This commit is contained in:
parent
44e8f784f5
commit
2fbbf39e9a
@ -14,10 +14,26 @@ Input *Input::GetInstance() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Input::Use(Window window){
|
void Input::Use(Window *window){
|
||||||
glfwSetInputMode(window.glfwWindow, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
|
this->window = window;
|
||||||
glfwSetKeyCallback(window.glfwWindow, (GLFWkeyfun)HandleKeys);
|
glfwSetKeyCallback(window->glfwWindow, (GLFWkeyfun)HandleKeys);
|
||||||
glfwSetCursorPosCallback(window.glfwWindow, (GLFWcursorposfun)HandleMousePosition);
|
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) {
|
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 {
|
class Input {
|
||||||
public:
|
public:
|
||||||
|
enum MouseMode {
|
||||||
|
VISIBLE, HIDDEN, CAPTURED
|
||||||
|
};
|
||||||
|
|
||||||
static Input *GetInstance();
|
static Input *GetInstance();
|
||||||
void Use(Window window);
|
void Use(Window *window);
|
||||||
|
void SetMouseMode(MouseMode mouseMode);
|
||||||
std::vector<KeyHandler> keyHandlers;
|
std::vector<KeyHandler> keyHandlers;
|
||||||
std::vector<MousePositionHandler> mousePositionHandlers;
|
std::vector<MousePositionHandler> mousePositionHandlers;
|
||||||
private:
|
private:
|
||||||
bool firstMousePositionUpdate = true;
|
bool firstMousePositionUpdate = true;
|
||||||
double lastx, lasty;
|
double lastx, lasty;
|
||||||
|
MouseMode mouseMode;
|
||||||
|
Window *window;
|
||||||
Input();
|
Input();
|
||||||
static void HandleKeys(GLFWwindow *_, int key, int code, int action, int mods);
|
static void HandleKeys(GLFWwindow *_, int key, int code, int action, int mods);
|
||||||
static void HandleMousePosition(GLFWwindow *_, double xpos, double ypos);
|
static void HandleMousePosition(GLFWwindow *_, double xpos, double ypos);
|
||||||
|
@ -69,7 +69,7 @@ int main(int argc, char *argv[]) {
|
|||||||
root = Node::GetRoot();
|
root = Node::GetRoot();
|
||||||
|
|
||||||
Input *input = Input::GetInstance();
|
Input *input = Input::GetInstance();
|
||||||
input->Use(window);
|
input->Use(&window);
|
||||||
|
|
||||||
Camera defaultCamera;
|
Camera defaultCamera;
|
||||||
|
|
||||||
|
@ -26,6 +26,8 @@ function init()
|
|||||||
local material
|
local material
|
||||||
local transform
|
local transform
|
||||||
|
|
||||||
|
couch.Input.GetInstance():SetMouseMode(couch.Input.CAPTURED)
|
||||||
|
|
||||||
freecam.init_camera()
|
freecam.init_camera()
|
||||||
freecam.camera:Translate(couch.Vector3(0.0, 0.0, 10.0))
|
freecam.camera:Translate(couch.Vector3(0.0, 0.0, 10.0))
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
#include "Skybox.h"
|
#include "Skybox.h"
|
||||||
#include "Rigidbody.h"
|
#include "Rigidbody.h"
|
||||||
#include "CollisionShape.h"
|
#include "CollisionShape.h"
|
||||||
|
#include "Input.h"
|
||||||
struct RaycastResult {
|
struct RaycastResult {
|
||||||
bool hit;
|
bool hit;
|
||||||
Vector3 position;
|
Vector3 position;
|
||||||
@ -73,3 +74,4 @@ public:
|
|||||||
%include "Skybox.h"
|
%include "Skybox.h"
|
||||||
%include "Rigidbody.h"
|
%include "Rigidbody.h"
|
||||||
%include "CollisionShape.h"
|
%include "CollisionShape.h"
|
||||||
|
%include "Input.h"
|
||||||
|
Loading…
Reference in New Issue
Block a user