diff --git a/entity.cc b/entity.cc index 4f68a6d..20a92d8 100644 --- a/entity.cc +++ b/entity.cc @@ -1,6 +1,11 @@ #include "entity.hh" Entity::Entity(glm::vec3 position, glm::vec3 rotation) { + this->position = position; + setRotation(rotation); +} + +Entity::Entity(glm::vec3 position, glm::mat4 rotation) { this->position = position; this->rotation = rotation; } @@ -15,7 +20,7 @@ glm::vec3 Entity::getPosition() { return position; } -glm::vec3 Entity::getRotation() { +glm::mat4 Entity::getRotation() { return rotation; } @@ -24,5 +29,11 @@ void Entity::setPosition(glm::vec3 position) { } void Entity::setRotation(glm::vec3 rotation) { + this->rotation = glm::rotate(rotation.x, glm::vec3(1.0f, 0.0f, 0.0f)) + * glm::rotate(rotation.y, glm::vec3(0.0f, 1.0f, 0.0f)) + * glm::rotate(rotation.z, glm::vec3(0.0f, 0.0f, 1.0f)); +} + +void Entity::setRotation(glm::mat4 rotation) { this->rotation = rotation; } diff --git a/entity.hh b/entity.hh index 959cf5d..c712644 100644 --- a/entity.hh +++ b/entity.hh @@ -6,15 +6,17 @@ class Entity { public: Entity(glm::vec3 position, glm::vec3 rotation); + Entity(glm::vec3 position, glm::mat4 rotation); Entity(); ~Entity(); void setPosition(glm::vec3 positon); void setRotation(glm::vec3 rotation); + void setRotation(glm::mat4 rotation); glm::vec3 getPosition(); - glm::vec3 getRotation(); + glm::mat4 getRotation(); private: glm::vec3 position; - glm::vec3 rotation; + glm::mat4 rotation; }; #endif diff --git a/object.cc b/object.cc index a917b4f..7bd7580 100644 --- a/object.cc +++ b/object.cc @@ -24,9 +24,7 @@ void Object::render() { shader->setUniform("shininess", material.getShininess()); shader->setTexture("uTexture", material.getReference(), 0); // set model matrix - glm::mat4 rotationMatrix = glm::rotate(this->getRotation()[0], glm::vec3(1.0f, 0.0f, 0.0f)) * - glm::rotate(this->getRotation()[1], glm::vec3(0.0f, 1.0f, 0.0f)) * glm::rotate(this->getRotation()[2], glm::vec3(0.0f, 0.0f, 1.0f)); - glm::mat4 modelMatrix = glm::translate(this->getPosition()) * rotationMatrix * glm::scale(glm::vec3(model.getScale())); + glm::mat4 modelMatrix = glm::translate(getPosition()) * getRotation() * glm::scale(glm::vec3(model.getScale())); shader->setUniform( "modelMatrix", modelMatrix); // draw model.getReference()->render();