summaryrefslogtreecommitdiffstats
path: root/demos/boxes/trackball.cpp
diff options
context:
space:
mode:
authorKim Motoyoshi Kalland <kim.kalland@nokia.com>2009-09-04 15:00:06 (GMT)
committerKim Motoyoshi Kalland <kim.kalland@nokia.com>2009-09-04 15:14:38 (GMT)
commit3959edcf4c4a531e87c9296ba401bd0f08caaed4 (patch)
treeeb078eb259766977f5ec9de22e6fd46c0b1040ea /demos/boxes/trackball.cpp
parent1dd1400a84831da7377dadd2521460f129e9640a (diff)
downloadQt-3959edcf4c4a531e87c9296ba401bd0f08caaed4.zip
Qt-3959edcf4c4a531e87c9296ba401bd0f08caaed4.tar.gz
Qt-3959edcf4c4a531e87c9296ba401bd0f08caaed4.tar.bz2
Fixed object rotations in the boxes demo.
When Math3D was introduced, the boxes demo was changed to use the classes in the new module, but the change caused some bugs with the object rotations. This commit should fix them. Reviewed-by: Samuel
Diffstat (limited to 'demos/boxes/trackball.cpp')
-rw-r--r--demos/boxes/trackball.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/demos/boxes/trackball.cpp b/demos/boxes/trackball.cpp
index 9898441..60de6af 100644
--- a/demos/boxes/trackball.cpp
+++ b/demos/boxes/trackball.cpp
@@ -92,9 +92,9 @@ void TrackBall::move(const QPointF& p, const QQuaternion &transformation)
{
QLineF delta(m_lastPos, p);
m_angularVelocity = 180*delta.length() / (PI*msecs);
- m_axis = QVector3D(delta.dy(), -delta.dx(), 0.0f).normalized();
+ m_axis = QVector3D(-delta.dy(), delta.dx(), 0.0f).normalized();
m_axis = transformation.rotateVector(m_axis);
- m_rotation *= QQuaternion::fromAxisAndAngle(m_axis, delta.length());
+ m_rotation = QQuaternion::fromAxisAndAngle(m_axis, 180 / PI * delta.length()) * m_rotation;
}
break;
case Sphere:
@@ -113,13 +113,13 @@ void TrackBall::move(const QPointF& p, const QQuaternion &transformation)
else
currentPos3D.normalize();
- m_axis = QVector3D::crossProduct(currentPos3D, lastPos3D);
- float angle = asin(sqrt(QVector3D::dotProduct(m_axis, m_axis)));
+ m_axis = QVector3D::crossProduct(lastPos3D, currentPos3D);
+ float angle = 180 / PI * asin(sqrt(QVector3D::dotProduct(m_axis, m_axis)));
- m_angularVelocity = 180*angle / (PI*msecs);
+ m_angularVelocity = angle / msecs;
m_axis.normalize();
m_axis = transformation.rotateVector(m_axis);
- m_rotation *= QQuaternion::fromAxisAndAngle(m_axis, angle);
+ m_rotation = QQuaternion::fromAxisAndAngle(m_axis, angle) * m_rotation;
}
break;
}
@@ -155,6 +155,6 @@ QQuaternion TrackBall::rotation() const
QTime currentTime = QTime::currentTime();
float angle = m_angularVelocity * m_lastTime.msecsTo(currentTime);
- return m_rotation * QQuaternion::fromAxisAndAngle(m_axis, angle);
+ return QQuaternion::fromAxisAndAngle(m_axis, angle) * m_rotation;
}