fixed background bug,
support directional light, zoom speed can be adjust via +/-
This commit is contained in:
@@ -55,6 +55,7 @@ void MainWindow::setupWidgets()
|
||||
{
|
||||
OglViewerWidget* viewer = new OglViewerWidget(this);
|
||||
setCentralWidget(viewer);
|
||||
connect(viewer, &OglViewerWidget::sendMessage, this, &MainWindow::printMessage);
|
||||
|
||||
QAction *openFile = new QAction(QIcon(":/images/toolbar/open.png"), "Open file", this);
|
||||
connect(openFile, &QAction::triggered, this, &MainWindow::openFile);
|
||||
|
@@ -145,7 +145,7 @@ void OglViewerWidget::mouseMoveEvent(QMouseEvent *e)
|
||||
|
||||
void OglViewerWidget::wheelEvent(QWheelEvent *e)
|
||||
{
|
||||
m_translation += {0.0, 0.0, (float)e->angleDelta().y() / 240};
|
||||
m_translation += {0.0, 0.0, (float)m_zSpeed * e->angleDelta().y() / 240};
|
||||
update();
|
||||
}
|
||||
|
||||
@@ -178,6 +178,17 @@ 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;
|
||||
emit sendMessage(QString("Zoom speed = %1%").arg(m_zSpeed * 100), 0);
|
||||
}
|
||||
else if (e->key() == Qt::Key_Plus)
|
||||
{
|
||||
m_zSpeed += 0.1;
|
||||
emit sendMessage(QString("Zoom speed = %1%").arg(m_zSpeed * 100), 0);
|
||||
}
|
||||
}
|
||||
|
||||
void OglViewerWidget::initializeGL()
|
||||
@@ -219,15 +230,15 @@ void OglViewerWidget::resizeGL(int w, int h)
|
||||
|
||||
void OglViewerWidget::paintGL()
|
||||
{
|
||||
// Clear color and depth buffer
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
if (m_backgroundColor[3] == 1.0)
|
||||
{
|
||||
glClearColor(m_backgroundColor[0], m_backgroundColor[1], m_backgroundColor[2], 0.0000f);
|
||||
m_backgroundColor[3] = 0.0;
|
||||
}
|
||||
|
||||
// Clear color and depth buffer
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Calculate model view transformation
|
||||
QMatrix4x4 view;
|
||||
view.translate(m_translation);
|
||||
@@ -290,7 +301,11 @@ void OglViewerWidget::updateLightPosition()
|
||||
{
|
||||
QMatrix4x4 rotateBack;
|
||||
rotateBack.rotate(m_rotation.inverted());
|
||||
m_light.position = rotateBack * (-m_translation);
|
||||
QVector3D cameraPosition = rotateBack * (-m_translation);
|
||||
|
||||
m_light.position.setX(cameraPosition.x());
|
||||
m_light.position.setY(cameraPosition.y());
|
||||
m_light.position.setZ(cameraPosition.z());
|
||||
}
|
||||
|
||||
|
||||
@@ -301,6 +316,7 @@ void OglViewerWidget::resetView()
|
||||
{
|
||||
m_rotation = QQuaternion();
|
||||
m_translation = { 0.0, 0.0, DEFAULT_Z_DISTANCE };
|
||||
m_zSpeed = 1;
|
||||
update();
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user