]> git.localhorst.tv Git - blank.git/blob - src/app/FPSController.cpp
store players in world save
[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         entity.Ref();
14 }
15
16 FPSController::~FPSController() {
17         entity.UnRef();
18 }
19
20
21 void FPSController::Pitch(float p) noexcept {
22         pitch = p;
23         if (pitch > PI / 2) {
24                 pitch = PI / 2;
25         } else if (pitch < -PI / 2) {
26                 pitch = -PI / 2;
27         }
28 }
29
30 void FPSController::RotatePitch(float delta) noexcept {
31         Pitch(pitch + delta);
32 }
33
34 void FPSController::Yaw(float y) noexcept {
35         yaw = y;
36         if (yaw > PI) {
37                 yaw -= PI * 2;
38         } else if (yaw < -PI) {
39                 yaw += PI * 2;
40         }
41 }
42
43 void FPSController::RotateYaw(float delta) noexcept {
44         Yaw(yaw + delta);
45 }
46
47
48 void FPSController::Update(int dt) noexcept {
49         entity.Orientation(glm::quat(glm::vec3(pitch, yaw, 0.0f)));
50         entity.Velocity(glm::rotateY(velocity, yaw));
51 }
52
53 }