Commit 3be5793f authored by Anakin's avatar Anakin

limit pitch to [-90,90]

parent f5ee8a97
......@@ -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
......
No preview for this file type
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