X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fentity.cpp;fp=src%2Fentity.cpp;h=ef9275f41f5f3a05ec975f88d6bdbf9afb7ca46b;hb=cb959294a8271969ddfe411471d7f04e82c4788a;hp=0000000000000000000000000000000000000000;hpb=09b5fd4523246deace5f52eed03623d150b76913;p=blank.git diff --git a/src/entity.cpp b/src/entity.cpp new file mode 100644 index 0000000..ef9275f --- /dev/null +++ b/src/entity.cpp @@ -0,0 +1,57 @@ +#include "entity.hpp" + +#include + + +namespace blank { + +Entity::Entity() +: velocity() +, position() +, rotation(1.0f) +, transform(1.0f) +, dirty(false) { + +} + + +void Entity::Velocity(const glm::vec3 &vel) { + velocity = vel; +} + +void Entity::Position(const glm::vec3 &pos) { + position = pos; + dirty = true; +} + +void Entity::Move(const glm::vec3 &delta) { + position += delta; + dirty = true; +} + +void Entity::Rotation(const glm::mat4 &rot) { + rotation = rot; +} + +const glm::mat4 &Entity::Transform() const { + if (dirty) { + transform = glm::translate(position) * rotation; + dirty = false; + } + return transform; +} + +Ray Entity::Aim() const { + Transform(); + glm::vec4 from = transform * glm::vec4(0.0f, 0.0f, 1.0f, 1.0f); + from /= from.w; + glm::vec4 to = transform * glm::vec4(0.0f, 0.0f, -1.0f, 1.0f); + to /= to.w; + return Ray{ glm::vec3(from), glm::normalize(glm::vec3(to - from)) }; +} + +void Entity::Update(int dt) { + Move(velocity * float(dt)); +} + +}