-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInputManager.cpp
119 lines (106 loc) · 2.51 KB
/
InputManager.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "InputManager.h"
InputCommands InputManager::lastCmd = NONE;
glm::vec2 InputManager::lastMovement = glm::vec2(0, 0);
InputManager::InputManager() {}
InputManager::~InputManager() {}
InputCommands InputManager::getLastCommand() {
return lastCmd;
}
glm::vec2 InputManager::getLastMovement() {
return lastMovement;
}
void InputManager::reset() {
lastCmd = NONE;
}
void InputManager::CursorCallback(GLFWwindow* window,const double xpos,const double ypos)
{
current_cursor = glm::vec2{xpos, ypos};
if ((glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_RIGHT) == GLFW_PRESS)) {
std::cout << "RIGHT_CLICK" << std::endl;
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
}
if ((glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS)) {
std::cout << "LEFT_CLICK" << std::endl;
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
}
}
glm::vec2 InputManager::GetCursorDelta()
{
const glm::vec2 delta = current_cursor - last_cursor;
last_cursor = current_cursor;
return delta;
}
void InputManager::keyCallback(GLFWwindow* window, int key, int scancode, int action, int mods) {
if (action == GLFW_RELEASE)
{
switch (key)
{
case GLFW_KEY_W:
lastMovement -= glm::vec2(0,1);
lastCmd = STOP_FORWARD;
break;
case GLFW_KEY_S:
lastMovement -= glm::vec2(0,-1);
lastCmd = STOP_BACKWARD;
break;
case GLFW_KEY_A:
lastMovement -= glm::vec2(-1,0);
lastCmd = STOP_LEFT;
break;
case GLFW_KEY_D:
lastMovement -= glm::vec2(1,0);
lastCmd = STOP_RIGHT;
break;
case GLFW_KEY_LEFT_SHIFT:
lastCmd = STOP_SPRINT;
break;
default: break;
}
}
if (action == GLFW_PRESS)
{
// Yeeted by Danica
/**
if (key == GLFW_KEY_ESCAPE) {
glfwSetWindowShouldClose(window, GL_TRUE); // Close the window.
}
*/
switch (key)
{
case GLFW_KEY_W:
lastMovement += glm::vec2(0,1);
lastCmd = MOVE_FORWARD;
break;
case GLFW_KEY_S:
lastMovement += glm::vec2(0,-1);
lastCmd = MOVE_BACKWARD;
break;
case GLFW_KEY_A:
lastMovement += glm::vec2(-1,0);
lastCmd = MOVE_LEFT;
break;
case GLFW_KEY_D:
lastMovement += glm::vec2(1,0);
lastCmd = MOVE_RIGHT;
break;
case GLFW_KEY_F:
lastCmd = USE;
//justMoved = false;
break;
case GLFW_KEY_G:
lastCmd = DROP;
//justMoved = false;
break;
case GLFW_KEY_LEFT_SHIFT:
lastCmd = SPRINT;
break;
case GLFW_KEY_X:
lastCmd = DANCE_CMD;
break;
case GLFW_KEY_ESCAPE:
lastCmd = CLOSE_UI;
break;
default: break;
}
}
}