From ea07ead94feb66fb5544f0530f7f775793e62868 Mon Sep 17 00:00:00 2001 From: Anakin Date: Mon, 31 Oct 2016 10:46:41 +0100 Subject: [PATCH] added new test mesh that is rotated, translation from model is now applied, still need to draw all modl from one mesh --- MshViewer/Header/OpenGLController.h | 4 ---- MshViewer/Source/Object.cpp | 9 ++++++++- MshViewer/Source/OpenGlController.cpp | 27 ++++++++++++++------------ README.md | 2 ++ Release/Msh/cubeTrans.msh | Bin 0 -> 1376 bytes 5 files changed, 25 insertions(+), 17 deletions(-) create mode 100644 Release/Msh/cubeTrans.msh 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 0000000000000000000000000000000000000000..01a499768a63eb74c438f0a3804ef65a00155a10 GIT binary patch literal 1376 zcmb_bO=}ZT6umKNZ8h4etsl5`;X+E<=r(y1XOa}=O~TA5QK%a0Pzt3=m||D*z?~b{ zb?raUtr&1CxO5?c;15vn4|wiNue>Q$5PfjwoOADe_uYBSbOS#gOcCj%yV3L*9i+kTqlcqB<6JxTbQN3z*b{yCTCLvTiq-DJG+pRkob>-DC9hT@kaNB)4BXXBY>!0S8rvt@8Q>?EAymBwCl z*(!GyqQ!6T8XUg!bgOU&ouH?`l!^ZKzCONMQ%TU#FR>SQwJPWLdr4TskQeL>GzJM2 zG-K>AYZq$Y3v=|kwqFolP=+AX-Ui27y1QHYG_(9Dv7o2xJYvq7FLpiWMinV)h zNb@ppC;U78uX)?o`5xT=!`1)0?y$KfCR{kvzyXDstiN%y7QRQ4zqcn}A2&aJSZaKJ zz1>`UmRM$w6xKa{PiW~Od}thXHjXWYI`NWs`XTk}|DR}{hv$&F5Oww)JeU3CtR#*5 zA&M{AHYIa}%BEtbXxbb#Gc;?Cnd4M7C(KEjGxO#Yoi-(Nh89p$rbX0D(^=Ha(mB*r O={#!Y=z6%!E$Jtzp2_0? literal 0 HcmV?d00001