/// <summary> /// Changes the direction of the camera. /// </summary> /// <param name="lookDir"> /// The look direction. /// </param> /// <param name="animationTime"> /// The animation time. /// </param> public void ChangeDirection(Vector3 lookDir, double animationTime = 500) { if (!this.IsRotationEnabled) { return; } this.StopAnimations(); this.PushCameraSetting(); this.ActualCamera.ChangeDirection(lookDir.ToVector3D(), this.ActualCamera.UpDirection, animationTime); }
/// <summary> /// Rotate around three axes. /// </summary> /// <param name="p1"> /// The previous mouse position. /// </param> /// <param name="p2"> /// The current mouse position. /// </param> /// <param name="rotateAround"> /// The point to rotate around. /// </param> public void RotateTurnball(Vector2 p1, Vector2 p2, Vector3 rotateAround) { this.InitTurnballRotationAxes(p1); Vector2 delta = p2 - p1; var relativeTarget = rotateAround - this.Camera.CameraInternal.Target; var relativePosition = rotateAround - this.Camera.CameraInternal.Position; float d = -1; if (this.CameraMode != CameraMode.Inspect) { d = 0.2f; } d *= (float)RotationSensitivity; var q1 = Quaternion.RotationAxis(this.rotationAxisX, d * Inv * delta.X / 180 * (float)Math.PI); var q2 = Quaternion.RotationAxis(this.rotationAxisY, d * delta.Y / 180 * (float)Math.PI); Quaternion q = q1 * q2; var m = Matrix.RotationQuaternion(q); Vector3 newLookDir = Vector3.TransformNormal(this.Camera.CameraInternal.LookDirection, m); Vector3 newUpDirection = Vector3.TransformNormal(this.Camera.CameraInternal.UpDirection, m); Vector3 newRelativeTarget = Vector3.TransformCoordinate(relativeTarget, m); Vector3 newRelativePosition = Vector3.TransformCoordinate(relativePosition, m); var newRightVector = Vector3.Normalize(Vector3.Cross(newLookDir, newUpDirection)); var modUpDir = Vector3.Normalize(Vector3.Cross(newRightVector, newLookDir)); if ((newUpDirection - modUpDir).Length() > 1e-8) { newUpDirection = modUpDir; } var newTarget = rotateAround - newRelativeTarget; var newPosition = rotateAround - newRelativePosition; var newLookDirection = newTarget - newPosition; this.Camera.LookDirection = newLookDirection.ToVector3D(); if (this.CameraMode == CameraMode.Inspect) { this.Camera.Position = newPosition.ToPoint3D(); } this.Camera.UpDirection = newUpDirection.ToVector3D(); }
/// <summary> /// Pans the camera by the specified 3D vector (world coordinates). /// </summary> /// <param name="delta"> /// The panning vector. /// </param> /// <param name="stopOther">Stop other manipulation</param> public void Pan(Vector3 delta, bool stopOther = true) { if (!this.Controller.IsPanEnabled) { return; } if (stopOther) { this.Controller.StopSpin(); this.Controller.StopZooming(); } if (this.CameraMode == CameraMode.FixedPosition) { return; } this.Camera.Position += delta.ToVector3D(); }
/// <summary> /// Rotates the specified p0. /// </summary> /// <param name="p0">The p0.</param> /// <param name="p1">The p1.</param> /// <param name="rotateAround">The rotate around.</param> /// <param name="stopOther">if set to <c>true</c> [stop other].</param> public void Rotate(Vector2 p0, Vector2 p1, Vector3 rotateAround, bool stopOther = true) { if (!this.Controller.IsRotationEnabled) { return; } if (stopOther) { Controller.StopZooming(); Controller.StopPanning(); } p0 = Vector2.Multiply(p0, Controller.AllowRotateXY); p1 = Vector2.Multiply(p1, Controller.AllowRotateXY); Vector3 newPos = Camera.CameraInternal.Position; Vector3 newLook = Camera.CameraInternal.LookDirection; Vector3 newUp = Vector3.Normalize(Camera.CameraInternal.UpDirection); switch (this.Controller.CameraRotationMode) { case CameraRotationMode.Trackball: CameraMath.RotateTrackball(CameraMode, ref p0, ref p1, ref rotateAround, (float)RotationSensitivity, Controller.Width, Controller.Height, Camera, Inv, out newPos, out newLook, out newUp); break; case CameraRotationMode.Turntable: var p = p1 - p0; CameraMath.RotateTurntable(CameraMode, ref p, ref rotateAround, (float)RotationSensitivity, Controller.Width, Controller.Height, Camera, Inv, ModelUpDirection, out newPos, out newLook, out newUp); break; case CameraRotationMode.Turnball: CameraMath.RotateTurnball(CameraMode, ref p0, ref p1, ref rotateAround, (float)RotationSensitivity, Controller.Width, Controller.Height, Camera, Inv, out newPos, out newLook, out newUp); break; default: break; } Camera.LookDirection = newLook.ToVector3D(); Camera.Position = newPos.ToPoint3D(); Camera.UpDirection = newUp.ToVector3D(); }
/// <summary> /// Changes the direction of the camera. /// </summary> /// <param name="lookDir"> /// The look direction. /// </param> /// <param name="upDir"> /// The up direction. /// </param> /// <param name="animationTime"> /// The animation time. /// </param> public void ChangeDirection(Vector3 lookDir, Vector3 upDir, double animationTime = 500) { ChangeDirection(lookDir.ToVector3D(), upDir.ToVector3D(), animationTime); }