protected override void ApplyScale(Vector scale, Point center)
        {
            Rect   elementBounds = this.EditingElementSet.ElementBounds;
            Matrix m             = this.startSharedTransform;
            Matrix inverseMatrix = ElementUtilities.GetInverseMatrix(m);
            Matrix matrix1       = new Matrix();

            matrix1.Translate(-center.X, -center.Y);
            foreach (SceneElement element in this.EditingElementSet.Elements)
            {
                Matrix matrix2 = this.elementToElementsTransformDictionary[element] * matrix1;
                Point  point1  = this.startCentersDictionary[element];
                Matrix matrix3 = this.startTransformsDictionary[element];
                Rect   rect    = this.startBoundsDictionary[element];
                Point  point2  = new Point(rect.X + rect.Width * point1.X, rect.Y + rect.Height * point1.Y);
                Point  point3  = matrix2.Transform(point2);
                Vector vector  = new Point(scale.X * point3.X, scale.Y * point3.Y) - point3;
                Matrix matrix4 = matrix3 * inverseMatrix;
                matrix4.ScaleAt(scale.X, scale.Y, matrix4.OffsetX, matrix4.OffsetY);
                matrix4.Translate(vector.X, vector.Y);
                CanonicalDecomposition newTransform = new CanonicalDecomposition(matrix4 * m);
                newTransform.ScaleX        = RoundingHelper.RoundScale(newTransform.ScaleX);
                newTransform.ScaleY        = RoundingHelper.RoundScale(newTransform.ScaleY);
                newTransform.SkewX         = RoundingHelper.RoundAngle(newTransform.SkewX);
                newTransform.SkewY         = RoundingHelper.RoundAngle(newTransform.SkewY);
                newTransform.RotationAngle = RoundingHelper.RoundAngle(newTransform.RotationAngle);
                newTransform.TranslationX  = RoundingHelper.RoundLength(newTransform.TranslationX);
                newTransform.TranslationY  = RoundingHelper.RoundLength(newTransform.TranslationY);
                AdornedToolBehavior.UpdateElementTransform(element, newTransform, AdornedToolBehavior.TransformPropertyFlags.All);
            }
        }
示例#2
0
        protected override void UpdateModelFromMouse(Base3DElement selected3DElement, Vector mousePositionDelta)
        {
            Camera   camera    = (Camera)selected3DElement.Viewport.Camera.ViewObject.PlatformSpecificObject;
            Matrix3D matrix3D1 = Helper3D.CameraRotationMatrix(camera);
            Matrix3D matrix3D2 = camera.Transform.Value;

            if (matrix3D2.HasInverse)
            {
                matrix3D2.Invert();
                matrix3D1 *= matrix3D2;
            }
            Vector3D      vector1       = new Vector3D(matrix3D1.M11, matrix3D1.M21, matrix3D1.M31);
            Vector3D      vector2_1     = new Vector3D(matrix3D1.M12, matrix3D1.M22, matrix3D1.M32);
            Vector3D      vector2_2     = new Vector3D(matrix3D1.M13, matrix3D1.M23, matrix3D1.M33);
            Base3DElement base3Delement = selected3DElement.Parent as Base3DElement;
            Matrix3D      matrix3D3     = Matrix3D.Identity;

            if (base3Delement != null)
            {
                matrix3D3 = base3Delement.GetComputedTransformFromRoot3DElementToElement();
                matrix3D3.Invert();
            }
            if (this.mouseMovementMode == ObjectRotateTranslateBehavior.MovementMode.Rotate)
            {
                mousePositionDelta /= 2.0;
                Vector3D axisOfRotation = Vector3D.CrossProduct(new Vector3D(-mousePositionDelta.X, mousePositionDelta.Y, 0.0), vector2_2);
                double   length         = axisOfRotation.Length;
                if (length <= 0.0)
                {
                    return;
                }
                Vector3D vector3D = Helper3D.EulerAnglesFromQuaternion(new Quaternion(axisOfRotation, length) * Helper3D.QuaternionFromEulerAngles(selected3DElement.CanonicalRotationAngles));
                vector3D = new Vector3D(RoundingHelper.RoundAngle(vector3D.X), RoundingHelper.RoundAngle(vector3D.Y), RoundingHelper.RoundAngle(vector3D.Z));
                selected3DElement.CanonicalRotationAngles = vector3D;
            }
            else
            {
                Vector3D vector3D1         = new Vector3D(selected3DElement.CanonicalTranslationX, selected3DElement.CanonicalTranslationY, selected3DElement.CanonicalTranslationZ);
                Point    lastMousePosition = this.LastMousePosition;
                Point    endPoint          = lastMousePosition + mousePositionDelta;
                Vector3D vector3D2;
                if (this.mouseMovementMode == ObjectRotateTranslateBehavior.MovementMode.TranslateXY)
                {
                    Plane3D  plane     = new Plane3D(Vector3D.CrossProduct(vector1, vector2_1), this.hitPoint);
                    Vector3D vector    = Helper3D.VectorBetweenPointsOnPlane((Viewport3D)selected3DElement.Viewport.ViewObject.PlatformSpecificObject, plane, lastMousePosition, endPoint);
                    Vector3D vector3D3 = matrix3D3.Transform(vector);
                    vector3D2 = vector3D1 + vector3D3;
                }
                else
                {
                    double scale = this.Scale;
                    vector3D2 = vector3D1 + scale * -mousePositionDelta.Y * vector2_2;
                }
                selected3DElement.CanonicalTranslationX = RoundingHelper.RoundLength(vector3D2.X);
                selected3DElement.CanonicalTranslationY = RoundingHelper.RoundLength(vector3D2.Y);
                selected3DElement.CanonicalTranslationZ = RoundingHelper.RoundLength(vector3D2.Z);
            }
        }
