Commit 9a5d09b8 authored by Anakin's avatar Anakin

fixed crash

parent ee8705f9
......@@ -31,4 +31,6 @@ private:
void readVertex(Segment* dataDestination, std::streampos position);
void readUV(Segment* dataDestination, std::streampos position);
QMatrix4x4 getParentMatrix(std::string parent) const;
};
\ No newline at end of file
......@@ -26,7 +26,7 @@ GeometryEngine::~GeometryEngine()
for (auto it : m_textures)
delete it;
m_textures.clear();
m_textures.squeeze();
m_drawList.clear();
}
......@@ -41,17 +41,10 @@ void GeometryEngine::initCubeGeometry()
try
{
MshFile file("..\\Release\\Msh\\sphere.msh");
MshFile file("..\\Release\\Msh\\triClothMan.msh");
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
}
catch (std::invalid_argument e)
{
//TODO: make a cool message box
auto msg = e.what();
}
// collect data
unsigned int offsetCount(0);
......@@ -82,7 +75,7 @@ void GeometryEngine::initCubeGeometry()
// Transfer vertex data to VBO 0
m_arrayBuf.bind();
m_arrayBuf.allocate(vertexData.data(),vertexData.size() * sizeof(VertexData));
m_arrayBuf.allocate(vertexData.data(), vertexData.size() * sizeof(VertexData));
// Transfer index data to VBO 1
m_indexBuf.bind();
......@@ -90,6 +83,15 @@ void GeometryEngine::initCubeGeometry()
// load the texture
initTexture();
}
catch (std::invalid_argument e)
{
//TODO: make a cool message box
auto msg = e.what();
}
}
void GeometryEngine::initTexture()
......@@ -146,9 +148,9 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
{
// bind the correct texture
if (it.textureIndex < m_textures.size())
m_textures.last()->bind();
else
m_textures.at(it.textureIndex)->bind();
else
m_textures.last()->bind();
// Set model matrix
program->setUniformValue("m_matrix", it.modelMatrix);
......
......@@ -17,6 +17,7 @@ MshFile::MshFile(const char * path)
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.translate(tmp_trans[0], tmp_trans[1], tmp_trans[2]);
dataDestination->m4x4Translation = getParentMatrix(dataDestination->parent) * dataDestination->m4x4Translation;
}
// 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));
}
}
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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment