scale and move to center,
performance is not very good. Takes very long to load
This commit is contained in:
parent
fc7941a890
commit
191c0cbcea
@ -27,6 +27,7 @@ private:
|
||||
QOpenGLBuffer m_indexBuf;
|
||||
QVector<QOpenGLTexture*> m_textures;
|
||||
QVector<DrawInformation> m_drawList;
|
||||
BoundingBox m_boundings;
|
||||
|
||||
void loadTexture(const char* filePath);
|
||||
void clearData();
|
||||
|
@ -5,6 +5,7 @@ precision mediump float;
|
||||
#endif
|
||||
|
||||
uniform mat4 vp_matrix;
|
||||
uniform mat4 norm_matrix;
|
||||
uniform mat4 m_matrix;
|
||||
|
||||
attribute vec4 a_position;
|
||||
@ -15,7 +16,7 @@ varying vec2 v_texcoord;
|
||||
void main()
|
||||
{
|
||||
// Calculate vertex position in screen space
|
||||
gl_Position = vp_matrix * m_matrix * a_position;
|
||||
gl_Position = vp_matrix * norm_matrix * m_matrix * a_position;
|
||||
|
||||
// Pass texture coordinate to fragment shader
|
||||
// Value will be automatically interpolated to fragments inside polygon faces
|
||||
|
@ -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);
|
||||
|
||||
|
@ -6,7 +6,7 @@
|
||||
#include <math.h>
|
||||
#include <iostream>
|
||||
|
||||
#define DEFAULT_Z_DISTANCE -5.0
|
||||
#define DEFAULT_Z_DISTANCE -4.0
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
|
Loading…
Reference in New Issue
Block a user