示例#3
0
        private void UpdateRotation()
        {
            double num = this.unsnappedAngle;

            if (this.snapping)
            {
                num = this.SnapToAngle(this.unsnappedAngle, RotateBehavior.shiftSnapAngle);
            }
            this.ApplyRotation(RoundingHelper.RoundAngle(num));
        }
        protected void SetBrushTransform(CanonicalTransform transform)
        {
            this.EnsureEditTransaction();
            transform.CenterX       = RoundingHelper.RoundLength(transform.CenterX);
            transform.CenterY       = RoundingHelper.RoundLength(transform.CenterY);
            transform.ScaleX        = RoundingHelper.RoundScale(transform.ScaleX);
            transform.ScaleY        = RoundingHelper.RoundScale(transform.ScaleY);
            transform.SkewX         = RoundingHelper.RoundAngle(transform.SkewX);
            transform.SkewY         = RoundingHelper.RoundAngle(transform.SkewY);
            transform.RotationAngle = RoundingHelper.RoundAngle(transform.RotationAngle);
            transform.TranslationX  = RoundingHelper.RoundLength(transform.TranslationX);
            transform.TranslationY  = RoundingHelper.RoundLength(transform.TranslationY);
            IProjectContext    projectContext     = this.ActiveDocument.ProjectContext;
            CanonicalTransform canonicalTransform = new CanonicalTransform((Transform)this.GetBrushValue(BrushNode.RelativeTransformProperty));

            if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.CenterX, transform.CenterX) != 0 || JoltHelper.CompareDoubles(projectContext, canonicalTransform.CenterY, transform.CenterY) != 0)
            {
                this.SetBrushValue(BrushNode.RelativeTransformProperty, transform.GetPlatformTransform(this.RootNode.Platform.GeometryHelper));
            }
            else
            {
                if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.ScaleX, transform.ScaleX) != 0)
                {
                    this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushScaleXReference, transform.ScaleX);
                }
                if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.ScaleY, transform.ScaleY) != 0)
                {
                    this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushScaleYReference, transform.ScaleY);
                }
                if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.SkewX, transform.SkewX) != 0)
                {
                    this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushSkewXReference, transform.SkewX);
                }
                if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.SkewY, transform.SkewY) != 0)
                {
                    this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushSkewYReference, transform.SkewY);
                }
                if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.RotationAngle, transform.RotationAngle) != 0)
                {
                    this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushRotationAngleReference, transform.RotationAngle);
                }
                if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.TranslationX, transform.TranslationX) != 0)
                {
                    this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushTranslationXReference, transform.TranslationX);
                }
                if (JoltHelper.CompareDoubles(projectContext, canonicalTransform.TranslationY, transform.TranslationY) != 0)
                {
                    this.SetBrushTransformValue(this.EditingElement.Platform.Metadata.CommonProperties.BrushTranslationYReference, transform.TranslationY);
                }
            }
            this.UpdateEditTransaction();
        }
