Ejemplo n.º 1
0
 private void UpdateModelFromMouse(Vector mousePositionDelta)
 {
     if (this.cameraElement == null || !(this.cameraElement is ProjectionCameraElement))
     {
         return;
     }
     if (this.mouseMovementMode == CameraOrbitToolBehavior.MovementMode.Rotate)
     {
         this.totalAzimuthDelta   += -mousePositionDelta.X / 2.0;
         this.totalElevationDelta += -mousePositionDelta.Y / 2.0;
         double angle1 = this.totalAzimuthDelta;
         if (this.IsShiftDown)
         {
             angle1 = CameraOrbitToolBehavior.shiftSnapAngle * Math.Round(angle1 / CameraOrbitToolBehavior.shiftSnapAngle);
         }
         RotateTransform3D rotateTransform3D1 = new RotateTransform3D(Vector3D.DotProduct((Vector3D)this.cameraElement.GetComputedValue(ProjectionCameraElement.UpDirectionProperty), this.cameraInitialUp) >= 0.0 ? (Rotation3D) new AxisAngleRotation3D(this.cameraInitialUp, angle1) : (Rotation3D) new AxisAngleRotation3D(-this.cameraInitialUp, angle1), this.cameraInitialLookAt);
         Point3D           point     = rotateTransform3D1.Transform(this.cameraInitialPosition);
         Vector3D          vector3D1 = rotateTransform3D1.Transform(this.cameraInitialUp);
         Vector3D          axis      = Vector3D.CrossProduct(this.cameraInitialLookAt - point, vector3D1);
         double            angle2    = this.totalElevationDelta;
         if (this.IsShiftDown)
         {
             angle2 = CameraOrbitToolBehavior.shiftSnapAngle * Math.Round(angle2 / CameraOrbitToolBehavior.shiftSnapAngle);
         }
         if (axis.LengthSquared == 0.0)
         {
             return;
         }
         RotateTransform3D rotateTransform3D2 = new RotateTransform3D((Rotation3D) new AxisAngleRotation3D(axis, angle2), this.cameraInitialLookAt);
         Point3D           point3D1           = rotateTransform3D2.Transform(point);
         Vector3D          vector3D2          = rotateTransform3D2.Transform(vector3D1);
         Point3D           point3D2           = RoundingHelper.RoundPosition(point3D1);
         Vector3D          vector3D3          = RoundingHelper.RoundDirection(vector3D2);
         Vector3D          vector3D4          = RoundingHelper.RoundDirection(this.cameraInitialLookAt - point3D2);
         this.cameraElement.SetValue(ProjectionCameraElement.PositionProperty, (object)point3D2);
         this.cameraElement.SetValue(ProjectionCameraElement.UpDirectionProperty, (object)vector3D3);
         this.cameraElement.SetValue(ProjectionCameraElement.LookDirectionProperty, (object)vector3D4);
     }
     else
     {
         Matrix3D matrix3D = Helper3D.CameraRotationMatrix((Camera)this.cameraElement.ViewObject.PlatformSpecificObject);
         if (this.mouseMovementMode == CameraOrbitToolBehavior.MovementMode.TranslateXY)
         {
             Vector3D vector3D1 = new Vector3D(matrix3D.M11, matrix3D.M21, matrix3D.M31);
             Vector3D vector3D2 = new Vector3D(matrix3D.M12, matrix3D.M22, matrix3D.M32);
             this.cameraInitialPosition += this.scale * (-mousePositionDelta.X * vector3D1 + mousePositionDelta.Y * vector3D2);
         }
         else
         {
             Vector3D vector3D1 = new Vector3D(matrix3D.M13, matrix3D.M23, matrix3D.M33);
             this.cameraInitialPosition += this.scale * mousePositionDelta.Y * vector3D1;
             Vector3D vector3D2 = RoundingHelper.RoundDirection(this.cameraInitialLookAt - this.cameraInitialPosition);
             this.cameraElement.SetValue(ProjectionCameraElement.LookDirectionProperty, (object)vector3D2);
         }
         this.cameraInitialPosition = RoundingHelper.RoundPosition(this.cameraInitialPosition);
         this.cameraElement.SetValue(ProjectionCameraElement.PositionProperty, (object)this.cameraInitialPosition);
     }
 }
Ejemplo n.º 2
0
        protected override void ModifyValue(PropertyReference propertyReference, object valueToSet, SceneNode.Modification modification, int index)
        {
            bool flag = DesignTimeProperties.EulerAnglesProperty.Equals((object)propertyReference.LastStep);

            if (!flag || !this.ViewModel.AnimationEditor.IsKeyFraming || this.ViewModel.IsForcingBaseValue)
            {
                base.ModifyValue(propertyReference, valueToSet, modification, index);
            }
            if (!flag)
            {
                return;
            }
            propertyReference = propertyReference.Subreference(0, propertyReference.Count - 2);
            propertyReference = propertyReference.Append(Base3DElement.RotateTransform3DRotationProperty);
            if (valueToSet is Vector3D)
            {
                Quaternion quaternion = Helper3D.QuaternionFromEulerAngles((Vector3D)valueToSet);
                valueToSet = (object)new AxisAngleRotation3D(RoundingHelper.RoundDirection(quaternion.Axis), RoundingHelper.RoundAngle(quaternion.Angle));
            }
            base.ModifyValue(propertyReference, valueToSet, modification, index);
        }