scale and move to center,

performance is not very good. Takes very long to load
This commit is contained in:
Anakin
2017-01-02 17:03:23 +01:00
parent fc7941a890
commit 191c0cbcea
4 changed files with 13 additions and 4 deletions

View File

@@ -1,5 +1,6 @@
#include "..\Header\GeometryEngine.h"
#include "..\Header\MshFile.h"
#include <cmath>
/////////////////////////////////////////////////////////////////////////
@@ -45,6 +46,7 @@ void GeometryEngine::loadFile(const char* filePath)
MshFile file(filePath);
models = file.getModels();
textureNames = file.getTextureNames();
m_boundings = file.getBoundingBox();
// collect data
unsigned int indexOffset(0);
@@ -76,8 +78,6 @@ void GeometryEngine::loadFile(const char* filePath)
}
}
//TODO: cleanup old stuff
// Transfer vertex data to VBO 0
m_arrayBuf.bind();
m_arrayBuf.allocate(vertexData.data(), vertexData.size() * sizeof(VertexData));
@@ -159,6 +159,13 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
m_arrayBuf.bind();
m_indexBuf.bind();
// Allways normalize by this
QMatrix4x4 normMatrix;
float maxExtent = std::max(std::max(m_boundings.extents[0], m_boundings.extents[1]), m_boundings.extents[2]);
normMatrix.scale(1 / maxExtent);
normMatrix.translate(-m_boundings.center[0], -m_boundings.center[1], -m_boundings.center[2]);
program->setUniformValue("norm_matrix", normMatrix);
// Allways use texture unit 0
program->setUniformValue("texture", 0);

View File

@@ -6,7 +6,7 @@
#include <math.h>
#include <iostream>
#define DEFAULT_Z_DISTANCE -5.0
#define DEFAULT_Z_DISTANCE -4.0
/////////////////////////////////////////////////////////////////////////