text in FileInfoWindow can be marked and copied,
code cleaning
This commit is contained in:
@@ -2,20 +2,18 @@
|
||||
#include "..\Header\MshFile.h"
|
||||
#include "..\Header\OglViewerWidget.h"
|
||||
#include "..\Header\MainWindow.h"
|
||||
#include <cmath>
|
||||
#include <QRegExp>
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// public constructor/destructor
|
||||
// constructor/destructor
|
||||
|
||||
GeometryEngine::GeometryEngine(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_indexBuf(QOpenGLBuffer::IndexBuffer)
|
||||
, m_defaultMaterial(FileInterface::getDefaultMaterial())
|
||||
{
|
||||
initializeOpenGLFunctions();
|
||||
|
||||
m_defaultMaterial = FileInterface::getDefaultMaterial();
|
||||
}
|
||||
|
||||
GeometryEngine::~GeometryEngine()
|
||||
@@ -27,7 +25,7 @@ GeometryEngine::~GeometryEngine()
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// private functions
|
||||
// functions
|
||||
|
||||
void GeometryEngine::clearData()
|
||||
{
|
||||
@@ -52,9 +50,100 @@ void GeometryEngine::clearData()
|
||||
m_drawList.clear();
|
||||
}
|
||||
|
||||
void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program, bool wireframe)
|
||||
{
|
||||
if (!m_arrayBuf.isCreated() || !m_indexBuf.isCreated())
|
||||
return;
|
||||
|
||||
// Setup
|
||||
// Tell OpenGL which VBOs to use
|
||||
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);
|
||||
|
||||
// Offset for position
|
||||
quintptr offset = 0;
|
||||
|
||||
// Tell OpenGL programmable pipeline how to locate vertex position data
|
||||
int vertexLocation = program->attributeLocation("a_position");
|
||||
program->enableAttributeArray(vertexLocation);
|
||||
program->setAttributeBuffer(vertexLocation, GL_FLOAT, offset, 3, sizeof(VertexData));
|
||||
|
||||
// Offset for texture coordinate
|
||||
offset += sizeof(QVector3D);
|
||||
|
||||
// Tell OpenGL programmable pipeline how to locate vertex texture coordinate data
|
||||
int texcoordLocation = program->attributeLocation("a_texcoord");
|
||||
program->enableAttributeArray(texcoordLocation);
|
||||
program->setAttributeBuffer(texcoordLocation, GL_FLOAT, offset, 2, sizeof(VertexData));
|
||||
|
||||
//Offset for normal
|
||||
offset += sizeof(QVector2D);
|
||||
|
||||
// Tell OpenGL programmable pipeline how to locate vertex normal data
|
||||
int normLocation = program->attributeLocation("a_normal");
|
||||
program->enableAttributeArray(normLocation);
|
||||
program->setAttributeBuffer(normLocation, GL_FLOAT, offset, 3, sizeof(VertexData));
|
||||
|
||||
// Paint
|
||||
|
||||
for (auto& it : m_drawList)
|
||||
{
|
||||
bool tmp_transparent(false);
|
||||
bool tmp_specular(false);
|
||||
float shininess(0.0);
|
||||
QVector3D specularColor;
|
||||
|
||||
// bind the correct texture
|
||||
if (it.textureIndex < (unsigned)m_materials->size() && m_materials->at(it.textureIndex).texture0 != Q_NULLPTR)
|
||||
{
|
||||
m_materials->at(it.textureIndex).texture0->bind();
|
||||
tmp_transparent = m_materials->at(it.textureIndex).transparent;
|
||||
tmp_specular = m_materials->at(it.textureIndex).flags[7];
|
||||
shininess = m_materials->at(it.textureIndex).shininess;
|
||||
specularColor = m_materials->at(it.textureIndex).specularColor.toVector3D();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_defaultMaterial->texture0->bind();
|
||||
tmp_transparent = m_defaultMaterial->transparent;
|
||||
}
|
||||
// Set model matrix
|
||||
program->setUniformValue("m_matrix", it.modelMatrix);
|
||||
|
||||
// Set normal matrix
|
||||
program->setUniformValue("n_matrix", (normMatrix * it.modelMatrix).normalMatrix());
|
||||
|
||||
// set some more values
|
||||
program->setUniformValue("b_transparent", tmp_transparent);
|
||||
program->setUniformValue("b_specular", tmp_specular);
|
||||
|
||||
// set some material attributes
|
||||
program->setUniformValue("materialShininess", shininess);
|
||||
program->setUniformValue("materialSpecularColor", specularColor);
|
||||
|
||||
// Draw cube geometry using indices from VBO 1
|
||||
if (wireframe)
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, it.size, GL_UNSIGNED_INT, (void*)(it.offset * sizeof(GLuint)));
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////
|
||||
// public slots
|
||||
// slots
|
||||
|
||||
void GeometryEngine::loadFile(QString filePath)
|
||||
{
|
||||
@@ -134,94 +223,3 @@ void GeometryEngine::loadFile(QString filePath)
|
||||
}
|
||||
}
|
||||
|
||||
void GeometryEngine::drawGeometry(QOpenGLShaderProgram *program, bool wireframe)
|
||||
{
|
||||
if (!m_arrayBuf.isCreated() || !m_indexBuf.isCreated())
|
||||
return;
|
||||
|
||||
// Setup
|
||||
// Tell OpenGL which VBOs to use
|
||||
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);
|
||||
|
||||
// Offset for position
|
||||
quintptr offset = 0;
|
||||
|
||||
// Tell OpenGL programmable pipeline how to locate vertex position data
|
||||
int vertexLocation = program->attributeLocation("a_position");
|
||||
program->enableAttributeArray(vertexLocation);
|
||||
program->setAttributeBuffer(vertexLocation, GL_FLOAT, offset, 3, sizeof(VertexData));
|
||||
|
||||
// Offset for texture coordinate
|
||||
offset += sizeof(QVector3D);
|
||||
|
||||
// Tell OpenGL programmable pipeline how to locate vertex texture coordinate data
|
||||
int texcoordLocation = program->attributeLocation("a_texcoord");
|
||||
program->enableAttributeArray(texcoordLocation);
|
||||
program->setAttributeBuffer(texcoordLocation, GL_FLOAT, offset, 2, sizeof(VertexData));
|
||||
|
||||
//Offset for normal
|
||||
offset += sizeof(QVector2D);
|
||||
|
||||
// Tell OpenGL programmable pipeline how to locate vertex normal data
|
||||
int normLocation = program->attributeLocation("a_normal");
|
||||
program->enableAttributeArray(normLocation);
|
||||
program->setAttributeBuffer(normLocation, GL_FLOAT, offset, 3, sizeof(VertexData));
|
||||
|
||||
// Paint
|
||||
|
||||
for (auto& it : m_drawList)
|
||||
{
|
||||
bool tmp_transparent(false);
|
||||
bool tmp_specular(false);
|
||||
float shininess(0.0);
|
||||
QVector3D specularColor;
|
||||
|
||||
// bind the correct texture
|
||||
if (it.textureIndex < (unsigned) m_materials->size() && m_materials->at(it.textureIndex).texture0 != Q_NULLPTR)
|
||||
{
|
||||
m_materials->at(it.textureIndex).texture0->bind();
|
||||
tmp_transparent = m_materials->at(it.textureIndex).transparent;
|
||||
tmp_specular = m_materials->at(it.textureIndex).flags[7];
|
||||
shininess = m_materials->at(it.textureIndex).shininess;
|
||||
specularColor = m_materials->at(it.textureIndex).specularColor.toVector3D();
|
||||
}
|
||||
else
|
||||
{
|
||||
m_defaultMaterial->texture0->bind();
|
||||
tmp_transparent = m_defaultMaterial->transparent;
|
||||
}
|
||||
// Set model matrix
|
||||
program->setUniformValue("m_matrix", it.modelMatrix);
|
||||
|
||||
// Set normal matrix
|
||||
program->setUniformValue("n_matrix", (normMatrix * it.modelMatrix).normalMatrix());
|
||||
|
||||
// set some more values
|
||||
program->setUniformValue("b_transparent", tmp_transparent);
|
||||
program->setUniformValue("b_specular", tmp_specular);
|
||||
|
||||
// set some material attributes
|
||||
program->setUniformValue("materialShininess", shininess);
|
||||
program->setUniformValue("materialSpecularColor", specularColor);
|
||||
|
||||
// Draw cube geometry using indices from VBO 1
|
||||
if(wireframe)
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
|
||||
|
||||
glDrawElements(GL_TRIANGLES, it.size, GL_UNSIGNED_INT, (void*)(it.offset * sizeof(GLuint)));
|
||||
|
||||
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user