]> git.localhorst.tv Git - blank.git/blobdiff - src/world/Entity.cpp
special treatment for players
[blank.git] / src / world / Entity.cpp
index 4a34a111dd35d6ca586780d49eaa0e1d323fecb8..f116153e640a467eec61b434860e118e1369e150 100644 (file)
@@ -15,45 +15,26 @@ blank::EntityModel::Buffer model_buffer;
 namespace blank {
 
 Entity::Entity() noexcept
-: shape(nullptr)
-, model()
+: model()
 , name("anonymous")
 , bounds()
 , velocity(0, 0, 0)
-, position(0, 0, 0)
 , chunk(0, 0, 0)
 , angular_velocity(0.0f)
-, rotation(1.0f, 0.0f, 0.0f, 0.0f)
+, ref_count(0)
 , world_collision(false)
-, remove(false) {
+, dead(false) {
 
 }
 
 
-void Entity::SetShape(const Shape *s, const glm::vec3 &color) {
-       shape = s;
-       model_buffer.Clear();
-       shape->Vertices(model_buffer.vertices, model_buffer.normals, model_buffer.indices);
-       model_buffer.colors.resize(shape->VertexCount(), color);
-       model.Update(model_buffer);
-}
-
-void Entity::SetShapeless() noexcept {
-       shape = nullptr;
-}
-
-
-void Entity::Velocity(const glm::vec3 &vel) noexcept {
-       velocity = vel;
-}
-
-void Entity::Position(const Chunk::Pos &c, const Block::Pos &pos) noexcept {
+void Entity::Position(const Chunk::Pos &c, const glm::vec3 &pos) noexcept {
        chunk = c;
-       position = pos;
+       model.Position(pos);
 }
 
-void Entity::Position(const Block::Pos &pos) noexcept {
-       position = pos;
+void Entity::Position(const glm::vec3 &pos) noexcept {
+       glm::vec3 position(pos);
        while (position.x >= Chunk::width) {
                position.x -= Chunk::width;
                ++chunk.x;
@@ -78,27 +59,25 @@ void Entity::Position(const Block::Pos &pos) noexcept {
                position.z += Chunk::depth;
                --chunk.z;
        }
+       model.Position(position);
 }
 
 void Entity::Move(const glm::vec3 &delta) noexcept {
-       Position(position + delta);
-}
-
-void Entity::AngularVelocity(const glm::vec3 &v) noexcept {
-       angular_velocity = v;
+       Position(Position() + delta);
 }
 
-void Entity::Rotation(const glm::quat &rot) noexcept {
-       rotation = rot;
+void Entity::Rotate(const glm::quat &delta) noexcept {
+       Orientation(delta * Orientation());
 }
 
-void Entity::Rotate(const glm::quat &delta) noexcept {
-       Rotation(delta * Rotation());
+glm::mat4 Entity::ChunkTransform(const Chunk::Pos &chunk_offset) const noexcept {
+       const glm::vec3 translation = glm::vec3((chunk - chunk_offset) * Chunk::Extent());
+       return glm::translate(translation);
 }
 
 glm::mat4 Entity::Transform(const Chunk::Pos &chunk_offset) const noexcept {
-       const glm::vec3 translation = glm::vec3((chunk - chunk_offset) * Chunk::Extent()) + position;
-       glm::mat4 transform(toMat4(Rotation()));
+       const glm::vec3 translation = glm::vec3((chunk - chunk_offset) * Chunk::Extent()) + Position();
+       glm::mat4 transform(toMat4(Orientation()));
        transform[3].x = translation.x;
        transform[3].y = translation.y;
        transform[3].z = translation.z;