]> git.localhorst.tv Git - blank.git/blobdiff - src/world/Entity.hpp
correct usage of quaternions :P
[blank.git] / src / world / Entity.hpp
index 83c1f6fb0889b88697365e34a129b15aa7dc076f..078daa6fe0eb4e5a80236b1b696e757f88fa92c7 100644 (file)
@@ -3,15 +3,16 @@
 
 #include "Block.hpp"
 #include "Chunk.hpp"
-#include "../model/Model.hpp"
+#include "../model/geometry.hpp"
+#include "../model/EntityModel.hpp"
 
+#include <string>
 #include <glm/glm.hpp>
 #include <glm/gtc/quaternion.hpp>
 
 
 namespace blank {
 
-class Ray;
 class Shape;
 
 class Entity {
@@ -24,39 +25,69 @@ public:
        void SetShape(const Shape *, const glm::vec3 &color);
        void SetShapeless() noexcept;
 
+       const std::string &Name() const noexcept { return name; }
+       void Name(const std::string &n) { name = n; }
+
+       const AABB &Bounds() const noexcept { return bounds; }
+       void Bounds(const AABB &b) noexcept { bounds = b; }
+
+       bool WorldCollidable() const noexcept { return world_collision; }
+       void WorldCollidable(bool b) noexcept { world_collision = b; }
+
        const glm::vec3 &Velocity() const noexcept { return velocity; }
        void Velocity(const glm::vec3 &) noexcept;
 
        const Block::Pos &Position() const noexcept { return position; }
+       void Position(const Chunk::Pos &, const Block::Pos &) noexcept;
        void Position(const Block::Pos &) noexcept;
        void Move(const glm::vec3 &delta) noexcept;
 
        const Chunk::Pos ChunkCoords() const noexcept { return chunk; }
 
-       const glm::quat &AngularVelocity() const noexcept { return angular_velocity; }
-       void AngularVelocity(const glm::quat &) noexcept;
+       glm::vec3 AbsolutePosition() const noexcept {
+               return glm::vec3(chunk * Chunk::Extent()) + position;
+       }
+       glm::vec3 AbsoluteDifference(const Entity &other) const noexcept {
+               return glm::vec3((chunk - other.chunk) * Chunk::Extent()) + position - other.position;
+       }
+
+       /// direction is rotation axis, magnitude is speed in rad/ms
+       const glm::vec3 &AngularVelocity() const noexcept { return angular_velocity; }
+       void AngularVelocity(const glm::vec3 &) noexcept;
 
-       const glm::mat4 &Rotation() const noexcept { return rotation; }
-       void Rotation(const glm::mat4 &) noexcept;
+       const glm::quat &Rotation() const noexcept { return rotation; }
+       void Rotation(const glm::quat &) noexcept;
        void Rotate(const glm::quat &delta) noexcept;
 
        glm::mat4 Transform(const Chunk::Pos &chunk_offset) const noexcept;
        Ray Aim(const Chunk::Pos &chunk_offset) const noexcept;
 
+       void Remove() noexcept { remove = true; }
+       bool CanRemove() const noexcept { return remove; }
+
        void Update(int dt) noexcept;
 
-       void Draw() noexcept;
+       void Draw() noexcept {
+               model.Draw();
+       }
 
 private:
        const Shape *shape;
-       Model model;
+       EntityModel model;
+
+       std::string name;
+
+       AABB bounds;
 
        glm::vec3 velocity;
        Block::Pos position;
        Chunk::Pos chunk;
 
-       glm::quat angular_velocity;
-       glm::mat4 rotation;
+       glm::vec3 angular_velocity;
+       glm::quat rotation;
+
+       bool world_collision;
+       bool remove;
 
 };