Exemple #1
0
        /// <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();
        }
Exemple #2
0
        /// <summary>
        /// Rotate camera using 'Turntable' rotation.
        /// </summary>
        /// <param name="delta">
        /// The relative change in position.
        /// </param>
        /// <param name="rotateAround">
        /// The point to rotate around.
        /// </param>
        public void RotateTurntable(Vector2 delta, Vector3 rotateAround)
        {
            var relativeTarget   = rotateAround - this.Camera.CameraInternal.Target;
            var relativePosition = rotateAround - this.Camera.CameraInternal.Position;
            var cUp   = Camera.CameraInternal.UpDirection;
            var up    = this.ModelUpDirection;
            var dir   = Vector3.Normalize(Camera.CameraInternal.LookDirection);
            var right = Vector3.Normalize(Vector3.Cross(dir, cUp));

            float d = -0.5f;

            if (this.CameraMode != CameraMode.Inspect)
            {
                d *= -0.2f;
            }

            d *= (float)this.RotationSensitivity;

            var        q1 = Quaternion.RotationAxis(up, d * Inv * delta.X / 180 * (float)Math.PI);
            var        q2 = Quaternion.RotationAxis(right, d * delta.Y / 180 * (float)Math.PI);
            Quaternion q  = q1 * q2;

            var m = Matrix.RotationQuaternion(q);

            var newUpDirection = Vector3.TransformNormal(cUp, m);

            var newRelativeTarget   = Vector3.TransformCoordinate(relativeTarget, m);
            var newRelativePosition = Vector3.TransformCoordinate(relativePosition, m);

            var newTarget   = rotateAround - newRelativeTarget;
            var newPosition = rotateAround - newRelativePosition;

            this.Camera.LookDirection = (newTarget - newPosition).ToVector3D();
            if (this.CameraMode == CameraMode.Inspect)
            {
                this.Camera.Position = newPosition.ToPoint3D();
            }

            this.Camera.UpDirection = newUpDirection.ToVector3D();
        }