2014-10-22 22:13:09 +00:00
|
|
|
#include "object.hh"
|
|
|
|
|
2015-02-07 18:09:49 +00:00
|
|
|
Object::Object(Model model, Material material, glm::vec3 position, glm::vec3 rotation, bool renderable) :
|
2014-10-22 22:53:00 +00:00
|
|
|
Entity(position, rotation) {
|
2014-11-13 00:22:33 +00:00
|
|
|
this->model = model;
|
2014-11-08 00:17:23 +00:00
|
|
|
this->material = material;
|
2015-02-07 18:09:49 +00:00
|
|
|
this->renderable = renderable;
|
2014-10-22 22:13:09 +00:00
|
|
|
}
|
|
|
|
|
2014-10-24 08:48:45 +00:00
|
|
|
Object::Object() {
|
|
|
|
}
|
|
|
|
|
2014-10-22 22:13:09 +00:00
|
|
|
Object::~Object() {
|
|
|
|
}
|
|
|
|
|
2014-12-15 11:41:30 +00:00
|
|
|
void Object::render(ACGL::OpenGL::SharedShaderProgram shader, bool lightingPass,
|
2015-04-12 19:06:59 +00:00
|
|
|
glm::mat4* viewProjectionMatrix,
|
2015-03-04 15:08:03 +00:00
|
|
|
std::vector<glm::mat4>* additionalMatrices) {
|
2015-02-07 18:09:49 +00:00
|
|
|
if (!renderable) {
|
|
|
|
return;
|
|
|
|
}
|
2014-12-15 10:45:31 +00:00
|
|
|
glm::mat4 modelMatrix = glm::translate(getPosition()) * getRotation() * glm::scale<float>(glm::vec3(model.getScale()));
|
2015-04-12 19:06:59 +00:00
|
|
|
shader->setUniform("modelMatrix", modelMatrix);
|
2014-12-04 00:13:59 +00:00
|
|
|
if (lightingPass) {
|
2014-12-15 10:45:31 +00:00
|
|
|
// set model matrix
|
2015-01-31 19:02:23 +00:00
|
|
|
shader->setUniform("modelMatrix", modelMatrix);
|
2014-12-15 11:41:30 +00:00
|
|
|
// set shadowMVPs
|
2014-12-15 12:16:27 +00:00
|
|
|
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;
|
2014-12-15 11:41:30 +00:00
|
|
|
}
|
|
|
|
glUniformMatrix4fv(shader->getUniformLocation("shadowMVPs"),
|
|
|
|
sizeof(shadowMVPs), false, (GLfloat*) shadowMVPs);
|
2014-12-04 00:13:59 +00:00
|
|
|
}
|
2015-01-31 19:02:23 +00:00
|
|
|
else {
|
2015-02-04 21:54:40 +00:00
|
|
|
if (additionalMatrices) {
|
|
|
|
shader->setUniform("modelViewMatrix", additionalMatrices->at(0) * modelMatrix);
|
2015-02-02 18:58:16 +00:00
|
|
|
}
|
2015-01-31 19:02:23 +00:00
|
|
|
}
|
2014-12-15 11:41:30 +00:00
|
|
|
glm::mat4 mvp = (*viewProjectionMatrix) * modelMatrix;
|
2014-12-15 10:45:31 +00:00
|
|
|
shader->setUniform("modelViewProjectionMatrix", mvp);
|
2014-11-13 00:22:33 +00:00
|
|
|
// draw
|
|
|
|
model.getReference()->render();
|
2014-10-22 22:13:09 +00:00
|
|
|
}
|
2015-03-20 22:45:28 +00:00
|
|
|
|
|
|
|
Material* Object::getMaterial() {
|
|
|
|
return &material;
|
|
|
|
}
|