limit pitch to [-90,90]

This commit is contained in:
Anakin 2017-01-08 12:21:56 +01:00
parent f5ee8a973d
commit 3be5793ffc
2 changed files with 33 additions and 8 deletions

View File

@ -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

Binary file not shown.