From 538453c1db6e939f084e4495c2ff1d8e14dbbd56 Mon Sep 17 00:00:00 2001 From: Anakin Date: Sun, 29 Jan 2017 23:47:14 +0100 Subject: [PATCH] added headlight option to settings, added cullface option to settings, zoom speed now adjust at settings, bugs: cullface does not work anymore, todo: connect headlight --- QtMeshViewer/Form Files/SettingsWindow.ui | 213 +++++++++++++--------- QtMeshViewer/Header/OglViewerWidget.h | 2 + QtMeshViewer/Header/SettingsWindow.h | 2 + QtMeshViewer/Resources/about.txt | 1 - QtMeshViewer/Source/OglViewerWidget.cpp | 33 ++-- QtMeshViewer/Source/SettingsWindow.cpp | 4 +- 6 files changed, 157 insertions(+), 98 deletions(-) diff --git a/QtMeshViewer/Form Files/SettingsWindow.ui b/QtMeshViewer/Form Files/SettingsWindow.ui index 75d8917..4dd2cf2 100644 --- a/QtMeshViewer/Form Files/SettingsWindow.ui +++ b/QtMeshViewer/Form Files/SettingsWindow.ui @@ -7,14 +7,14 @@ 0 0 400 - 300 + 358 Settings - + Background @@ -281,46 +281,28 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - - + Light - - - - Ambientcoefficient: + + + + + 30 + 16777215 + - - - - - - Attenuationfactor: + + QAbstractSpinBox::NoButtons - - - - - - B: + + 255 @@ -331,6 +313,13 @@ + + + + Attenuationfactor: + + + @@ -347,29 +336,10 @@ - - - - - 30 - 16777215 - - - - QAbstractSpinBox::NoButtons - - - 255 - - - - - + + - Directional light - - - true + B: @@ -389,13 +359,6 @@ - - - - R: - - - @@ -422,31 +385,22 @@ - - - - 255 - - - 255 - - - Qt::Horizontal + + + + R: - - - - Qt::Vertical + + + + Directional light - - - 20 - 40 - + + true - + @@ -492,7 +446,34 @@ - + + + + 255 + + + 255 + + + Qt::Horizontal + + + + + + + Ambientcoefficient: + + + + + + + Headlight + + + + Point light @@ -502,6 +483,74 @@ + + + + General + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Zoom speed: + + + + + + + % + + + 200 + + + 10 + + + 100 + + + + + + + Backface Culling + + + true + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + diff --git a/QtMeshViewer/Header/OglViewerWidget.h b/QtMeshViewer/Header/OglViewerWidget.h index 799bbc1..0eb3398 100644 --- a/QtMeshViewer/Header/OglViewerWidget.h +++ b/QtMeshViewer/Header/OglViewerWidget.h @@ -87,6 +87,8 @@ public slots: void setLightColor(QVector3D value); void setAttFac(double value); void setAmbCoef(double value); + void setBackfaceCulling(bool value); + void setZoomSpeed(int percent); }; diff --git a/QtMeshViewer/Header/SettingsWindow.h b/QtMeshViewer/Header/SettingsWindow.h index 26a5963..ac3f8ba 100644 --- a/QtMeshViewer/Header/SettingsWindow.h +++ b/QtMeshViewer/Header/SettingsWindow.h @@ -30,4 +30,6 @@ signals: void updateLightColor(QVector3D value); void updateAttFac(double value); void updateAmbCoef(double value); + void sendBackfaceCulling(bool value); + void sendZommSpeed(int percent); }; \ No newline at end of file diff --git a/QtMeshViewer/Resources/about.txt b/QtMeshViewer/Resources/about.txt index ffb3566..779ecdb 100644 --- a/QtMeshViewer/Resources/about.txt +++ b/QtMeshViewer/Resources/about.txt @@ -8,7 +8,6 @@ left mouse - rotate right mouse - move scroll - zoom space - reset view -+/- - adjust zoom speed L - set light to current position esc - close diff --git a/QtMeshViewer/Source/OglViewerWidget.cpp b/QtMeshViewer/Source/OglViewerWidget.cpp index fbd971f..85bf2f6 100644 --- a/QtMeshViewer/Source/OglViewerWidget.cpp +++ b/QtMeshViewer/Source/OglViewerWidget.cpp @@ -1,5 +1,4 @@ #include "..\Header\OglViewerWidget.h" -#include "..\Header\OutputDevice.h" #include "..\Header\MainWindow.h" #include #include @@ -26,6 +25,8 @@ OglViewerWidget::OglViewerWidget(QWidget *parent) connect(m_settings, &SettingsWindow::updateLightColor, this, &OglViewerWidget::setLightColor); connect(m_settings, &SettingsWindow::updateAttFac, this, &OglViewerWidget::setAttFac); connect(m_settings, &SettingsWindow::updateAmbCoef, this, &OglViewerWidget::setAmbCoef); + connect(m_settings, &SettingsWindow::sendBackfaceCulling, this, &OglViewerWidget::setBackfaceCulling); + connect(m_settings, &SettingsWindow::sendZommSpeed, this, &OglViewerWidget::setZoomSpeed); } OglViewerWidget::~OglViewerWidget() @@ -91,9 +92,9 @@ void OglViewerWidget::initializeGL() // Enable depth buffer glEnable(GL_DEPTH_TEST); - //TODO: make this optional + //TODO: does not work // Enable back face culling - //glEnable(GL_CULL_FACE); + glEnable(GL_CULL_FACE); // Enable transparency glEnable(GL_BLEND); @@ -303,17 +304,6 @@ void OglViewerWidget::keyPressEvent(QKeyEvent *e) updateLightPosition(); update(); } - else if (e->key() == Qt::Key_Minus) - { - m_zSpeed -= 0.1; - m_zSpeed < 0.09 ? m_zSpeed = 0 : NULL; - OutputDevice::getInstance()->print(QString("Zoom speed = %1%").arg(m_zSpeed * 100), 0); - } - else if (e->key() == Qt::Key_Plus) - { - m_zSpeed += 0.1; - OutputDevice::getInstance()->print(QString("Zoom speed = %1%").arg(m_zSpeed * 100), 0); - } } void OglViewerWidget::dragEnterEvent(QDragEnterEvent *e) @@ -417,3 +407,18 @@ void OglViewerWidget::setAmbCoef(double value) if (m_lightOn) update(); } + +void OglViewerWidget::setBackfaceCulling(bool value) +{ + if (value) + glCullFace(GL_FRONT_AND_BACK); + else if(!value) + glCullFace(GL_FRONT); + + update(); +} + +void OglViewerWidget::setZoomSpeed(int percent) +{ + m_zSpeed = percent / 100; +} diff --git a/QtMeshViewer/Source/SettingsWindow.cpp b/QtMeshViewer/Source/SettingsWindow.cpp index f440ccc..f751be4 100644 --- a/QtMeshViewer/Source/SettingsWindow.cpp +++ b/QtMeshViewer/Source/SettingsWindow.cpp @@ -91,6 +91,9 @@ void SettingsWindow::setupConnections() connect(ui->radioDirectLight, &QRadioButton::toggled, this, &SettingsWindow::radioToggled); connect(ui->ambCoef, static_cast(&QDoubleSpinBox::valueChanged), [this](double value) {emit updateAmbCoef(value); }); connect(ui->attFac, static_cast(&QDoubleSpinBox::valueChanged), [this](double value) {emit updateAttFac(value); }); + + connect(ui->checkBackfaceCulling, &QCheckBox::toggled, [this]() {emit sendBackfaceCulling(ui->checkBackfaceCulling->isChecked()); }); + connect(ui->spinZSpeed, static_cast(&QSpinBox::valueChanged), [this](int value) {emit sendZommSpeed(value); }); } @@ -157,4 +160,3 @@ void SettingsWindow::lightColorChanged() ui->lightOn_B_S->setValue((int)(ui->light_B_S->value() / 50)); } } -