Changed how the rotation of objects is saved to better work with bullet together.
This commit is contained in:
parent
3916e58efc
commit
98270e919d
13
entity.cc
13
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;
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user