added new test mesh that is rotated,

translation from model is now applied,
still need to draw all modl from one mesh
This commit is contained in:
Anakin 2016-10-31 10:46:41 +01:00
parent e509b1e11c
commit ea07ead94f
5 changed files with 25 additions and 17 deletions

View File

@ -62,10 +62,6 @@ private:
double dTranslationY;
double dTranslationZ;
//matrices
glm::mat4 m4x4Model;
glm::mat4 m4x4View;
glm::mat4 m4x4Projection;
// ==============================
// camera

View File

@ -1,5 +1,6 @@
#include "Object.h"
#include <iostream>
#define PI (4.0*atan(1.0))
/////////////////////////////////////////////////////////////////////////
@ -276,12 +277,18 @@ void Object::analyseModlChunks(Modl* dataDestination, std::list<ChunkHeader*>& c
fsMesh.read(reinterpret_cast<char*>(&tempScale[1]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempScale[2]), sizeof(float));
//TODO: rotation value is wrong
fsMesh.read(reinterpret_cast<char*>(&tempRotation[0]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempRotation[1]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempRotation[2]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&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<char*>(&tempTrans[0]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempTrans[1]), sizeof(float));
fsMesh.read(reinterpret_cast<char*>(&tempTrans[2]), sizeof(float));

View File

@ -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;
}

View File

@ -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,

BIN
Release/Msh/cubeTrans.msh Normal file

Binary file not shown.