headlight,

bug fixes,
code improvement,
This commit is contained in:
Anakin 2017-01-30 11:31:37 +01:00
parent fbb51563c9
commit 9c16aa32f1
5 changed files with 31 additions and 11 deletions

View File

@ -34,6 +34,7 @@ private:
QVector3D intensities = { 1.0,1.0,1.0 }; QVector3D intensities = { 1.0,1.0,1.0 };
float attenuationFactor = 0.0f; float attenuationFactor = 0.0f;
float ambientCoefficient = 0.005f; float ambientCoefficient = 0.005f;
bool headlight = false;
} m_light; } m_light;
SettingsWindow* m_settings; SettingsWindow* m_settings;
@ -79,6 +80,7 @@ protected:
// slots // slots
public slots: public slots:
void loadFile(QString name);
void toggleAxis(int axis); void toggleAxis(int axis);
void toggleWireframe(); void toggleWireframe();
void toggleLight(); void toggleLight();
@ -88,6 +90,7 @@ public slots:
void setLightColor(QVector3D value); void setLightColor(QVector3D value);
void setAttFac(double value); void setAttFac(double value);
void setAmbCoef(double value); void setAmbCoef(double value);
void setHeadlight(bool value);
void setBackfaceCulling(bool value); void setBackfaceCulling(bool value);
void setZoomSpeed(int percent); void setZoomSpeed(int percent);

View File

@ -30,6 +30,8 @@ signals:
void updateLightColor(QVector3D value); void updateLightColor(QVector3D value);
void updateAttFac(double value); void updateAttFac(double value);
void updateAmbCoef(double value); void updateAmbCoef(double value);
void sendHeadlight(bool value);
void sendBackfaceCulling(bool value); void sendBackfaceCulling(bool value);
void sendZommSpeed(int percent); void sendZommSpeed(int percent);
}; };

View File

@ -71,6 +71,7 @@ void MainWindow::setupWidgets()
// Ogl Viewer // Ogl Viewer
OglViewerWidget* viewer = new OglViewerWidget(this); OglViewerWidget* viewer = new OglViewerWidget(this);
setCentralWidget(viewer); setCentralWidget(viewer);
connect(this, &MainWindow::loadFile, viewer, &OglViewerWidget::loadFile);
// open file // open file
QToolButton *openFile = new QToolButton(this); QToolButton *openFile = new QToolButton(this);

View File

@ -25,6 +25,7 @@ OglViewerWidget::OglViewerWidget(QWidget *parent)
connect(m_settings, &SettingsWindow::updateLightColor, this, &OglViewerWidget::setLightColor); connect(m_settings, &SettingsWindow::updateLightColor, this, &OglViewerWidget::setLightColor);
connect(m_settings, &SettingsWindow::updateAttFac, this, &OglViewerWidget::setAttFac); connect(m_settings, &SettingsWindow::updateAttFac, this, &OglViewerWidget::setAttFac);
connect(m_settings, &SettingsWindow::updateAmbCoef, this, &OglViewerWidget::setAmbCoef); 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::sendBackfaceCulling, this, &OglViewerWidget::setBackfaceCulling);
connect(m_settings, &SettingsWindow::sendZommSpeed, this, &OglViewerWidget::setZoomSpeed); connect(m_settings, &SettingsWindow::sendZommSpeed, this, &OglViewerWidget::setZoomSpeed);
} }
@ -68,6 +69,9 @@ void OglViewerWidget::resetView()
m_rotation = QQuaternion(); m_rotation = QQuaternion();
m_translation = { 0.0, 0.0, DEFAULT_Z_DISTANCE }; m_translation = { 0.0, 0.0, DEFAULT_Z_DISTANCE };
m_zSpeed = 1; m_zSpeed = 1;
if (m_light.headlight)
updateLightPosition();
update(); update();
} }
@ -92,10 +96,6 @@ void OglViewerWidget::initializeGL()
// Enable depth buffer // Enable depth buffer
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
//TODO: does not work
// Enable back face culling
//glEnable(GL_CULL_FACE);
// Enable transparency // Enable transparency
glEnable(GL_BLEND); glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
@ -103,12 +103,6 @@ void OglViewerWidget::initializeGL()
m_dataEngine = new GeometryEngine(this); m_dataEngine = new GeometryEngine(this);
connect(m_dataEngine, &GeometryEngine::requestResetView, this, &OglViewerWidget::resetView); connect(m_dataEngine, &GeometryEngine::requestResetView, this, &OglViewerWidget::resetView);
connect(m_dataEngine, &GeometryEngine::requestUpdate, this, static_cast<void(OglViewerWidget::*)(void)>(&OglViewerWidget::update)); 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) void OglViewerWidget::resizeGL(int w, int h)
@ -274,6 +268,8 @@ void OglViewerWidget::mouseMoveEvent(QMouseEvent *e)
} }
// request an update // request an update
if (m_light.headlight)
updateLightPosition();
update(); update();
} }
else if (m_mouse.right) 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}; m_translation += {(float)(diff.x() * 0.01), (float)(diff.y() * -0.01), 0.0};
// request an update // request an update
if (m_light.headlight)
updateLightPosition();
update(); update();
} }
} }
@ -295,6 +293,9 @@ void OglViewerWidget::mouseMoveEvent(QMouseEvent *e)
void OglViewerWidget::wheelEvent(QWheelEvent *e) void OglViewerWidget::wheelEvent(QWheelEvent *e)
{ {
m_translation += {0.0, 0.0, (float)m_zSpeed * e->angleDelta().y() / 240}; m_translation += {0.0, 0.0, (float)m_zSpeed * e->angleDelta().y() / 240};
if (m_light.headlight)
updateLightPosition();
update(); update();
} }
@ -333,6 +334,11 @@ void OglViewerWidget::dropEvent(QDropEvent * e)
///////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////
// public slots // public slots
void OglViewerWidget::loadFile(QString name)
{
m_dataEngine->loadFile(name);
}
void OglViewerWidget::toggleAxis(int axis) void OglViewerWidget::toggleAxis(int axis)
{ {
switch (axis) switch (axis)
@ -417,6 +423,13 @@ void OglViewerWidget::setAmbCoef(double value)
update(); update();
} }
void OglViewerWidget::setHeadlight(bool value)
{
m_light.headlight = value;
if (m_lightOn)
update();
}
void OglViewerWidget::setBackfaceCulling(bool value) void OglViewerWidget::setBackfaceCulling(bool value)
{ {
m_backfaceCulling = value; m_backfaceCulling = value;
@ -425,5 +438,5 @@ void OglViewerWidget::setBackfaceCulling(bool value)
void OglViewerWidget::setZoomSpeed(int percent) void OglViewerWidget::setZoomSpeed(int percent)
{ {
m_zSpeed = percent / 100; m_zSpeed = (double) percent / 100;
} }

View File

@ -94,6 +94,7 @@ void SettingsWindow::setupConnections()
connect(ui->checkBackfaceCulling, &QCheckBox::toggled, [this]() {emit sendBackfaceCulling(ui->checkBackfaceCulling->isChecked()); }); 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->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()); });
} }