From c28a12cd8f0d4269e7a39d34411aced42cc6c1c3 Mon Sep 17 00:00:00 2001 From: Anakin Date: Tue, 3 Jan 2017 14:18:46 +0100 Subject: [PATCH] finally fixed rotation bug, some performance, --- QtMeshViewer/Header/MshFile.h | 1 + QtMeshViewer/Source/GeometryEngine.cpp | 9 ++++---- QtMeshViewer/Source/MshFile.cpp | 30 +++++++++++++++++-------- QtMeshViewer/main.cpp | 2 ++ Release/Msh/rotTest.msh | Bin 0 -> 3068 bytes 5 files changed, 28 insertions(+), 14 deletions(-) create mode 100644 Release/Msh/rotTest.msh diff --git a/QtMeshViewer/Header/MshFile.h b/QtMeshViewer/Header/MshFile.h index b242340..7dc1744 100644 --- a/QtMeshViewer/Header/MshFile.h +++ b/QtMeshViewer/Header/MshFile.h @@ -44,4 +44,5 @@ private: void readUV(Segment* dataDestination, std::streampos position); QMatrix4x4 getParentMatrix(std::string parent) const; + QQuaternion getParentRotation(std::string parent) const; }; \ No newline at end of file diff --git a/QtMeshViewer/Source/GeometryEngine.cpp b/QtMeshViewer/Source/GeometryEngine.cpp index 714d534..9813904 100644 --- a/QtMeshViewer/Source/GeometryEngine.cpp +++ b/QtMeshViewer/Source/GeometryEngine.cpp @@ -10,8 +10,6 @@ GeometryEngine::GeometryEngine() : m_indexBuf(QOpenGLBuffer::IndexBuffer) { initializeOpenGLFunctions(); - - loadFile("..\\Release\\Msh\\cubeTex.msh"); } GeometryEngine::~GeometryEngine() @@ -63,9 +61,10 @@ void GeometryEngine::loadFile(const char* filePath) new_info.modelMatrix = modelIterator->m4x4Translation; new_info.modelMatrix.rotate(modelIterator->quadRotation); - // add offset to indices - for (auto& it : segmentIterator->indices) - it += vertexOffset; + // add offset to indices, no need to do it for the first one (maybe it's very big) + if(vertexOffset != 0) + for (auto& it : segmentIterator->indices) + it += vertexOffset; // save data vertexData += segmentIterator->vertices; diff --git a/QtMeshViewer/Source/MshFile.cpp b/QtMeshViewer/Source/MshFile.cpp index 290aad9..49c41d9 100644 --- a/QtMeshViewer/Source/MshFile.cpp +++ b/QtMeshViewer/Source/MshFile.cpp @@ -291,14 +291,14 @@ void MshFile::analyseModlChunks(Model * dataDestination, std::list for (int i = 0; i < 3; i++) m_file.read(F2V(tmp_trans[i]), sizeof(float)); - // modify the matrix + // modify the matrix and quaternion dataDestination->m4x4Translation.scale(tmp_scale[0], tmp_scale[1], tmp_scale[2]); dataDestination->m4x4Translation.translate(tmp_trans[0], tmp_trans[1], tmp_trans[2]); dataDestination->quadRotation.setVector(QVector3D(tmp_rotation[0], tmp_rotation[1], tmp_rotation[2])); dataDestination->quadRotation.setScalar(tmp_rotation[3]); dataDestination->m4x4Translation = getParentMatrix(dataDestination->parent) * dataDestination->m4x4Translation; - + dataDestination->quadRotation = getParentRotation(dataDestination->parent) * dataDestination->quadRotation; } // geometry data @@ -406,10 +406,7 @@ void MshFile::analyseSegmChunks(Model * dataDestination, std::list else if (!strcmp("STRP", it->name)) { // don't get null, bone, shadowMesh and hidden mesh indices - if (m_currentType == null || - m_currentType == bone || - m_currentType == shadowMesh || - m_currentRenderFlag == 1) + if (m_currentType == null || m_currentType == bone || m_currentType == shadowMesh || m_currentRenderFlag == 1) continue; // jump to the data section and read the size; @@ -455,7 +452,7 @@ void MshFile::analyseSegmChunks(Model * dataDestination, std::list for (unsigned int tri = 0; tri < tmp_multiPolySize - 2; tri++) // ..calculate the edge indices for (int triEdge = 0; triEdge < 3; triEdge++) - new_segment->indices.push_back((GLuint)tmp_buffer[(tri + triEdge - ((tri % 2) * (triEdge - 1) * 2))]); + new_segment->indices.push_back(tmp_buffer[(tri + triEdge - ((tri % 2) * (triEdge - 1) * 2))]); } } // if 2 high bits are set @@ -475,7 +472,7 @@ void MshFile::analyseSegmChunks(Model * dataDestination, std::list for (unsigned int tri = 0; tri < tmp_multiPolySize - 2; tri++) // ..calculate the edge indices for (int triEdge = 0; triEdge < 3; triEdge++) - new_segment->indices.push_back((GLuint)tmp_buffer[(tri + triEdge - ((tri % 2) * (triEdge - 1) * 2))]); + new_segment->indices.push_back(tmp_buffer[(tri + triEdge - ((tri % 2) * (triEdge - 1) * 2))]); } } } @@ -610,7 +607,6 @@ QMatrix4x4 MshFile::getParentMatrix(std::string parent) const { if (!strcmp(parent.c_str(), it->name.c_str())) { - //TODO: the other way around?? matrix = getParentMatrix(it->parent) * it->m4x4Translation; break; } @@ -618,3 +614,19 @@ QMatrix4x4 MshFile::getParentMatrix(std::string parent) const return matrix; } + +QQuaternion MshFile::getParentRotation(std::string parent) const +{ + QQuaternion rotation; + + for (auto& it : *m_models) + { + if (!strcmp(parent.c_str(), it->name.c_str())) + { + rotation = getParentRotation(it->parent) * it->quadRotation; + break; + } + } + + return rotation; +} diff --git a/QtMeshViewer/main.cpp b/QtMeshViewer/main.cpp index 5621a59..6eb27ba 100644 --- a/QtMeshViewer/main.cpp +++ b/QtMeshViewer/main.cpp @@ -1,11 +1,13 @@ #include "Header\MainWindow.h" #include + int main(int argc, char *argv[]) { QApplication a(argc, argv); MainWindow w; w.show(); + return a.exec(); } diff --git a/Release/Msh/rotTest.msh b/Release/Msh/rotTest.msh new file mode 100644 index 0000000000000000000000000000000000000000..b946224eafc7e69557cafa6970371c0a48fe0832 GIT binary patch literal 3068 zcmeHIOHUJF6uqrQi>MT+Qh63E#55)bDqCizwmeLyH0_x9SO|e8ny3(hiSF*wjXwYr z6BoLHHA_1#{3-kZ6a4|6GmkQg5+!lhN$%V;_dDOY_j~kqsa&dm?-8*ZOS6aYjpgdX zhKN)xyPSq^tT&%GA3Z2L<(FHV+dEB;Ez~Xh0(=a{Z;`K7vAA;YhKHjsHTL)Nu84m0 zy_moT81SZPTTbOEKBxm+T7_rc6uh6;UfXGIKUo8*WI5I?#0!Oj5t^?>y(4?OyE`A6 zA73h3PQ94GTt4Ec+XeXPG= za=iMX(_TCET|d_x^&^-Zul`oGZnw|T+eVy+@A*C*zWwl}3*%jo#=D!Y1q^REz{LQ= zdzc*mQDgPa-9mu>sRrhP8JtUfn1_E?KkEqVAtoPn{gF@Ia4pm&->;GHVT#sEh$Z7>@uQpFfMDqT#*4C)U;$I ztr?76MKlh^RlOoZGN{9vkrB!02*yScje{|&Loz1AI<6ytfO?4{A(`nP?YzeyUm zG<^P{k8+BM!@ztsI(?M?51l@WyAb@gc|A_X=nI`bir&`gqyMLm-mc74cng03enAT| literal 0 HcmV?d00001