-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer_Camera.cpp
More file actions
51 lines (36 loc) · 1.5 KB
/
Copy pathPlayer_Camera.cpp
File metadata and controls
51 lines (36 loc) · 1.5 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
45
46
47
48
49
50
51
#include "Player_Camera.h"
Player_Camera::Player_Camera(const std::pair<float, float>& offset) : mouse_offset(&offset) {
}
void Player_Camera::update(GameObject& g) {
// TODO: add in some checking code to only update front, right, up when required
if(!has_target) {
has_target = true;
g.front = glm::normalize(g.get_position() - glm::vec3(g.get_position().x, g.get_position().y, g.get_position().z - 1));
g.right = glm::normalize(glm::cross(g.world_up, g.front));
g.up = glm::normalize(glm::cross(g.front, g.right));
g.front = -glm::normalize(g.front);
}
if(mouse_offset->first != lastX || mouse_offset->second != lastY) {
lastX = mouse_offset->first;
lastY = mouse_offset->second;
float sensitivity = 0.025f;
yaw += mouse_offset->first * sensitivity;
pitch += mouse_offset->second * sensitivity;
if(pitch > 89.0f) { pitch = 89.0f; }
if(pitch < -89.0f) { pitch = -89.0f; }
g.front.x = cos(glm::radians(yaw)) * cos(glm::radians(pitch));
g.front.y = sin(glm::radians(pitch));
g.front.z = sin(glm::radians(yaw)) * cos(glm::radians(pitch));
g.front = glm::normalize(g.front);
g.flat_front = glm::normalize(glm::vec3(g.front.x, 0, g.front.z));
g.right = glm::normalize(glm::cross(g.front, g.world_up));
g.up = -glm::normalize(glm::cross(g.front, g.right));
}
g.view = glm::lookAt(g.get_position(), g.get_position() + g.front, g.up);
}
void Player_Camera::receive(std::string component, std::string action) {
}
void Player_Camera::activate() {
}
void Player_Camera::deactivate() {
}