fixed crash

This commit is contained in:
Anakin 2016-12-31 13:04:03 +01:00
parent ee8705f9e4
commit 9a5d09b80c
3 changed files with 68 additions and 44 deletions

View File

@ -31,4 +31,6 @@ private:
void readVertex(Segment* dataDestination, std::streampos position); void readVertex(Segment* dataDestination, std::streampos position);
void readUV(Segment* dataDestination, std::streampos position); void readUV(Segment* dataDestination, std::streampos position);
QMatrix4x4 getParentMatrix(std::string parent) const;
}; };

View File

@ -26,7 +26,7 @@ GeometryEngine::~GeometryEngine()
for (auto it : m_textures) for (auto it : m_textures)
delete it; delete it;
m_textures.clear(); m_textures.clear();
m_textures.squeeze(); m_drawList.clear();
} }
@ -41,17 +41,10 @@ void GeometryEngine::initCubeGeometry()
try try
{ {
MshFile file("..\\Release\\Msh\\sphere.msh"); MshFile file("..\\Release\\Msh\\triClothMan.msh");
models = file.getModels(); models = file.getModels();
//TODO use models local, apply MVP directly to the vertex, save size and tex index info //TODO normalize
//TODO: handle the textures //TODO: handle the textures
}
catch (std::invalid_argument e)
{
//TODO: make a cool message box
auto msg = e.what();
}
// collect data // collect data
unsigned int offsetCount(0); unsigned int offsetCount(0);
@ -90,6 +83,15 @@ void GeometryEngine::initCubeGeometry()
// load the texture // load the texture
initTexture(); initTexture();
}
catch (std::invalid_argument e)
{
//TODO: make a cool message box
auto msg = e.what();
}
} }
void GeometryEngine::initTexture() void GeometryEngine::initTexture()
@ -146,9 +148,9 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
{ {
// bind the correct texture // bind the correct texture
if (it.textureIndex < m_textures.size()) if (it.textureIndex < m_textures.size())
m_textures.last()->bind();
else
m_textures.at(it.textureIndex)->bind(); m_textures.at(it.textureIndex)->bind();
else
m_textures.last()->bind();
// Set model matrix // Set model matrix
program->setUniformValue("m_matrix", it.modelMatrix); program->setUniformValue("m_matrix", it.modelMatrix);

View File

@ -17,6 +17,7 @@ MshFile::MshFile(const char * path)
MshFile::~MshFile() MshFile::~MshFile()
{ {
//TODO: clean up
} }
@ -294,6 +295,8 @@ void MshFile::analyseModlChunks(Model * dataDestination, std::list<ChunkHeader*>
dataDestination->m4x4Translation.rotate(QQuaternion(tmp_rotation[3], tmp_rotation[0], tmp_rotation[1], tmp_rotation[2])); dataDestination->m4x4Translation.rotate(QQuaternion(tmp_rotation[3], tmp_rotation[0], tmp_rotation[1], tmp_rotation[2]));
dataDestination->m4x4Translation.translate(tmp_trans[0], tmp_trans[1], tmp_trans[2]); dataDestination->m4x4Translation.translate(tmp_trans[0], tmp_trans[1], tmp_trans[2]);
dataDestination->m4x4Translation = getParentMatrix(dataDestination->parent) * dataDestination->m4x4Translation;
} }
// geometry data // geometry data
@ -605,3 +608,20 @@ void MshFile::readUV(Segment * dataDestination, std::streampos position)
m_file.read(F2V(dataDestination->vertices[i].texCoord[j]), sizeof(float)); m_file.read(F2V(dataDestination->vertices[i].texCoord[j]), sizeof(float));
} }
} }
QMatrix4x4 MshFile::getParentMatrix(std::string parent) const
{
QMatrix4x4 matrix;
for (auto& it : *m_models)
{
if (!strcmp(parent.c_str(), it->name.c_str()))
{
//TODO: the other way around??
matrix = getParentMatrix(it->parent) * it->m4x4Translation;
break;
}
}
return matrix;
}