示例#5
0
        protected static void UpdateElementTransform(SceneElement element, CanonicalDecomposition newTransform, AdornedToolBehavior.TransformPropertyFlags properties)
        {
            Transform transform = element.GetComputedValueAsWpf(Base2DElement.RenderTransformProperty) as Transform;
            CanonicalDecomposition canonicalDecomposition = new CanonicalDecomposition();

            if (transform != null)
            {
                canonicalDecomposition = new CanonicalTransform(transform).Decomposition;
            }
            double num1 = RoundingHelper.RoundScale(newTransform.ScaleX);
            double num2 = RoundingHelper.RoundScale(newTransform.ScaleY);
            double num3 = RoundingHelper.RoundLength(newTransform.TranslationX);
            double num4 = RoundingHelper.RoundLength(newTransform.TranslationY);
            double num5 = RoundingHelper.RoundLength(newTransform.SkewX);
            double num6 = RoundingHelper.RoundLength(newTransform.SkewY);
            double num7 = RoundingHelper.RoundAngle(newTransform.RotationAngle);

            if ((properties & AdornedToolBehavior.TransformPropertyFlags.ScaleX) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.ScaleX, num1))
            {
                element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformScaleX, (object)num1);
            }
            if ((properties & AdornedToolBehavior.TransformPropertyFlags.ScaleY) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.ScaleY, num2))
            {
                element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformScaleY, (object)num2);
            }
            if ((properties & AdornedToolBehavior.TransformPropertyFlags.TranslationX) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.TranslationX, num3))
            {
                element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformTranslationX, (object)num3);
            }
            if ((properties & AdornedToolBehavior.TransformPropertyFlags.TranslationY) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.TranslationY, num4))
            {
                element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformTranslationY, (object)num4);
            }
            if ((properties & AdornedToolBehavior.TransformPropertyFlags.SkewX) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.SkewX, num5))
            {
                element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformSkewX, (object)num5);
            }
            if ((properties & AdornedToolBehavior.TransformPropertyFlags.SkewY) != AdornedToolBehavior.TransformPropertyFlags.None && !Tolerances.AreClose(canonicalDecomposition.SkewY, num6))
            {
                element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformSkewY, (object)num6);
            }
            if ((properties & AdornedToolBehavior.TransformPropertyFlags.RotatationAngle) == AdornedToolBehavior.TransformPropertyFlags.None || Tolerances.AreClose(canonicalDecomposition.RotationAngle, num7))
            {
                return;
            }
            element.SetValue(element.Platform.Metadata.CommonProperties.RenderTransformRotationAngle, (object)num7);
        }
示例#6
0
        protected override void UpdateModelFromMouse(Base3DElement selected3DElement, Vector mousePositionDelta)
        {
            this.lastUnsnappedAngle += this.ActiveView.Zoom * this.mouseMovementAxis * mousePositionDelta;
            double angleInDegrees1 = this.lastUnsnappedAngle;

            if (this.ShiftKeyDepressed)
            {
                angleInDegrees1 = RotateBehavior3D.shiftSnapAngle * Math.Round(angleInDegrees1 / RotateBehavior3D.shiftSnapAngle);
            }
            double angleInDegrees2 = !this.previousAngle.HasValue ? angleInDegrees1 : angleInDegrees1 - this.previousAngle.Value;

            this.previousAngle = new double?(angleInDegrees1);
            Vector3D unitEulerAngles = RotateBehavior3D.GetUnitEulerAngles(Helper3D.EulerAnglesFromQuaternion(this.previousQuaternion * new Quaternion(this.rotationAxis, angleInDegrees2)) - selected3DElement.CanonicalRotationAngles);

            this.previousQuaternion = this.initialQuaternion * new Quaternion(this.rotationAxis, angleInDegrees1);
            Vector3D vector3D = selected3DElement.CanonicalRotationAngles + unitEulerAngles;

            vector3D = new Vector3D(RoundingHelper.RoundAngle(vector3D.X), RoundingHelper.RoundAngle(vector3D.Y), RoundingHelper.RoundAngle(vector3D.Z));
            selected3DElement.CanonicalRotationAngles = vector3D;
        }
