From 3959edcf4c4a531e87c9296ba401bd0f08caaed4 Mon Sep 17 00:00:00 2001 From: Kim Motoyoshi Kalland Date: Fri, 4 Sep 2009 17:00:06 +0200 Subject: 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 --- demos/boxes/scene.cpp | 5 +---- demos/boxes/trackball.cpp | 14 +++++++------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/demos/boxes/scene.cpp b/demos/boxes/scene.cpp index 7c0d4d8..0975fc5 100644 --- a/demos/boxes/scene.cpp +++ b/demos/boxes/scene.cpp @@ -718,8 +718,6 @@ void Scene::renderBoxes(const QMatrix4x4 &view, int excludeBox) glPushMatrix(); QMatrix4x4 m; m.rotate(m_trackBalls[1].rotation()); - m = m.transposed(); - multMatrix(m); glRotatef(360.0f * i / m_programs.size(), 0.0f, 0.0f, 1.0f); @@ -753,7 +751,6 @@ void Scene::renderBoxes(const QMatrix4x4 &view, int excludeBox) if (-1 != excludeBox) { QMatrix4x4 m; m.rotate(m_trackBalls[0].rotation()); - m = m.transposed(); multMatrix(m); if (glActiveTexture) { @@ -880,7 +877,7 @@ void Scene::renderCubemaps() GLRenderTargetCube::getViewMatrix(mat, face); QVector4D v = QVector4D(-center.x(), -center.y(), -center.z(), 1.0); - mat.setColumn(3, v * mat); + mat.setColumn(3, mat * v); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); renderBoxes(mat, i); 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; } -- cgit v0.12