2014-10-22 22:13:09 +00:00
|
|
|
#include "object.hh"
|
|
|
|
|
2014-11-27 23:17:56 +00:00
|
|
|
Object::Object(Model model, Material material, glm::vec3 position, glm::vec3 rotation) :
|
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;
|
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,
|
|
|
|
glm::mat4* viewProjectionMatrix, std::vector<glm::mat4>* shadowVPs) {
|
2014-12-15 10:45:31 +00:00
|
|
|
glm::mat4 modelMatrix = glm::translate(getPosition()) * getRotation() * glm::scale<float>(glm::vec3(model.getScale()));
|
2014-12-04 00:13:59 +00:00
|
|
|
if (lightingPass) {
|
2014-11-13 00:22:33 +00:00
|
|
|
// set lightning parameters for this object
|
2014-12-04 00:13:59 +00:00
|
|
|
shader->setUniform("ambientFactor", material.getAmbientFactor());
|
|
|
|
shader->setUniform("diffuseFactor", material.getDiffuseFactor());
|
|
|
|
shader->setUniform("specularFactor", material.getSpecularFactor());
|
|
|
|
shader->setUniform("shininess", material.getShininess());
|
|
|
|
shader->setTexture("uTexture", material.getReference(), 0);
|
2014-12-15 10:45:31 +00:00
|
|
|
// set model matrix
|
|
|
|
shader->setUniform( "modelMatrix", modelMatrix);
|
2014-12-15 11:41:30 +00:00
|
|
|
// set shadowMVPs
|
|
|
|
glm::mat4 shadowMVPs[35];
|
|
|
|
for(unsigned int i = 0; (i<shadowVPs->size() && i<35); i++) {
|
|
|
|
shadowMVPs[i] = shadowVPs->at(i) * modelMatrix;
|
|
|
|
}
|
|
|
|
glUniformMatrix4fv(shader->getUniformLocation("shadowMVPs"),
|
|
|
|
sizeof(shadowMVPs), false, (GLfloat*) shadowMVPs);
|
2014-12-04 00:13:59 +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
|
|
|
}
|