]> git.localhorst.tv Git - blank.git/blob - src/controller.cpp
b996f9e37a04c80301a5776c288b5af09202b38e
[blank.git] / src / controller.cpp
1 #include "controller.hpp"
2
3 #include <glm/gtx/euler_angles.hpp>
4 #include <glm/gtx/rotate_vector.hpp>
5
6
7 namespace blank {
8
9 FPSController::FPSController(Entity &entity)
10 : entity(entity)
11 , pitch(0)
12 , yaw(0) {
13
14 }
15
16
17 void FPSController::Pitch(float p) {
18         pitch = p;
19         if (pitch > PI / 2) {
20                 pitch = PI / 2;
21         } else if (pitch < -PI / 2) {
22                 pitch = -PI / 2;
23         }
24 }
25
26 void FPSController::RotatePitch(float delta) {
27         Pitch(pitch + delta);
28 }
29
30 void FPSController::Yaw(float y) {
31         yaw = y;
32         if (yaw > PI) {
33                 yaw -= PI * 2;
34         } else if (yaw < -PI) {
35                 yaw += PI * 2;
36         }
37 }
38
39 void FPSController::RotateYaw(float delta) {
40         Yaw(yaw + delta);
41 }
42
43
44 void FPSController::Update(int dt) {
45         entity.Rotation(glm::eulerAngleYX(yaw, pitch));
46         entity.Velocity(glm::rotateY(velocity, yaw));
47 }
48
49 }