Commit 73ee8a40 authored by Anakin's avatar Anakin

added settings window,

connected all slider, lineEdits, checkboxes,...,
need to connect everything with the OglViewerWidget now
parent 0a9103fd
This diff is collapsed.
#pragma once
#include "geometryengine.h"
#include "..\Header\SettingsWindow.h"
#include <QOpenGLWidget>
#include <QOpenGLFunctions>
#include <QMatrix4x4>
......@@ -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);
......
#pragma once
#include <QWidget>
#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
......@@ -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);
......
......@@ -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);
......
......@@ -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();
}
#include "..\Header\SettingsWindow.h"
#include <QString>
#include <QLineEdit>
#include <QSlider>
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);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment