Saxum/game/object.cc

49 lines
1.5 KiB
C++
Raw Normal View History

2014-10-22 22:13:09 +00:00
#include "object.hh"
Object::Object(Model model, Material material, glm::vec3 position, glm::vec3 rotation, bool renderable) :
Entity(position, rotation) {
this->model = model;
this->material = material;
this->renderable = renderable;
2014-10-22 22:13:09 +00:00
}
Object::Object() {
}
2014-10-22 22:13:09 +00:00
Object::~Object() {
}
void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
glm::mat4* viewProjectionMatrix,
2015-03-04 15:08:03 +00:00
std::vector<glm::mat4>* additionalMatrices) {
if (!renderable) {
return;
}
glm::mat4 modelMatrix = glm::translate(getPosition()) * getRotation() * glm::scale<float>(glm::vec3(model.getScale()));
shader->setUniform("modelMatrix", modelMatrix);
if (lightingPass) {
// set model matrix
shader->setUniform("modelMatrix", modelMatrix);
// set shadowMVPs
glm::mat4 shadowMVPs[5];
2015-02-04 21:54:40 +00:00
for(unsigned int i = 0; (i<additionalMatrices->size() && i<5); i++) {
shadowMVPs[i] = additionalMatrices->at(i) * modelMatrix;
}
glUniformMatrix4fv(shader->getUniformLocation("shadowMVPs"),
sizeof(shadowMVPs), false, (GLfloat*) shadowMVPs);
}
else {
2015-02-04 21:54:40 +00:00
if (additionalMatrices) {
shader->setUniform("modelViewMatrix", additionalMatrices->at(0) * modelMatrix);
}
}
glm::mat4 mvp = (*viewProjectionMatrix) * modelMatrix;
shader->setUniform("modelViewProjectionMatrix", mvp);
// draw
model.getReference()->render();
2014-10-22 22:13:09 +00:00
}
Material* Object::getMaterial() {
return &material;
}