adjust light functionality,

bugs:
- background cannot be changed during runtime
This commit is contained in:
Anakin
2017-01-18 17:01:43 +01:00
parent a521dfc292
commit 4c177f2ddc
9 changed files with 75 additions and 35 deletions

View File

@@ -101,6 +101,12 @@ void MainWindow::setupWidgets()
connect(wireframe, &QAction::triggered, viewer, &OglViewerWidget::toggleWireframe);
ui->mainToolBar->addAction(wireframe);
QAction *light = new QAction(QIcon(":/images/toolbar/light.png"), "Light", this);
light->setCheckable(true);
light->setChecked(false);
connect(light, &QAction::triggered, viewer, &OglViewerWidget::toggleLight);
ui->mainToolBar->addAction(light);
ui->mainToolBar->addSeparator();
QAction *fileInfo = new QAction(QIcon(":/images/toolbar/info.png"), "File info", this);

View File

@@ -173,14 +173,18 @@ void OglViewerWidget::keyPressEvent(QKeyEvent *e)
{
parentWidget()->close();
}
else if (e->key() == Qt::Key_L)
{
updateLightPosition();
update();
}
}
void OglViewerWidget::initializeGL()
{
initializeOpenGLFunctions();
//glClearColor(0.5000f, 0.8000f, 1.0000f, 0.0000f);
glClearColor(0.02f, 0.01f, 0.01f, 0.0000f);
glClearColor(0.5000f, 0.8000f, 1.0000f, 0.0000f);
initShaders();
@@ -269,6 +273,13 @@ void OglViewerWidget::setConnections()
}
void OglViewerWidget::updateLightPosition()
{
QMatrix4x4 rotateBack;
rotateBack.rotate(m_rotation.inverted());
m_light.position = rotateBack * (-m_translation);
}
/////////////////////////////////////////////////////////////////////////
// private slots
@@ -305,3 +316,21 @@ void OglViewerWidget::toggleWireframe()
m_wireframe = 1 - m_wireframe;
update();
}
void OglViewerWidget::toggleLight()
{
m_lightOn = 1 - m_lightOn;
if (m_lightOn)
{
glClearColor(m_light.intensities.x() / 100, m_light.intensities.y() / 100, m_light.intensities.z() / 100, 0.0000f);
updateLightPosition();
}
else
{
glClearColor(0.5000f, 0.8000f, 1.0000f, 0.0000f);
}
update();
}