1 #ifndef BLANK_WORLD_ENTITY_HPP_
2 #define BLANK_WORLD_ENTITY_HPP_
5 #include "EntityState.hpp"
6 #include "../model/CompositeInstance.hpp"
7 #include "../model/geometry.hpp"
11 #include <glm/glm.hpp>
12 #include <glm/gtc/quaternion.hpp>
17 class DirectionalLighting;
25 CompositeInstance &GetModel() noexcept { return model; }
26 const CompositeInstance &GetModel() const noexcept { return model; }
28 std::uint32_t ID() const noexcept { return id; }
29 void ID(std::uint32_t i) noexcept { id = i; }
31 const std::string &Name() const noexcept { return name; }
32 void Name(const std::string &n) { name = n; }
34 const AABB &Bounds() const noexcept { return bounds; }
35 void Bounds(const AABB &b) noexcept { bounds = b; }
37 bool WorldCollidable() const noexcept { return world_collision; }
38 void WorldCollidable(bool b) noexcept { world_collision = b; }
40 const glm::vec3 &Velocity() const noexcept { return state.velocity; }
41 void Velocity(const glm::vec3 &v) noexcept { state.velocity = v; }
43 const glm::vec3 &Position() const noexcept { return state.block_pos; }
44 void Position(const glm::ivec3 &, const glm::vec3 &) noexcept;
45 void Position(const glm::vec3 &) noexcept;
47 const glm::ivec3 ChunkCoords() const noexcept { return state.chunk_pos; }
49 glm::vec3 AbsolutePosition() const noexcept {
50 return state.AbsolutePosition();
52 glm::vec3 AbsoluteDifference(const Entity &other) const noexcept {
53 return state.Diff(other.state);
56 /// direction is rotation axis, magnitude is speed in rad/ms
57 const glm::vec3 &AngularVelocity() const noexcept { return state.ang_vel; }
58 void AngularVelocity(const glm::vec3 &v) noexcept { state.ang_vel = v; }
60 const glm::quat &Orientation() const noexcept { return state.orient; }
61 void Orientation(const glm::quat &o) noexcept { state.orient = o; }
63 glm::mat4 Transform(const glm::ivec3 &reference) const noexcept {
64 return state.Transform(reference);
66 Ray Aim(const Chunk::Pos &chunk_offset) const noexcept;
68 void SetState(const EntityState &s) noexcept { state = s; }
69 EntityState &GetState() noexcept { return state; }
70 const EntityState &GetState() const noexcept { return state; }
72 void Ref() noexcept { ++ref_count; }
73 void UnRef() noexcept { --ref_count; }
74 void Kill() noexcept { dead = true; }
75 bool Referenced() const noexcept { return ref_count > 0; }
76 bool Dead() const noexcept { return dead; }
77 bool CanRemove() const noexcept { return dead && ref_count <= 0; }
79 void Update(int dt) noexcept;
81 void Render(const glm::mat4 &M, DirectionalLighting &prog) noexcept {
82 if (model) model.Render(M, prog);
86 CompositeInstance model;