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
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>SettingsWindow</class>
<widget class="QWidget" name="SettingsWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Settings</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QGroupBox" name="groupBackground">
<property name="title">
<string>Background</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="4" column="5">
<widget class="QLineEdit" name="lightOn_G_LE">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximumSize">
<size>
<width>30</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>5</string>
</property>
</widget>
</item>
<item row="4" column="7">
<widget class="QLabel" name="label_5">
<property name="text">
<string>B:</string>
</property>
</widget>
</item>
<item row="4" column="6">
<widget class="QSlider" name="lightOn_G_S">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximum">
<number>255</number>
</property>
<property name="value">
<number>5</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="9">
<widget class="QSlider" name="lightOn_B_S">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximum">
<number>255</number>
</property>
<property name="value">
<number>5</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="3" column="3" colspan="3">
<widget class="QCheckBox" name="checkAutoColor">
<property name="text">
<string>auto color</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="8">
<widget class="QLineEdit" name="lightOn_B_LE">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximumSize">
<size>
<width>30</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>5</string>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QLabel" name="label_0">
<property name="text">
<string>R:</string>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QLabel" name="label_1">
<property name="text">
<string>G:</string>
</property>
</widget>
</item>
<item row="2" column="7">
<widget class="QLabel" name="label_2">
<property name="text">
<string>B:</string>
</property>
</widget>
</item>
<item row="2" column="5">
<widget class="QLineEdit" name="lightOff_G_LE">
<property name="maximumSize">
<size>
<width>30</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>204</string>
</property>
</widget>
</item>
<item row="2" column="8">
<widget class="QLineEdit" name="lightOff_B_LE">
<property name="maximumSize">
<size>
<width>30</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>255</string>
</property>
</widget>
</item>
<item row="2" column="9">
<widget class="QSlider" name="lightOff_B_S">
<property name="maximum">
<number>255</number>
</property>
<property name="value">
<number>255</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QLineEdit" name="lightOff_R_LE">
<property name="enabled">
<bool>true</bool>
</property>
<property name="maximumSize">
<size>
<width>30</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>127</string>
</property>
</widget>
</item>
<item row="2" column="6">
<widget class="QSlider" name="lightOff_G_S">
<property name="maximum">
<number>255</number>
</property>
<property name="value">
<number>204</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QSlider" name="lightOff_R_S">
<property name="maximum">
<number>255</number>
</property>
<property name="value">
<number>127</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="3" column="0" colspan="3">
<widget class="QLabel" name="labelLightOn">
<property name="text">
<string>Light on:</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="10">
<widget class="QLabel" name="labelLightOff">
<property name="text">
<string>Light off:</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>R:</string>
</property>
</widget>
</item>
<item row="4" column="2">
<widget class="QLineEdit" name="lightOn_R_LE">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximumSize">
<size>
<width>30</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>5</string>
</property>
</widget>
</item>
<item row="4" column="3">
<widget class="QSlider" name="lightOn_R_S">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximum">
<number>255</number>
</property>
<property name="value">
<number>5</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="4">
<widget class="QLabel" name="label_4">
<property name="text">
<string>G:</string>
</property>
</widget>
</item>
<item row="5" column="5">
<spacer name="verticalSpacerBackground">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</item>
<item row="2" column="0">
<widget class="QGroupBox" name="groupLight">
<property name="title">
<string>Light</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="2" column="0" colspan="4">
<widget class="QLabel" name="labelAmbCoeff">
<property name="text">
<string>Ambientcoefficient:</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="4">
<widget class="QLabel" name="labelAttFac">
<property name="text">
<string>Attenuationfactor:</string>
</property>
</widget>
</item>
<item row="1" column="6">
<widget class="QLabel" name="label_8">
<property name="text">
<string>B:</string>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLabel" name="label_7">
<property name="text">
<string>G:</string>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QLineEdit" name="light_G_LE">
<property name="maximumSize">
<size>
<width>30</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>255</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QLineEdit" name="light_R_LE">
<property name="maximumSize">
<size>
<width>30</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>255</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="4">
<widget class="QRadioButton" name="radioDirectLight">
<property name="text">
<string>Directional light</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="7">
<widget class="QLineEdit" name="light_B_LE">
<property name="maximumSize">
<size>
<width>30</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>255</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>R:</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QSlider" name="light_R_S">
<property name="maximum">
<number>255</number>
</property>
<property name="value">
<number>255</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="8">
<widget class="QSlider" name="light_B_S">
<property name="maximum">
<number>255</number>
</property>
<property name="value">
<number>255</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="1" column="5">
<widget class="QSlider" name="light_G_S">
<property name="maximum">
<number>255</number>
</property>
<property name="value">
<number>255</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="4" column="4">
<spacer name="verticalSpacerLight">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="4" colspan="2">
<widget class="QDoubleSpinBox" name="attFac">
<property name="enabled">
<bool>false</bool>
</property>
<property name="maximumSize">
<size>
<width>55</width>
<height>16777215</height>
</size>
</property>
<property name="decimals">
<number>1</number>
</property>
<property name="singleStep">
<double>0.100000000000000</double>
</property>
</widget>
</item>
<item row="2" column="4" colspan="2">
<widget class="QDoubleSpinBox" name="ambCoef">
<property name="maximumSize">
<size>
<width>55</width>
<height>16777215</height>
</size>
</property>
<property name="decimals">
<number>3</number>
</property>
<property name="maximum">
<double>1.000000000000000</double>
</property>
<property name="singleStep">
<double>0.001000000000000</double>
</property>
<property name="value">
<double>0.005000000000000</double>
</property>
</widget>
</item>
<item row="0" column="4" colspan="4">
<widget class="QRadioButton" name="radioPointLight">
<property name="text">
<string>Point light</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
#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);