diff --git a/MshViewer/Header/OpenGLController.h b/MshViewer/Header/OpenGLController.h index abd804b..a831426 100644 --- a/MshViewer/Header/OpenGLController.h +++ b/MshViewer/Header/OpenGLController.h @@ -62,10 +62,6 @@ private: double dTranslationY; double dTranslationZ; - //matrices - glm::mat4 m4x4Model; - glm::mat4 m4x4View; - glm::mat4 m4x4Projection; // ============================== // camera diff --git a/MshViewer/Source/Object.cpp b/MshViewer/Source/Object.cpp index 8bcb685..1473f6d 100644 --- a/MshViewer/Source/Object.cpp +++ b/MshViewer/Source/Object.cpp @@ -1,5 +1,6 @@ #include "Object.h" #include +#define PI (4.0*atan(1.0)) ///////////////////////////////////////////////////////////////////////// @@ -276,12 +277,18 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list& c fsMesh.read(reinterpret_cast(&tempScale[1]), sizeof(float)); fsMesh.read(reinterpret_cast(&tempScale[2]), sizeof(float)); - //TODO: rotation value is wrong fsMesh.read(reinterpret_cast(&tempRotation[0]), sizeof(float)); fsMesh.read(reinterpret_cast(&tempRotation[1]), sizeof(float)); fsMesh.read(reinterpret_cast(&tempRotation[2]), sizeof(float)); fsMesh.read(reinterpret_cast(&tempRotation[3]), sizeof(float)); + //calculate x,y,z rotation + tempRotation[0] = atan2(2 * (tempRotation[0] * tempRotation[1] + tempRotation[2] * tempRotation[3]), + 1 - 2 * (pow(tempRotation[1], 2) + pow(tempRotation[2], 2))); + tempRotation[1] = asin(2 * (tempRotation[0] * tempRotation[2] - tempRotation[3] * tempRotation[1])); + tempRotation[2] = atan2(2 * (tempRotation[0] * tempRotation[3] + tempRotation[1] * tempRotation[2]), + 1 - 2 * (pow(tempRotation[2], 2) + pow(tempRotation[3], 2))) - PI; + fsMesh.read(reinterpret_cast(&tempTrans[0]), sizeof(float)); fsMesh.read(reinterpret_cast(&tempTrans[1]), sizeof(float)); fsMesh.read(reinterpret_cast(&tempTrans[2]), sizeof(float)); diff --git a/MshViewer/Source/OpenGlController.cpp b/MshViewer/Source/OpenGlController.cpp index b7edda7..d7633f4 100644 --- a/MshViewer/Source/OpenGlController.cpp +++ b/MshViewer/Source/OpenGlController.cpp @@ -74,10 +74,6 @@ void OpenGLController::initDefault() dTranslationY = 0; dTranslationZ = 5; - m4x4Model = glm::mat4(1.0f); - m4x4View = glm::mat4(1.0f); - m4x4Projection = glm::mat4(1.f); - fFOV = 45.0f; fMinView = 0.1f; fMaxView = 100.0f; @@ -160,21 +156,28 @@ void OpenGLController::setCallbackFunctions() glm::mat4 OpenGLController::getMVPMatrix() { - m4x4Projection = glm::perspective(fFOV, float(iWidth) / float(iHeight), fMinView, fMaxView); - m4x4View = glm::lookAt( + // Projection + glm::mat4 m4x4Projection = glm::perspective(fFOV, float(iWidth) / float(iHeight), fMinView, fMaxView); + + // View + glm::mat4 m4x4View = glm::lookAt( glm::vec3(dTranslationX, dTranslationY, dTranslationZ), glm::vec3(dTranslationX, dTranslationY, dTranslationZ - 1), glm::vec3(0, 1, 0) ); - //m4x4Model = glm::mat4(1.0f); + // Model //TODO for all - m4x4Model = vModels.front()->m4x4Translation; - m4x4Model = glm::rotate(m4x4Model, fRotationX, glm::vec3(1, 0, 0)); - m4x4Model = glm::rotate(m4x4Model, fRotationY, glm::vec3(0, 1, 0)); - m4x4Model = glm::rotate(m4x4Model, fRotationZ, glm::vec3(0, 0, 1)); + glm::mat4 m4x4Model = vModels.front()->m4x4Translation; + + // User controlled rotation + glm::mat4 m4x4ModelRot = glm::mat4(1.0f); + m4x4ModelRot = glm::rotate(m4x4ModelRot, fRotationX, glm::vec3(1, 0, 0)); + m4x4ModelRot = glm::rotate(m4x4ModelRot, fRotationY, glm::vec3(0, 1, 0)); + m4x4ModelRot = glm::rotate(m4x4ModelRot, fRotationZ, glm::vec3(0, 0, 1)); - return m4x4Projection * m4x4View * m4x4Model; + // Return MVP + return m4x4Projection * m4x4View * m4x4ModelRot * m4x4Model; } diff --git a/README.md b/README.md index dce0f7c..20e30cf 100644 --- a/README.md +++ b/README.md @@ -13,6 +13,8 @@ Feel free to use my code the way you like. But remember i used some public libra licence, too. ### To Do +- draw multiple models of one mesh, +- crashing sometimes - no idea why, - bones are not triangulated, - nulls are not triangulated, - crash when loading trooper, diff --git a/Release/Msh/cubeTrans.msh b/Release/Msh/cubeTrans.msh new file mode 100644 index 0000000..01a4997 Binary files /dev/null and b/Release/Msh/cubeTrans.msh differ