//-------------------------------------------------------------------------------------------------- /// Rotate /// /// \return Returns true if input caused changes to the camera an false if no changes occurred //-------------------------------------------------------------------------------------------------- bool ManipulatorTrackball::rotate(int posX, int posY) { if (m_camera.isNull()) return false; if (posX == m_lastPosX && posY == m_lastPosY) return false; const double vpPixSizeX = m_camera->viewport()->width(); const double vpPixSizeY = m_camera->viewport()->height(); if (vpPixSizeX <= 0 || vpPixSizeY <= 0) return false; const double vpPosX = posX - static_cast<int>(m_camera->viewport()->x()); const double vpPosY = posY - static_cast<int>(m_camera->viewport()->y()); const double vpLastPosX = m_lastPosX - static_cast<int>(m_camera->viewport()->x()); const double vpLastPosY = m_lastPosY - static_cast<int>(m_camera->viewport()->y()); // Scale the new/last positions to the range [-1.0, 1.0] double newPosX = 2.0*(vpPosX/vpPixSizeX) - 1.0; double newPosY = 2.0*(vpPosY/vpPixSizeY) - 1.0; double lastPosX = 2.0*(vpLastPosX/vpPixSizeX) - 1.0; double lastPosY = 2.0*(vpLastPosY/vpPixSizeY) - 1.0; Mat4d viewMat = m_camera->viewMatrix(); // Compute rotation quaternion Quatd rotQuat = trackballRotation(lastPosX, lastPosY, newPosX, newPosY, viewMat, m_rotateSensitivity); // Update navigation by modifying the view matrix Mat4d rotMatr = rotQuat.toMatrix4(); rotMatr.translatePostMultiply(-m_rotationPoint); rotMatr.translatePreMultiply(m_rotationPoint); viewMat = viewMat*rotMatr; m_camera->setViewMatrix(viewMat); m_lastPosX = posX; m_lastPosY = posY; return true; }