]> git.localhorst.tv Git - blank.git/blob - src/app/FPSController.cpp
show player orientation in debug overlay
[blank.git] / src / app / FPSController.cpp
1 #include "FPSController.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) noexcept
10 : entity(entity)
11 , pitch(0)
12 , yaw(0) {
13
14 }
15
16
17 void FPSController::Pitch(float p) noexcept {
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) noexcept {
27         Pitch(pitch + delta);
28 }
29
30 void FPSController::Yaw(float y) noexcept {
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) noexcept {
40         Yaw(yaw + delta);
41 }
42
43
44 void FPSController::Update(int dt) noexcept {
45         entity.Orientation(glm::quat(glm::vec3(pitch, yaw, 0.0f)));
46         entity.Velocity(glm::rotateY(velocity, yaw));
47 }
48
49 }