1 #ifndef BLANK_WORLD_ENTITY_HPP_
2 #define BLANK_WORLD_ENTITY_HPP_
5 #include "../model/CompositeInstance.hpp"
6 #include "../model/geometry.hpp"
10 #include <glm/glm.hpp>
11 #include <glm/gtc/quaternion.hpp>
16 class DirectionalLighting;
24 CompositeInstance &GetModel() noexcept { return model; }
25 const CompositeInstance &GetModel() const noexcept { return model; }
27 std::uint32_t ID() const noexcept { return id; }
28 void ID(std::uint32_t i) noexcept { id = i; }
30 const std::string &Name() const noexcept { return name; }
31 void Name(const std::string &n) { name = n; }
33 const AABB &Bounds() const noexcept { return bounds; }
34 void Bounds(const AABB &b) noexcept { bounds = b; }
36 bool WorldCollidable() const noexcept { return world_collision; }
37 void WorldCollidable(bool b) noexcept { world_collision = b; }
39 const glm::vec3 &Velocity() const noexcept { return velocity; }
40 void Velocity(const glm::vec3 &v) noexcept { velocity = v; }
42 const glm::vec3 &Position() const noexcept { return model.Position(); }
43 void Position(const Chunk::Pos &, const glm::vec3 &) noexcept;
44 void Position(const glm::vec3 &) noexcept;
45 void Move(const glm::vec3 &delta) noexcept;
47 const Chunk::Pos ChunkCoords() const noexcept { return chunk; }
49 glm::vec3 AbsolutePosition() const noexcept {
50 return glm::vec3(chunk * Chunk::Extent()) + Position();
52 glm::vec3 AbsoluteDifference(const Entity &other) const noexcept {
53 return glm::vec3((chunk - other.chunk) * Chunk::Extent()) + Position() - other.Position();
56 /// direction is rotation axis, magnitude is speed in rad/ms
57 const glm::vec3 &AngularVelocity() const noexcept { return angular_velocity; }
58 void AngularVelocity(const glm::vec3 &v) noexcept { angular_velocity = v; }
60 const glm::quat &Orientation() const noexcept { return model.Orientation(); }
61 void Orientation(const glm::quat &o) noexcept { model.Orientation(o); }
62 void Rotate(const glm::quat &delta) noexcept;
64 glm::mat4 ChunkTransform(const Chunk::Pos &chunk_offset) const noexcept;
65 glm::mat4 Transform(const Chunk::Pos &chunk_offset) const noexcept;
66 Ray Aim(const Chunk::Pos &chunk_offset) const noexcept;
68 void Ref() noexcept { ++ref_count; }
69 void UnRef() noexcept { --ref_count; }
70 void Kill() noexcept { dead = true; }
71 bool Referenced() const noexcept { return ref_count > 0; }
72 bool Dead() const noexcept { return dead; }
73 bool CanRemove() const noexcept { return dead && ref_count <= 0; }
75 void Update(int dt) noexcept;
77 void Render(const glm::mat4 &M, DirectionalLighting &prog) noexcept {
78 if (model) model.Render(M, prog);
82 CompositeInstance model;
92 glm::vec3 angular_velocity;