]> git.localhorst.tv Git - blank.git/blob - src/world/Entity.hpp
correct usage of quaternions :P
[blank.git] / src / world / Entity.hpp
1 #ifndef BLANK_WORLD_ENTITY_HPP_
2 #define BLANK_WORLD_ENTITY_HPP_
3
4 #include "Block.hpp"
5 #include "Chunk.hpp"
6 #include "../model/geometry.hpp"
7 #include "../model/EntityModel.hpp"
8
9 #include <string>
10 #include <glm/glm.hpp>
11 #include <glm/gtc/quaternion.hpp>
12
13
14 namespace blank {
15
16 class Shape;
17
18 class Entity {
19
20 public:
21         Entity() noexcept;
22
23         bool HasShape() const noexcept { return shape; }
24         const Shape *GetShape() const noexcept { return shape; }
25         void SetShape(const Shape *, const glm::vec3 &color);
26         void SetShapeless() noexcept;
27
28         const std::string &Name() const noexcept { return name; }
29         void Name(const std::string &n) { name = n; }
30
31         const AABB &Bounds() const noexcept { return bounds; }
32         void Bounds(const AABB &b) noexcept { bounds = b; }
33
34         bool WorldCollidable() const noexcept { return world_collision; }
35         void WorldCollidable(bool b) noexcept { world_collision = b; }
36
37         const glm::vec3 &Velocity() const noexcept { return velocity; }
38         void Velocity(const glm::vec3 &) noexcept;
39
40         const Block::Pos &Position() const noexcept { return position; }
41         void Position(const Chunk::Pos &, const Block::Pos &) noexcept;
42         void Position(const Block::Pos &) noexcept;
43         void Move(const glm::vec3 &delta) noexcept;
44
45         const Chunk::Pos ChunkCoords() const noexcept { return chunk; }
46
47         glm::vec3 AbsolutePosition() const noexcept {
48                 return glm::vec3(chunk * Chunk::Extent()) + position;
49         }
50         glm::vec3 AbsoluteDifference(const Entity &other) const noexcept {
51                 return glm::vec3((chunk - other.chunk) * Chunk::Extent()) + position - other.position;
52         }
53
54         /// direction is rotation axis, magnitude is speed in rad/ms
55         const glm::vec3 &AngularVelocity() const noexcept { return angular_velocity; }
56         void AngularVelocity(const glm::vec3 &) noexcept;
57
58         const glm::quat &Rotation() const noexcept { return rotation; }
59         void Rotation(const glm::quat &) noexcept;
60         void Rotate(const glm::quat &delta) noexcept;
61
62         glm::mat4 Transform(const Chunk::Pos &chunk_offset) const noexcept;
63         Ray Aim(const Chunk::Pos &chunk_offset) const noexcept;
64
65         void Remove() noexcept { remove = true; }
66         bool CanRemove() const noexcept { return remove; }
67
68         void Update(int dt) noexcept;
69
70         void Draw() noexcept {
71                 model.Draw();
72         }
73
74 private:
75         const Shape *shape;
76         EntityModel model;
77
78         std::string name;
79
80         AABB bounds;
81
82         glm::vec3 velocity;
83         Block::Pos position;
84         Chunk::Pos chunk;
85
86         glm::vec3 angular_velocity;
87         glm::quat rotation;
88
89         bool world_collision;
90         bool remove;
91
92 };
93
94 }
95
96 #endif