-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer_Keyboard.cpp
More file actions
44 lines (33 loc) · 1.83 KB
/
Copy pathPlayer_Keyboard.cpp
File metadata and controls
44 lines (33 loc) · 1.83 KB
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
#include "Player_Keyboard.h"
#include <glfw3.h>
Player_Keyboard::Player_Keyboard(const bool(&KEY_MAP)[1024]) : key_map(KEY_MAP) {
}
void Player_Keyboard::update(GameObject& g) {
float deltaSpeed = speed * g.delta_time;
if(key_map[GLFW_KEY_LEFT_SHIFT]) { deltaSpeed *= modifier; }
if(key_map[GLFW_KEY_LEFT_ALT]) { deltaSpeed /= modifier; }
//if(key_map[GLFW_KEY_W]) { g.set_position(g.get_position() + g.flat_front * deltaSpeed); }
//if(key_map[GLFW_KEY_S]) { g.set_position(g.get_position() - g.flat_front * deltaSpeed); }
//if(key_map[GLFW_KEY_A]) { g.set_position(g.get_position() - g.right * deltaSpeed); }
//if(key_map[GLFW_KEY_D]) { g.set_position(g.get_position() + g.right * deltaSpeed); }
//if(key_map[GLFW_KEY_SPACE]) { g.set_position(g.get_position() + g.world_up * deltaSpeed); }
//if(key_map[GLFW_KEY_LEFT_CONTROL]) { g.set_position(g.get_position() - g.world_up * deltaSpeed); }
if(key_map[GLFW_KEY_W]) { g.velocity += g.flat_front * deltaSpeed; }
if(key_map[GLFW_KEY_S]) { g.velocity -= g.flat_front * deltaSpeed; }
if(key_map[GLFW_KEY_A]) { g.velocity -= g.right * deltaSpeed; }
if(key_map[GLFW_KEY_D]) { g.velocity += g.right * deltaSpeed; }
if(key_map[GLFW_KEY_SPACE]) { g.velocity += g.world_up * deltaSpeed; }
if(key_map[GLFW_KEY_LEFT_CONTROL]) { g.velocity -= g.world_up * deltaSpeed; }
float limit = 0.5f;
while(glm::length(glm::vec3(g.velocity.x, 0, g.velocity.z)) >= limit) {
g.velocity = glm::vec3(g.velocity.x * limit, g.velocity.y, g.velocity.z * limit);
}
if(key_map[GLFW_KEY_M]) { std::cout << "Position: (" << g.get_position().x << "," << g.get_position().y << "," << g.get_position().z << ")" << std::endl; }
}
void Player_Keyboard::receive(std::string component, std::string action) {
// TODO: incorporate some form of message system
}
void Player_Keyboard::activate() {
}
void Player_Keyboard::deactivate() {
}