]> git.localhorst.tv Git - blank.git/blob - src/ui/PlayerController.hpp
glm backwards compatibility
[blank.git] / src / ui / PlayerController.hpp
1 #ifndef BLANK_UI_PLAYERCONTROLLER_HPP_
2 #define BLANK_UI_PLAYERCONTROLLER_HPP_
3
4 #include "../graphics/glm.hpp"
5 #include "../world/EntityCollision.hpp"
6 #include "../world/EntityController.hpp"
7 #include "../world/WorldCollision.hpp"
8
9
10 namespace blank {
11
12 class Player;
13 class World;
14
15 class PlayerController
16 : public EntityController {
17
18 public:
19         PlayerController(World &, Player &);
20         ~PlayerController();
21
22         World &GetWorld() noexcept { return world; }
23         const World &GetWorld() const noexcept { return world; }
24         Player &GetPlayer() noexcept { return player; }
25         const Player &GetPlayer() const noexcept { return player; }
26
27         WorldCollision &BlockFocus() noexcept { return aim_world; }
28         const WorldCollision &BlockFocus() const noexcept { return aim_world; }
29         EntityCollision &EntityFocus() noexcept { return aim_entity; }
30         const EntityCollision &EntityFocus() const noexcept { return aim_entity; }
31
32         /// set desired direction of movement
33         /// the magnitude (clamped to [0..1]) can be used to attenuate target velocity
34         void SetMovement(const glm::vec3 &) noexcept;
35         const glm::vec3 &GetMovement() const noexcept { return move_dir; }
36
37         /// turn the controlled entity's head by given pitch and yaw deltas
38         void TurnHead(float pitch, float yaw) noexcept;
39
40         /// get player pitch in radians, normalized to [-PI/2,PI/2]
41         float GetPitch() const noexcept;
42         /// get player yaw in radians, normalized to [-PI,PI]
43         float GetYaw() const noexcept;
44
45         /// start doing primary action
46         /// what exactly this means depends on the active item
47         virtual void StartPrimaryAction() = 0;
48         /// stop doing primary action
49         virtual void StopPrimaryAction() = 0;
50         // etc
51         virtual void StartSecondaryAction() = 0;
52         virtual void StopSecondaryAction() = 0;
53         virtual void StartTertiaryAction() = 0;
54         virtual void StopTertiaryAction() = 0;
55
56         /// set the item at given inventory slot as active
57         void SelectInventory(int) noexcept;
58         int InventorySlot() const noexcept;
59
60 protected:
61         void Invalidate() noexcept;
62         void UpdatePlayer() noexcept;
63
64 private:
65         World &world;
66         Player &player;
67         glm::vec3 move_dir;
68         bool dirty;
69
70         WorldCollision aim_world;
71         EntityCollision aim_entity;
72
73 };
74
75 }
76
77 #endif