]> git.localhorst.tv Git - blank.git/blob - src/world/EntityState.hpp
8f74114cb7de0ba2d681b362385698b4d31c77b8
[blank.git] / src / world / EntityState.hpp
1 #ifndef BLANK_WORLD_ENTITYSTATE_HPP_
2 #define BLANK_WORLD_ENTITYSTATE_HPP_
3
4 #include "Chunk.hpp"
5
6 #include <glm/glm.hpp>
7 #include <glm/gtc/quaternion.hpp>
8
9
10 namespace blank {
11
12 struct EntityState {
13
14         glm::ivec3 chunk_pos;
15         glm::vec3 block_pos;
16         glm::vec3 velocity;
17
18         glm::quat orient;
19         glm::vec3 ang_vel;
20
21         EntityState();
22
23         /// make sure block_pos is within chunk bounds
24         void AdjustPosition() noexcept;
25
26         /// do an integration step of dt milliseconds
27         void Update(int dt) noexcept;
28
29         /// get a position vector relative to the (0,0,0) chunk
30         glm::vec3 AbsolutePosition() const noexcept {
31                 return glm::vec3(chunk_pos * Chunk::Extent()) + block_pos;
32         }
33         /// get a position vector relative to given reference chunk
34         glm::vec3 RelativePosition(const glm::ivec3 &reference) const noexcept {
35                 return glm::vec3((chunk_pos - reference) * Chunk::Extent()) + block_pos;
36         }
37
38         /// get the difference between this and the given position
39         glm::vec3 Diff(const EntityState &other) const noexcept {
40                 return RelativePosition(other.chunk_pos) - other.block_pos;
41         }
42
43         /// get entity state as a matrix tranform relative to given reference chunk
44         glm::mat4 Transform(const glm::ivec3 &reference) const noexcept;
45
46 };
47
48 }
49
50 #endif