]> git.localhorst.tv Git - blank.git/blob - src/app/FPSController.hpp
some cleaning :)
[blank.git] / src / app / FPSController.hpp
1 #ifndef BLANK_APP_FPSCONTROLLER_HPP_
2 #define BLANK_APP_FPSCONTROLLER_HPP_
3
4 #include "../model/geometry.hpp"
5 #include "../world/Entity.hpp"
6
7 #include <glm/glm.hpp>
8
9
10 namespace blank {
11
12 /// Sets entity rotation and velocity according to stored velocity
13 /// and pitch/yaw components.
14 /// Rotation is applied in yaw,pitch order (YX). Velocity is relative
15 /// to yaw only (Y axis).
16 class FPSController {
17
18 public:
19         explicit FPSController(Entity &) noexcept;
20
21         /// get position and face direction of controlled entity
22         Ray Aim() const noexcept { return entity.Aim(entity.ChunkCoords()); }
23
24         /// velocity, relative to heading (yaw only)
25         const glm::vec3 &Velocity() const noexcept { return velocity; }
26         void Velocity(const glm::vec3 &vel) noexcept { velocity = vel; }
27
28         // all angles in radians (full circle = 2π)
29         float Pitch() const noexcept { return pitch; }
30         void Pitch(float p) noexcept;
31         void RotatePitch(float delta) noexcept;
32         float Yaw() const noexcept { return yaw; }
33         void Yaw(float y) noexcept;
34         void RotateYaw(float delta) noexcept;
35
36         void Update(int dt) noexcept;
37
38 private:
39         Entity &entity;
40
41         glm::vec3 velocity;
42
43         float pitch;
44         float yaw;
45
46 };
47
48 }
49
50 #endif