diff --git a/QtMeshViewer/Source/OglViewerWidget.cpp b/QtMeshViewer/Source/OglViewerWidget.cpp index 22185f4..deadc89 100644 --- a/QtMeshViewer/Source/OglViewerWidget.cpp +++ b/QtMeshViewer/Source/OglViewerWidget.cpp @@ -72,17 +72,19 @@ void OglViewerWidget::mouseMoveEvent(QMouseEvent *e) } else if (m_rotDirections.x && m_rotDirections.y && !m_rotDirections.z) { - //float pitch, yaw, roll; - //m_rotation.getEulerAngles(&pitch, &yaw, &roll); - //pitch += diff.y() * 0.5; - //yaw += diff.x() * 0.5; - //std::cout << pitch << " - " << yaw << std::endl; + float pitch, yaw, roll; + m_rotation.getEulerAngles(&pitch, &yaw, &roll); - //m_rotation = QQuaternion::fromEulerAngles(pitch, yaw, roll); + pitch += diff.y() * 0.5; + yaw += diff.x() * 0.5; - m_rotation = QQuaternion::fromAxisAndAngle(QVector3D(0.0, 1.0, 0.0).normalized(), diff.x() * 0.5) + m_rotation; - m_rotation = QQuaternion::fromAxisAndAngle(QVector3D(1.0, 0.0, 0.0).normalized(), diff.y() * 0.5) + m_rotation; + if (pitch > 89) + pitch = 89; + else if (pitch < -89) + pitch = -89; + + m_rotation = QQuaternion::fromEulerAngles(pitch, yaw, roll); } else if (m_rotDirections.x && !m_rotDirections.y && !m_rotDirections.z) @@ -97,6 +99,29 @@ void OglViewerWidget::mouseMoveEvent(QMouseEvent *e) { m_rotation = QQuaternion::fromAxisAndAngle(QVector3D(0.0, 0.0, 1.0).normalized(), diff.x() * 0.5) * m_rotation; } + else if (m_rotDirections.x && !m_rotDirections.y && m_rotDirections.z) + { + float pitch, yaw, roll; + m_rotation.getEulerAngles(&pitch, &yaw, &roll); + roll -= diff.y() * 0.5; + yaw += diff.x() * 0.5; + + m_rotation = QQuaternion::fromEulerAngles(pitch, yaw, roll); + } + else if (!m_rotDirections.x && m_rotDirections.y && m_rotDirections.z) + { + float pitch, yaw, roll; + m_rotation.getEulerAngles(&pitch, &yaw, &roll); + pitch += diff.y() * 0.5; + roll += diff.x() * 0.5; + + if (pitch > 89) + pitch = 89; + else if (pitch < -89) + pitch = -89; + + m_rotation = QQuaternion::fromEulerAngles(pitch, yaw, roll); + } // request an update diff --git a/Release/QtMeshViewer.exe b/Release/QtMeshViewer.exe index 963a86e..96e3179 100644 Binary files a/Release/QtMeshViewer.exe and b/Release/QtMeshViewer.exe differ