include all parent modelmatrices

This commit is contained in:
Anakin
2016-11-12 11:54:44 +01:00
parent 15743e11fa
commit 2524971d19
4 changed files with 19 additions and 7 deletions

View File

@@ -184,6 +184,22 @@ void OpenGLController::setCallbackFunctions()
glfwSetKeyCallback(pWindow, keyPress);
}
glm::mat4 OpenGLController::getModelMatrix(unsigned int index)
{
glm::mat4 tempParentMatrix = glm::mat4(1.0f);
for (unsigned int loop = 0; loop < vModels.size(); loop++)
{
if (!strcmp(vModels[index]->parent.c_str(), vModels[loop]->name.c_str()))
{
tempParentMatrix = getModelMatrix(loop);
break;
}
}
return tempParentMatrix * vModels[index]->m4x4Translation;
}
glm::mat4 OpenGLController::getMVPMatrix(unsigned int index)
{
// Projection
@@ -196,10 +212,6 @@ glm::mat4 OpenGLController::getMVPMatrix(unsigned int index)
glm::vec3(0, 1, 0)
);
// Model
//TODO for all
glm::mat4 m4x4Model = vModels[index]->m4x4Translation;
// User controlled rotation
glm::mat4 m4x4ModelRot = glm::mat4(1.0f);
m4x4ModelRot = glm::rotate(m4x4ModelRot, fRotationX, glm::vec3(1, 0, 0));
@@ -207,7 +219,7 @@ glm::mat4 OpenGLController::getMVPMatrix(unsigned int index)
m4x4ModelRot = glm::rotate(m4x4ModelRot, fRotationZ, glm::vec3(0, 0, 1));
// Return MVP
return m4x4Projection * m4x4View * m4x4ModelRot * m4x4Model;
return m4x4Projection * m4x4View * m4x4ModelRot * getModelMatrix(index);
}