void QD3D11MultiViewportViewer::mouseMoveEvent( QMouseEvent* event ) { Vector2i curPos( event->x(), event->y() ); Vector2f delta = curPos - m_prevPos; #if 1 float pitchSpeed = m_flipMouseUpDown ? m_mousePitchSpeed : -m_mousePitchSpeed; const float yawSpeed = 0.005f; const float panSpeed = 0.005f; const float walkSpeed = -0.005f; Matrix3f worldToCamera = m_perspectiveCamera.viewMatrix().getSubmatrix3x3( 0, 0 ); Matrix3f cameraToWorld = m_perspectiveCamera.inverseViewMatrix().getSubmatrix3x3( 0, 0 ); Vector3f eye = m_perspectiveCamera.eye(); Vector3f x = m_perspectiveCamera.right(); Vector3f y = m_perspectiveCamera.up(); Vector3f z = m_perspectiveCamera.forward(); // rotate if( event->buttons() == Qt::LeftButton ) { // pitch around the local x axis float pitch = pitchSpeed * delta.y; Matrix3f pitchMatrix = Matrix3f::rotateX( pitch ); y = cameraToWorld * pitchMatrix * worldToCamera * y; z = cameraToWorld * pitchMatrix * worldToCamera * z; // yaw around the world up vector float yaw = yawSpeed * delta.x; Matrix3f yawMatrix = m_groundPlaneToWorld * Matrix3f::rotateY( yaw ) * m_worldToGroundPlane; x = yawMatrix * x; y = yawMatrix * y; z = yawMatrix * z; m_perspectiveCamera.setLookAt( eye, eye + z, y ); } // walk else if( event->buttons() == Qt::RightButton ) { float dx = panSpeed * delta.x; float dz = walkSpeed * delta.y; translate( dx, 0, dz ); } // move up/down else if( event->buttons() == Qt::MiddleButton ) { float dy = -panSpeed * delta.y; translate( 0, dy, 0 ); } #else if(event->buttons() & Qt::RightButton) //rotate { float rotSpeed = 0.005f; //radians per pixel Quat4f rotation; rotation.setAxisAngle(rotSpeed * delta.abs(), Vector3f(-delta[1], -delta[0], 0)); Matrix3f rotMatrix = Matrix3f::rotation(rotation); Matrix3f viewMatrix = m_camera.getViewMatrix().getSubmatrix3x3(0, 0); rotMatrix = viewMatrix.transposed() * rotMatrix * viewMatrix; Vector3f eye, center, up; m_camera.getLookAt(&eye, ¢er, &up); m_camera.setLookAt(center + rotMatrix * (eye - center), center, rotMatrix * up); } else if(event->buttons() & Qt::LeftButton) //translate { float speed = 10.f; Vector3f screenDelta(delta[0], delta[1], 0); screenDelta[0] /= -double(width()); screenDelta[1] /= double(height()); Matrix4f iViewProjMatrix = m_camera.getInverseViewProjectionMatrix(); Vector3f worldDelta = iViewProjMatrix.getSubmatrix3x3(0, 0) * (speed * screenDelta); Vector3f eye, center, up; m_camera.getLookAt(&eye, ¢er, &up); m_camera.setLookAt(eye + worldDelta, center + worldDelta, up); } #endif m_prevPos = curPos; update(); }