diff --git a/QtMeshViewer/Form Files/SettingsWindow.ui b/QtMeshViewer/Form Files/SettingsWindow.ui
new file mode 100644
index 0000000..6a0973f
--- /dev/null
+++ b/QtMeshViewer/Form Files/SettingsWindow.ui
@@ -0,0 +1,479 @@
+
+
+ SettingsWindow
+
+
+
+ 0
+ 0
+ 400
+ 300
+
+
+
+ Settings
+
+
+ -
+
+
+ Background
+
+
+
-
+
+
+ false
+
+
+
+ 30
+ 16777215
+
+
+
+ 5
+
+
+
+ -
+
+
+ B:
+
+
+
+ -
+
+
+ false
+
+
+ 255
+
+
+ 5
+
+
+ Qt::Horizontal
+
+
+
+ -
+
+
+ false
+
+
+ 255
+
+
+ 5
+
+
+ Qt::Horizontal
+
+
+
+ -
+
+
+ auto color
+
+
+ true
+
+
+
+ -
+
+
+ false
+
+
+
+ 30
+ 16777215
+
+
+
+ 5
+
+
+
+ -
+
+
+ R:
+
+
+
+ -
+
+
+ G:
+
+
+
+ -
+
+
+ B:
+
+
+
+ -
+
+
+
+ 30
+ 16777215
+
+
+
+ 204
+
+
+
+ -
+
+
+
+ 30
+ 16777215
+
+
+
+ 255
+
+
+
+ -
+
+
+ 255
+
+
+ 255
+
+
+ Qt::Horizontal
+
+
+
+ -
+
+
+ true
+
+
+
+ 30
+ 16777215
+
+
+
+ 127
+
+
+
+ -
+
+
+ 255
+
+
+ 204
+
+
+ Qt::Horizontal
+
+
+
+ -
+
+
+ 255
+
+
+ 127
+
+
+ Qt::Horizontal
+
+
+
+ -
+
+
+ Light on:
+
+
+
+ -
+
+
+ Light off:
+
+
+
+ -
+
+
+ R:
+
+
+
+ -
+
+
+ false
+
+
+
+ 30
+ 16777215
+
+
+
+ 5
+
+
+
+ -
+
+
+ false
+
+
+ 255
+
+
+ 5
+
+
+ Qt::Horizontal
+
+
+
+ -
+
+
+ G:
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+
+
+
+ -
+
+
+ Light
+
+
+
-
+
+
+ Ambientcoefficient:
+
+
+
+ -
+
+
+ Attenuationfactor:
+
+
+
+ -
+
+
+ B:
+
+
+
+ -
+
+
+ G:
+
+
+
+ -
+
+
+
+ 30
+ 16777215
+
+
+
+ 255
+
+
+
+ -
+
+
+
+ 30
+ 16777215
+
+
+
+ 255
+
+
+
+ -
+
+
+ Directional light
+
+
+ true
+
+
+
+ -
+
+
+
+ 30
+ 16777215
+
+
+
+ 255
+
+
+
+ -
+
+
+ R:
+
+
+
+ -
+
+
+ 255
+
+
+ 255
+
+
+ Qt::Horizontal
+
+
+
+ -
+
+
+ 255
+
+
+ 255
+
+
+ Qt::Horizontal
+
+
+
+ -
+
+
+ 255
+
+
+ 255
+
+
+ Qt::Horizontal
+
+
+
+ -
+
+
+ Qt::Vertical
+
+
+
+ 20
+ 40
+
+
+
+
+ -
+
+
+ false
+
+
+
+ 55
+ 16777215
+
+
+
+ 1
+
+
+ 0.100000000000000
+
+
+
+ -
+
+
+
+ 55
+ 16777215
+
+
+
+ 3
+
+
+ 1.000000000000000
+
+
+ 0.001000000000000
+
+
+ 0.005000000000000
+
+
+
+ -
+
+
+ Point light
+
+
+
+
+
+
+
+
+
+
+
diff --git a/QtMeshViewer/Header/OglViewerWidget.h b/QtMeshViewer/Header/OglViewerWidget.h
index 56e59f2..bdd04d9 100644
--- a/QtMeshViewer/Header/OglViewerWidget.h
+++ b/QtMeshViewer/Header/OglViewerWidget.h
@@ -1,7 +1,7 @@
#pragma once
#include "geometryengine.h"
-
+#include "..\Header\SettingsWindow.h"
#include
#include
#include
@@ -40,10 +40,12 @@ private:
struct {
QVector4D position = { 1,1,1,0 };
QVector3D intensities = { 1.0,1.0,1.0 };
- float attenuationFactor = 0.2f;
+ float attenuationFactor = 0.0f;
float ambientCoefficient = 0.005f;
} m_light;
+ SettingsWindow* m_settings;
+
QVector4D m_backgroundColor = {0.5f, 0.8f, 1.0f, 1.0f};
QOpenGLShaderProgram m_program;
@@ -83,6 +85,7 @@ public slots:
void changeDirection(int direction);
void toggleWireframe();
void toggleLight();
+ void showSettings();
signals:
void sendMessage(QString message, int severity);
diff --git a/QtMeshViewer/Header/SettingsWindow.h b/QtMeshViewer/Header/SettingsWindow.h
new file mode 100644
index 0000000..cdd1184
--- /dev/null
+++ b/QtMeshViewer/Header/SettingsWindow.h
@@ -0,0 +1,50 @@
+#pragma once
+#include
+#include "ui_SettingsWindow.h"
+
+class SettingsWindow : public QWidget
+{
+ Q_OBJECT
+
+public:
+ SettingsWindow(QWidget * parent = Q_NULLPTR);
+ ~SettingsWindow();
+
+private:
+ Ui::SettingsWindow* ui;
+
+private slots:
+ // light off
+ void lightOffRValueChanged(QString value);
+ void lightOffRValueChanged(int value);
+
+ void lightOffGValueChanged(QString value);
+ void lightOffGValueChanged(int value);
+
+ void lightOffBValueChanged(QString value);
+ void lightOffBValueChanged(int value);
+
+ // light on
+ void lightOnRValueChanged(QString value);
+ void lightOnRValueChanged(int value);
+
+ void lightOnGValueChanged(QString value);
+ void lightOnGValueChanged(int value);
+
+ void lightOnBValueChanged(QString value);
+ void lightOnBValueChanged(int value);
+
+ // light
+ void lightRValueChanged(QString value);
+ void lightRValueChanged(int value);
+
+ void lightGValueChanged(QString value);
+ void lightGValueChanged(int value);
+
+ void lightBValueChanged(QString value);
+ void lightBValueChanged(int value);
+
+ void autoColorToggled();
+
+ void radioToggled();
+};
\ No newline at end of file
diff --git a/QtMeshViewer/Resources/fshader.glsl b/QtMeshViewer/Resources/fshader.glsl
index 43b1b17..ec72252 100644
--- a/QtMeshViewer/Resources/fshader.glsl
+++ b/QtMeshViewer/Resources/fshader.glsl
@@ -42,16 +42,15 @@ void main()
if(light.position.w == 0)
{
surfaceToLight = normalize(light.position.xyz);
- attenuation = 1;
}
// point light
else
{
surfaceToLight = normalize(light.position.xyz - v_surfacePosition);
-
- float distanceToLight = length(light.position.xyz - v_surfacePosition);
- attenuation = 1.0 / (1.0 + light.attenuationFactor * pow(distanceToLight, 2));
}
+
+ float distanceToLight = length(light.position.xyz - v_surfacePosition);
+ attenuation = 1.0 / (1.0 + light.attenuationFactor * pow(distanceToLight, 2));
vec3 surfaceToCamera = normalize(cameraPosition - v_surfacePosition);
diff --git a/QtMeshViewer/Source/MainWindow.cpp b/QtMeshViewer/Source/MainWindow.cpp
index 207a131..c2d8977 100644
--- a/QtMeshViewer/Source/MainWindow.cpp
+++ b/QtMeshViewer/Source/MainWindow.cpp
@@ -127,6 +127,12 @@ void MainWindow::setupWidgets()
connect(light, &QToolButton::pressed, viewer, &OglViewerWidget::toggleLight);
ui->mainToolBar->addWidget(light);
+ QToolButton *settings = new QToolButton(this);
+ settings->setObjectName("settings");
+ settings->setToolTip("settings");
+ connect(settings, &QToolButton::pressed, viewer, &OglViewerWidget::showSettings);
+ ui->mainToolBar->addWidget(settings);
+
ui->mainToolBar->addSeparator();
QToolButton *fileInfo = new QToolButton(this);
diff --git a/QtMeshViewer/Source/OglViewerWidget.cpp b/QtMeshViewer/Source/OglViewerWidget.cpp
index 51fd12d..3d6a77a 100644
--- a/QtMeshViewer/Source/OglViewerWidget.cpp
+++ b/QtMeshViewer/Source/OglViewerWidget.cpp
@@ -12,9 +12,10 @@
/////////////////////////////////////////////////////////////////////////
// public constructor/destructor
-OglViewerWidget::OglViewerWidget(QWidget *parent) :
- QOpenGLWidget(parent),
- m_dataEngine(0)
+OglViewerWidget::OglViewerWidget(QWidget *parent)
+ : QOpenGLWidget(parent)
+ , m_dataEngine(0)
+ , m_settings(new SettingsWindow(this))
{
setFocus();
m_translation.setZ(DEFAULT_Z_DISTANCE);
@@ -29,6 +30,8 @@ OglViewerWidget::~OglViewerWidget()
makeCurrent();
delete m_dataEngine;
doneCurrent();
+
+ delete m_settings;
}
@@ -363,3 +366,8 @@ void OglViewerWidget::toggleLight()
update();
}
+
+void OglViewerWidget::showSettings()
+{
+ m_settings->show();
+}
diff --git a/QtMeshViewer/Source/SettingsWindow.cpp b/QtMeshViewer/Source/SettingsWindow.cpp
new file mode 100644
index 0000000..fd0588f
--- /dev/null
+++ b/QtMeshViewer/Source/SettingsWindow.cpp
@@ -0,0 +1,237 @@
+#include "..\Header\SettingsWindow.h"
+#include
+#include
+#include
+
+SettingsWindow::SettingsWindow(QWidget * parent)
+ : QWidget(parent)
+ , ui(new Ui::SettingsWindow)
+{
+ ui->setupUi(this);
+
+ setWindowFlags(Qt::Tool | Qt::NoDropShadowWindowHint);
+
+ // light off
+ connect(ui->lightOff_R_LE, SIGNAL(textChanged(QString)), this, SLOT(lightOffRValueChanged(QString)));
+ connect(ui->lightOff_R_S, SIGNAL(valueChanged(int)), this, SLOT(lightOffRValueChanged(int)));
+
+ connect(ui->lightOff_G_LE, SIGNAL(textChanged(QString)), this, SLOT(lightOffGValueChanged(QString)));
+ connect(ui->lightOff_G_S, SIGNAL(valueChanged(int)), this, SLOT(lightOffGValueChanged(int)));
+
+ connect(ui->lightOff_B_LE, SIGNAL(textChanged(QString)), this, SLOT(lightOffBValueChanged(QString)));
+ connect(ui->lightOff_B_S, SIGNAL(valueChanged(int)), this, SLOT(lightOffBValueChanged(int)));
+
+ // light on
+ connect(ui->lightOn_R_LE, SIGNAL(textChanged(QString)), this, SLOT(lightOnRValueChanged(QString)));
+ connect(ui->lightOn_R_S, SIGNAL(valueChanged(int)), this, SLOT(lightOnRValueChanged(int)));
+
+ connect(ui->lightOn_G_LE, SIGNAL(textChanged(QString)), this, SLOT(lightOnGValueChanged(QString)));
+ connect(ui->lightOn_G_S, SIGNAL(valueChanged(int)), this, SLOT(lightOnGValueChanged(int)));
+
+ connect(ui->lightOn_B_LE, SIGNAL(textChanged(QString)), this, SLOT(lightOnBValueChanged(QString)));
+ connect(ui->lightOn_B_S, SIGNAL(valueChanged(int)), this, SLOT(lightOnBValueChanged(int)));
+
+ // light
+ connect(ui->light_R_LE, SIGNAL(textChanged(QString)), this, SLOT(lightRValueChanged(QString)));
+ connect(ui->light_R_S, SIGNAL(valueChanged(int)), this, SLOT(lightRValueChanged(int)));
+
+ connect(ui->light_G_LE, SIGNAL(textChanged(QString)), this, SLOT(lightGValueChanged(QString)));
+ connect(ui->light_G_S, SIGNAL(valueChanged(int)), this, SLOT(lightGValueChanged(int)));
+
+ connect(ui->light_B_LE, SIGNAL(textChanged(QString)), this, SLOT(lightBValueChanged(QString)));
+ connect(ui->light_B_S, SIGNAL(valueChanged(int)), this, SLOT(lightBValueChanged(int)));
+
+
+ connect(ui->checkAutoColor, &QCheckBox::toggled, this, &SettingsWindow::autoColorToggled);
+
+ connect(ui->radioDirectLight, &QRadioButton::toggled, this, &SettingsWindow::radioToggled);
+}
+
+SettingsWindow::~SettingsWindow()
+{
+ delete ui;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Slider - LineEdit connections
+
+#pragma region light off
+
+void SettingsWindow::lightOffRValueChanged(QString value)
+{
+ ui->lightOff_R_S->setValue(value.toInt());
+}
+
+void SettingsWindow::lightOffRValueChanged(int value)
+{
+ ui->lightOff_R_LE->setText(QString::number(value));
+}
+
+void SettingsWindow::lightOffGValueChanged(QString value)
+{
+ ui->lightOff_G_S->setValue(value.toInt());
+}
+
+void SettingsWindow::lightOffGValueChanged(int value)
+{
+ ui->lightOff_G_LE->setText(QString::number(value));
+}
+
+void SettingsWindow::lightOffBValueChanged(QString value)
+{
+ ui->lightOff_B_S->setValue(value.toInt());
+}
+
+void SettingsWindow::lightOffBValueChanged(int value)
+{
+ ui->lightOff_B_LE->setText(QString::number(value));
+}
+
+#pragma endregion
+
+#pragma region light on
+
+void SettingsWindow::lightOnRValueChanged(QString value)
+{
+ ui->lightOn_R_S->setValue(value.toInt());
+}
+
+void SettingsWindow::lightOnRValueChanged(int value)
+{
+ ui->lightOn_R_LE->setText(QString::number(value));
+}
+
+void SettingsWindow::lightOnGValueChanged(QString value)
+{
+ ui->lightOn_G_S->setValue(value.toInt());
+}
+
+void SettingsWindow::lightOnGValueChanged(int value)
+{
+ ui->lightOn_G_LE->setText(QString::number(value));
+}
+
+void SettingsWindow::lightOnBValueChanged(QString value)
+{
+ ui->lightOn_B_S->setValue(value.toInt());
+}
+
+void SettingsWindow::lightOnBValueChanged(int value)
+{
+ ui->lightOn_B_LE->setText(QString::number(value));
+}
+
+#pragma endregion
+
+#pragma region light
+
+void SettingsWindow::lightRValueChanged(QString value)
+{
+ ui->light_R_S->setValue(value.toInt());
+
+ if (ui->checkAutoColor->isChecked())
+ {
+ ui->lightOn_R_LE->setText(QString::number((int)(value.toInt() / 50)));
+ ui->lightOn_R_S->setValue((int)(value.toInt() / 50));
+ }
+}
+
+void SettingsWindow::lightRValueChanged(int value)
+{
+ ui->light_R_LE->setText(QString::number(value));
+
+ if (ui->checkAutoColor->isChecked())
+ {
+ ui->lightOn_R_LE->setText(QString::number((int)(value / 50)));
+ ui->lightOn_R_S->setValue((int)(value / 50));
+ }
+}
+
+void SettingsWindow::lightGValueChanged(QString value)
+{
+ ui->light_G_S->setValue(value.toInt());
+
+ if (ui->checkAutoColor->isChecked())
+ {
+ ui->lightOn_G_LE->setText(QString::number((int)(value.toInt() / 50)));
+ ui->lightOn_G_S->setValue((int)(value.toInt() / 50));
+ }
+}
+
+void SettingsWindow::lightGValueChanged(int value)
+{
+ ui->light_G_LE->setText(QString::number(value));
+
+ if (ui->checkAutoColor->isChecked())
+ {
+ ui->lightOn_G_LE->setText(QString::number((int)(value / 50)));
+ ui->lightOn_G_S->setValue((int)(value / 50));
+ }
+}
+
+void SettingsWindow::lightBValueChanged(QString value)
+{
+ ui->light_B_S->setValue(value.toInt());
+
+ if (ui->checkAutoColor->isChecked())
+ {
+ ui->lightOn_B_LE->setText(QString::number((int)(value.toInt() / 50)));
+ ui->lightOn_B_S->setValue((int)(value.toInt() / 50));
+ }
+}
+
+void SettingsWindow::lightBValueChanged(int value)
+{
+ ui->light_B_LE->setText(QString::number(value));
+
+ if (ui->checkAutoColor->isChecked())
+ {
+ ui->lightOn_B_LE->setText(QString::number((int)(value / 50)));
+ ui->lightOn_B_S->setValue((int)(value / 50));
+ }
+}
+
+#pragma endregion
+
+
+void SettingsWindow::autoColorToggled()
+{
+ if (!ui->checkAutoColor->isChecked())
+ {
+ ui->lightOn_R_LE->setEnabled(true);
+ ui->lightOn_R_S->setEnabled(true);
+ ui->lightOn_G_LE->setEnabled(true);
+ ui->lightOn_G_S->setEnabled(true);
+ ui->lightOn_B_LE->setEnabled(true);
+ ui->lightOn_B_S->setEnabled(true);
+ }
+ else
+ {
+ ui->lightOn_R_LE->setEnabled(false);
+ ui->lightOn_R_S->setEnabled(false);
+ ui->lightOn_G_LE->setEnabled(false);
+ ui->lightOn_G_S->setEnabled(false);
+ ui->lightOn_B_LE->setEnabled(false);
+ ui->lightOn_B_S->setEnabled(false);
+
+ ui->lightOn_R_LE->setText(QString::number((int)(ui->light_R_S->value() / 50)));
+ ui->lightOn_R_S->setValue((int)(ui->light_R_S->value() / 50));
+ ui->lightOn_G_LE->setText(QString::number((int)(ui->light_G_S->value() / 50)));
+ ui->lightOn_G_S->setValue((int)(ui->light_G_S->value() / 50));
+ ui->lightOn_B_LE->setText(QString::number((int)(ui->light_B_S->value() / 50)));
+ ui->lightOn_B_S->setValue((int)(ui->light_B_S->value() / 50));
+ }
+}
+
+void SettingsWindow::radioToggled()
+{
+ if(ui->radioDirectLight->isChecked())
+ {
+ ui->attFac->setValue(0.0);
+ ui->attFac->setEnabled(false);
+ }
+ else
+ {
+ ui->attFac->setEnabled(true);
+ }
+}