Changed how the rotation of objects is saved to better work with bullet together.

This commit is contained in:
Faerbit 2014-11-15 00:03:52 +01:00
parent 3916e58efc
commit 98270e919d
3 changed files with 17 additions and 6 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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<float>(this->getRotation()[0], glm::vec3(1.0f, 0.0f, 0.0f)) *
glm::rotate<float>(this->getRotation()[1], glm::vec3(0.0f, 1.0f, 0.0f)) * glm::rotate<float>(this->getRotation()[2], glm::vec3(0.0f, 0.0f, 1.0f));
glm::mat4 modelMatrix = glm::translate(this->getPosition()) * rotationMatrix * glm::scale<float>(glm::vec3(model.getScale()));
glm::mat4 modelMatrix = glm::translate(getPosition()) * getRotation() * glm::scale<float>(glm::vec3(model.getScale()));
shader->setUniform( "modelMatrix", modelMatrix);
// draw
model.getReference()->render();