示例#7
0
        private void UpdateSkew()
        {
            if (!this.behaviorEnabled)
            {
                return;
            }
            Vector vector1 = this.MouseDevice.GetPosition((IInputElement)this.ActiveView.ViewRootContainer) - this.startPointerPosition;
            double num1    = vector1.X * this.transformedDisplacementVector.X + vector1.Y * this.transformedDisplacementVector.Y;

            vector1.X = this.transformedDisplacementVector.X * num1;
            vector1.Y = this.transformedDisplacementVector.Y * num1;
            Vector             vector2      = vector1 * this.documentToObjectTransform;
            double             num2         = vector2.X * this.displacementVector.X + vector2.Y * this.displacementVector.Y;
            CanonicalTransform newTransform = new CanonicalTransform(this.canonicalTransform);
            Point  fixedPoint = !this.skewAroundCenter ? this.oppositeAdornerPosition : this.BaseEditingElement.RenderTransformOriginInElementCoordinates;
            Vector vector3    = fixedPoint - this.adornerPosition;

            if (vector3.LengthSquared < FloatingPointArithmetic.DistanceTolerance)
            {
                return;
            }
            Vector vector4 = vector3 / vector3.Length;
            double num3    = vector4.X * this.displacementVector.X + vector4.Y * this.displacementVector.Y;

            if ((this.displacementVector - vector4 * num3).LengthSquared < FloatingPointArithmetic.DistanceTolerance)
            {
                return;
            }
            newTransform.ApplySkewScale(this.displacementVector, this.adornerPosition - fixedPoint, this.BaseEditingElement.RenderTransformOriginInElementCoordinates, fixedPoint, this.displacementVector, this.adornerPosition - fixedPoint + this.displacementVector * num2);
            newTransform.ScaleX       = RoundingHelper.RoundScale(newTransform.ScaleX);
            newTransform.ScaleY       = RoundingHelper.RoundScale(newTransform.ScaleY);
            newTransform.SkewX        = RoundingHelper.RoundAngle(newTransform.SkewX);
            newTransform.SkewY        = RoundingHelper.RoundAngle(newTransform.SkewY);
            newTransform.TranslationX = RoundingHelper.RoundLength(newTransform.TranslationX);
            newTransform.TranslationY = RoundingHelper.RoundLength(newTransform.TranslationY);
            if ((Math.Abs(newTransform.Skew.X) - 90.0) * (Math.Abs(newTransform.Skew.X) - 90.0) < FloatingPointArithmetic.DistanceTolerance || (Math.Abs(newTransform.Skew.Y) - 90.0) * (Math.Abs(newTransform.Skew.Y) - 90.0) < FloatingPointArithmetic.DistanceTolerance)
            {
                return;
            }
            AdornedToolBehavior.UpdateElementTransform(this.EditingElement, newTransform, AdornedToolBehavior.TransformPropertyFlags.Scale | AdornedToolBehavior.TransformPropertyFlags.Skew | AdornedToolBehavior.TransformPropertyFlags.Translation);
        }
示例#8
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);
        }
示例#9
0
        private object ApplyRelativeTransform(object relativeTransform, object currentTransform)
        {
            object instance1 = Activator.CreateInstance(this.ComponentType);
            object instance2 = Activator.CreateInstance(this.ComponentType);
            object target    = instance2;

            if (currentTransform != null)
            {
                if (this.PropertyLookup.TransformType == TransformType.PlaneProjection || this.PropertyLookup.IsCompositeSupported)
                {
                    target = currentTransform;
                }
                else
                {
                    target = Activator.CreateInstance(this.ComponentType, new object[1]
                    {
                        currentTransform
                    });
                }
            }
            foreach (PropertyReferenceProperty property in this.PropertyLookup.ActiveProperties)
            {
                if (property != null && property.Reference.FirstStep.TargetType == this.ComponentType)
                {
                    if (((PropertyEntry)property).get_PropertyType() == typeof(double) && !(property.Reference.ShortPath == "RotationAngleX") && (!(property.Reference.ShortPath == "RotationAngleY") && !(property.Reference.ShortPath == "RotationAngleZ")))
                    {
                        double num1 = (double)property.Reference.GetValue(relativeTransform);
                        double num2 = (double)property.Reference.GetValue(target);
                        double num3 = (double)property.Reference.GetValue(instance2);
                        double num4 = !this.ComposesByMultiplication(property, instance2) ? num2 + (num1 - num3) : num2 * num1;
                        double num5 = !((PropertyEntry)property).get_PropertyName().Contains("Angle") ? (!((PropertyEntry)property).get_PropertyName().Contains("Scale") ? RoundingHelper.RoundLength(num4) : RoundingHelper.RoundScale(num4)) : RoundingHelper.RoundAngle(num4);
                        if (num5 != num3)
                        {
                            property.Reference.SetValue(instance1, (object)num5);
                        }
                    }
                    else if (property.Reference.ShortPath == "RotationAngles")
                    {
                        Quaternion orientation = Helper3D.QuaternionFromEulerAngles((Vector3D)property.Reference.GetValue(relativeTransform)) * Helper3D.QuaternionFromEulerAngles((Vector3D)property.Reference.GetCurrentValue(target));
                        property.Reference.SetValue(instance1, (object)Helper3D.EulerAnglesFromQuaternion(orientation));
                    }
                }
            }
            return(instance1);
        }
示例#10
0
        private void SetRotationFromPointer()
        {
            Vector vector = Mouse.GetPosition((IInputElement)this) - new Point(this.RenderSize.Width / 2.0, this.RenderSize.Height / 2.0);

            if (Tolerances.NearZero(vector) || !this.IsEnabled)
            {
                return;
            }
            double num = Math.Atan2(vector.Y, vector.X) * 180.0 / Math.PI;

            this.RotationAngle = this.ClosestAngleTo(Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift) ? Math.Round(num / 15.0) * 15.0 : RoundingHelper.RoundAngle(num));
        }