Skip to content
Snippets Groups Projects
Commit 191c0cbc authored by Anakin's avatar Anakin
Browse files

scale and move to center,

performance is not very good. Takes very long to load
parent fc7941a8
Branches
Tags
No related merge requests found
...@@ -27,6 +27,7 @@ private: ...@@ -27,6 +27,7 @@ private:
QOpenGLBuffer m_indexBuf; QOpenGLBuffer m_indexBuf;
QVector<QOpenGLTexture*> m_textures; QVector<QOpenGLTexture*> m_textures;
QVector<DrawInformation> m_drawList; QVector<DrawInformation> m_drawList;
BoundingBox m_boundings;
void loadTexture(const char* filePath); void loadTexture(const char* filePath);
void clearData(); void clearData();
......
...@@ -5,6 +5,7 @@ precision mediump float; ...@@ -5,6 +5,7 @@ precision mediump float;
#endif #endif
uniform mat4 vp_matrix; uniform mat4 vp_matrix;
uniform mat4 norm_matrix;
uniform mat4 m_matrix; uniform mat4 m_matrix;
attribute vec4 a_position; attribute vec4 a_position;
...@@ -15,7 +16,7 @@ varying vec2 v_texcoord; ...@@ -15,7 +16,7 @@ varying vec2 v_texcoord;
void main() void main()
{ {
// Calculate vertex position in screen space // 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 // Pass texture coordinate to fragment shader
// Value will be automatically interpolated to fragments inside polygon faces // Value will be automatically interpolated to fragments inside polygon faces
......
#include "..\Header\GeometryEngine.h" #include "..\Header\GeometryEngine.h"
#include "..\Header\MshFile.h" #include "..\Header\MshFile.h"
#include <cmath>
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
...@@ -45,6 +46,7 @@ void GeometryEngine::loadFile(const char* filePath) ...@@ -45,6 +46,7 @@ void GeometryEngine::loadFile(const char* filePath)
MshFile file(filePath); MshFile file(filePath);
models = file.getModels(); models = file.getModels();
textureNames = file.getTextureNames(); textureNames = file.getTextureNames();
m_boundings = file.getBoundingBox();
// collect data // collect data
unsigned int indexOffset(0); unsigned int indexOffset(0);
...@@ -76,8 +78,6 @@ void GeometryEngine::loadFile(const char* filePath) ...@@ -76,8 +78,6 @@ void GeometryEngine::loadFile(const char* filePath)
} }
} }
//TODO: cleanup old stuff
// Transfer vertex data to VBO 0 // Transfer vertex data to VBO 0
m_arrayBuf.bind(); m_arrayBuf.bind();
m_arrayBuf.allocate(vertexData.data(), vertexData.size() * sizeof(VertexData)); m_arrayBuf.allocate(vertexData.data(), vertexData.size() * sizeof(VertexData));
...@@ -159,6 +159,13 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program) ...@@ -159,6 +159,13 @@ void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program)
m_arrayBuf.bind(); m_arrayBuf.bind();
m_indexBuf.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 // Allways use texture unit 0
program->setUniformValue("texture", 0); program->setUniformValue("texture", 0);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include <math.h> #include <math.h>
#include <iostream> #include <iostream>
#define DEFAULT_Z_DISTANCE -5.0 #define DEFAULT_Z_DISTANCE -4.0
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment