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