Aufgrund einer Wartung wird GitLab am 28.09. zwischen 10:00 und 11:00 Uhr kurzzeitig nicht zur Verfügung stehen. / Due to maintenance, GitLab will be temporarily unavailable on 28.09. between 10:00 and 11:00 am.

Commit 9c16aa32 authored by Anakin's avatar Anakin

headlight,

bug fixes,
code improvement,
parent fbb51563
......@@ -34,6 +34,7 @@ private:
QVector3D intensities = { 1.0,1.0,1.0 };
float attenuationFactor = 0.0f;
float ambientCoefficient = 0.005f;
bool headlight = false;
} m_light;
SettingsWindow* m_settings;
......@@ -79,6 +80,7 @@ protected:
// slots
public slots:
void loadFile(QString name);
void toggleAxis(int axis);
void toggleWireframe();
void toggleLight();
......@@ -88,6 +90,7 @@ public slots:
void setLightColor(QVector3D value);
void setAttFac(double value);
void setAmbCoef(double value);
void setHeadlight(bool value);
void setBackfaceCulling(bool value);
void setZoomSpeed(int percent);
......
......@@ -30,6 +30,8 @@ signals:
void updateLightColor(QVector3D value);
void updateAttFac(double value);
void updateAmbCoef(double value);
void sendHeadlight(bool value);
void sendBackfaceCulling(bool value);
void sendZommSpeed(int percent);
};
\ No newline at end of file
......@@ -71,6 +71,7 @@ void MainWindow::setupWidgets()
// Ogl Viewer
OglViewerWidget* viewer = new OglViewerWidget(this);
setCentralWidget(viewer);
connect(this, &MainWindow::loadFile, viewer, &OglViewerWidget::loadFile);
// open file
QToolButton *openFile = new QToolButton(this);
......
......@@ -25,6 +25,7 @@ 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::sendHeadlight, this, &OglViewerWidget::setHeadlight);
connect(m_settings, &SettingsWindow::sendBackfaceCulling, this, &OglViewerWidget::setBackfaceCulling);
connect(m_settings, &SettingsWindow::sendZommSpeed, this, &OglViewerWidget::setZoomSpeed);
}
......@@ -68,6 +69,9 @@ void OglViewerWidget::resetView()
m_rotation = QQuaternion();
m_translation = { 0.0, 0.0, DEFAULT_Z_DISTANCE };
m_zSpeed = 1;
if (m_light.headlight)
updateLightPosition();
update();
}
......@@ -92,10 +96,6 @@ void OglViewerWidget::initializeGL()
// Enable depth buffer
glEnable(GL_DEPTH_TEST);
//TODO: does not work
// Enable back face culling
//glEnable(GL_CULL_FACE);
// Enable transparency
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
......@@ -103,12 +103,6 @@ void OglViewerWidget::initializeGL()
m_dataEngine = new GeometryEngine(this);
connect(m_dataEngine, &GeometryEngine::requestResetView, this, &OglViewerWidget::resetView);
connect(m_dataEngine, &GeometryEngine::requestUpdate, this, static_cast<void(OglViewerWidget::*)(void)>(&OglViewerWidget::update));
//TODO: better solution
MainWindow* parent = dynamic_cast<MainWindow*>(parentWidget());
if (parent != NULL)
connect(parent, &MainWindow::loadFile, [this](QString value) {m_dataEngine->loadFile(value); });
}
void OglViewerWidget::resizeGL(int w, int h)
......@@ -274,6 +268,8 @@ void OglViewerWidget::mouseMoveEvent(QMouseEvent *e)
}
// request an update
if (m_light.headlight)
updateLightPosition();
update();
}
else if (m_mouse.right)
......@@ -288,6 +284,8 @@ void OglViewerWidget::mouseMoveEvent(QMouseEvent *e)
m_translation += {(float)(diff.x() * 0.01), (float)(diff.y() * -0.01), 0.0};
// request an update
if (m_light.headlight)
updateLightPosition();
update();
}
}
......@@ -295,6 +293,9 @@ void OglViewerWidget::mouseMoveEvent(QMouseEvent *e)
void OglViewerWidget::wheelEvent(QWheelEvent *e)
{
m_translation += {0.0, 0.0, (float)m_zSpeed * e->angleDelta().y() / 240};
if (m_light.headlight)
updateLightPosition();
update();
}
......@@ -333,6 +334,11 @@ void OglViewerWidget::dropEvent(QDropEvent * e)
/////////////////////////////////////////////////////////////////////////
// public slots
void OglViewerWidget::loadFile(QString name)
{
m_dataEngine->loadFile(name);
}
void OglViewerWidget::toggleAxis(int axis)
{
switch (axis)
......@@ -417,6 +423,13 @@ void OglViewerWidget::setAmbCoef(double value)
update();
}
void OglViewerWidget::setHeadlight(bool value)
{
m_light.headlight = value;
if (m_lightOn)
update();
}
void OglViewerWidget::setBackfaceCulling(bool value)
{
m_backfaceCulling = value;
......@@ -425,5 +438,5 @@ void OglViewerWidget::setBackfaceCulling(bool value)
void OglViewerWidget::setZoomSpeed(int percent)
{
m_zSpeed = percent / 100;
m_zSpeed = (double) percent / 100;
}
......@@ -94,6 +94,7 @@ void SettingsWindow::setupConnections()
connect(ui->checkBackfaceCulling, &QCheckBox::toggled, [this]() {emit sendBackfaceCulling(ui->checkBackfaceCulling->isChecked()); });
connect(ui->spinZSpeed, static_cast<void (QSpinBox::*)(int)>(&QSpinBox::valueChanged), [this](int value) {emit sendZommSpeed(value); });
connect(ui->checkHeadlight, &QCheckBox::toggled, [this]() {emit sendHeadlight(ui->checkHeadlight->isChecked()); });
}
......
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