]> git.localhorst.tv Git - blank.git/blob - src/app/FPSController.hpp
move RandomWalk into new "ai" module
[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         Entity &Controlled() noexcept { return entity; }
22         const Entity &Controlled() const noexcept { return entity; }
23
24         /// get position and face direction of controlled entity
25         Ray Aim() const noexcept { return entity.Aim(entity.ChunkCoords()); }
26
27         /// velocity, relative to heading (yaw only)
28         const glm::vec3 &Velocity() const noexcept { return velocity; }
29         void Velocity(const glm::vec3 &vel) noexcept { velocity = vel; }
30
31         // all angles in radians (full circle = 2π)
32         float Pitch() const noexcept { return pitch; }
33         void Pitch(float p) noexcept;
34         void RotatePitch(float delta) noexcept;
35         float Yaw() const noexcept { return yaw; }
36         void Yaw(float y) noexcept;
37         void RotateYaw(float delta) noexcept;
38
39         void Update(int dt) noexcept;
40
41 private:
42         Entity &entity;
43
44         glm::vec3 velocity;
45
46         float pitch;
47         float yaw;
48
49 };
50
51 }
52
53 #endif