コード例 #1
0
        /// <summary>
        /// 重設控制項中的相片大小
        /// </summary>
        private void ResetCamSize(object o)
        {
            PresentationSource source = PresentationSource.FromVisual(_mainWindow);

            System.Windows.Media.Matrix transformToDevice = source.CompositionTarget.TransformToDevice;
            var pixelSize  = (Size)transformToDevice.Transform(new Vector(_mainWindow.CamHost1.ActualWidth, _mainWindow.CamHost1.ActualHeight));
            var pixelSize2 = (Size)transformToDevice.Transform(new Vector(_mainWindow.CamHost2.ActualWidth, _mainWindow.CamHost2.ActualHeight));

            _mainWindow.CamHost1.ResetCameraSize(pixelSize.Width, pixelSize.Height);
            _mainWindow.CamHost2.ResetCameraSize(pixelSize2.Width, pixelSize2.Height);
        }
コード例 #2
0
ファイル: MainWindow.xaml.cs プロジェクト: chamons/ArenaLS
        SKPointI GetMousePosition(System.Windows.Input.MouseButtonEventArgs e)
        {
            Point p = e.GetPosition(null);

            p = Transform.Transform(p);
            return(new SKPointI((int)p.X, (int)p.Y));
        }
コード例 #3
0
        public static NativeRectFloat Transform(this NativeRectFloat rect, System.Windows.Media.Matrix matrix)
        {
            System.Windows.Point[] myPointArray = { rect.TopLeft, rect.BottomRight };
            matrix.Transform(myPointArray);
            NativePointFloat topLeft     = myPointArray[0];
            NativePointFloat bottomRight = myPointArray[1];

            return(new NativeRectFloat(topLeft, bottomRight));
        }
コード例 #4
0
 public void CamHost1_Loaded(object sender, RoutedEventArgs e)
 {
     if (!_mainWindow.CamHost1.IsActivated)
     {
         PresentationSource          source            = PresentationSource.FromVisual(_mainWindow);
         System.Windows.Media.Matrix transformToDevice = source.CompositionTarget.TransformToDevice;
         var pixelSize = (Size)transformToDevice.Transform(new Vector(_mainWindow.CamHost1.ActualWidth, _mainWindow.CamHost1.ActualHeight));
         _mainWindow.CamHost1.InitializeCamSetting(pixelSize.Width, pixelSize.Height);
     }
 }
コード例 #5
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Point pointToWindow = Mouse.GetPosition(this);
            Point pointToScreen = PointToScreen(pointToWindow);

            System.Windows.Media.Matrix transform = PresentationSource.FromVisual(this).CompositionTarget.TransformFromDevice;
            Point mouse = transform.Transform(pointToScreen);

            Left = mouse.X - (Width / 2);
            Top  = mouse.Y - (Height / 2);
        }
コード例 #6
0
        /// <summary>
        /// Centers to parent.
        /// </summary>
        /// <param name="ctrl">The <see cref="System.Windows.Forms.Control"/> control.</param>
        public void CenterToParent(System.Windows.Forms.Control ctrl)
        {
            // Get the handle to the non-WPF owner window
            IntPtr ownerWindowHandle = ctrl.Handle; // Get hWnd for non-WPF window

            // Set the owned WPF window’s owner with the non-WPF owner window
            WindowInteropHelper helper = new WindowInteropHelper(this);

            helper.Owner = ownerWindowHandle;

            // Center window
            // Note - Need to use HwndSource to get handle to WPF owned window,
            //        and the handle only exists when SourceInitialized has been
            //        raised
            if (SrcInitialized)
            {
                // Get WPF size and location for non-WPF owner window
                int ownerLeft   = ctrl.Left;   // Get non-WPF owner’s Left
                int ownerWidth  = ctrl.Width;  // Get non-WPF owner’s Width
                int ownerTop    = ctrl.Top;    // Get non-WPF owner’s Top
                int ownerHeight = ctrl.Height; // Get non-WPF owner’s Height

                // Get transform matrix to transform non-WPF owner window
                // size and location units into device-independent WPF
                // size and location units
                HwndSource source = HwndSource.FromHwnd(helper.Handle);
                if (source == null || source.CompositionTarget == null)
                {
                    return;
                }

                System.Windows.Media.Matrix matrix           = source.CompositionTarget.TransformFromDevice;
                System.Windows.Point        ownerWPFSize     = matrix.Transform(new System.Windows.Point(ownerWidth, ownerHeight));
                System.Windows.Point        ownerWPFPosition = matrix.Transform(new System.Windows.Point(ownerLeft, ownerTop));

                // Center WPF window
                this.WindowStartupLocation = WindowStartupLocation.Manual;
                this.Left = ownerWPFPosition.X + (ownerWPFSize.X - this.Width) / 2;
                this.Top  = ownerWPFPosition.Y + (ownerWPFSize.Y - this.Height) / 2;
            }
        }
コード例 #7
0
        /// <summary>
        /// Creates a new <see cref="RectanglePolygon"/> instance
        /// by rotating an axis-aligned <see cref="Rect"/> to a specified angle.
        /// </summary>
        /// <param name="axisAlignedRect">The axis-aligned <see cref="Rect"/> to rotate.</param>
        /// <param name="rotationAngle">The rotation angle (in degrees).</param>
        public RectanglePolygon(Rect axisAlignedRect, double rotationAngle)
        {
            Point[] rectPoints = new[] { axisAlignedRect.TopLeft, axisAlignedRect.TopRight, axisAlignedRect.BottomRight, axisAlignedRect.BottomLeft };

            if (Math.Abs(rotationAngle) != 0d)
            {
                System.Windows.Media.Matrix rotationMatrix = MatrixFactory.CreateRotationMatrix(rotationAngle, axisAlignedRect.CenterPoint());
                rotationMatrix.Transform(rectPoints);
            }

            TopLeft     = rectPoints[0];
            TopRight    = rectPoints[1];
            BottomRight = rectPoints[2];
            BottomLeft  = rectPoints[3];
        }
コード例 #8
0
        /// <summary>
        /// De-rotates the <see cref="RectanglePolygon"/>, converting it into an axis-aligned <see cref="Rect"/>.
        /// </summary>
        /// <returns>A de-rotated axis-aligned <see cref="Rect"/>.</returns>
        public Rect ToDerotatedAxisAlignedRect()
        {
            double angle = Angle;

            if (Math.Abs(angle) == 0d)
            {
                return(new Rect(TopLeft, BottomRight));
            }
            else
            {
                System.Windows.Media.Matrix rotationMatrix = MatrixFactory.CreateRotationMatrix(-angle, Center);
                Point[] rectPoints = new[] { TopLeft, BottomRight };
                rotationMatrix.Transform(rectPoints);

                return(new Rect(rectPoints[0], rectPoints[1]));
            }
        }
コード例 #9
0
ファイル: MainWindow.cs プロジェクト: ClemensT/WPF-Samples
        public void PerformOperation(object sender, RoutedEventArgs e)
        {
            var li = sender as RadioButton;
            string syntaxString, resultType, operationString;

            switch (li?.Name)
            {
                // begin switch


                case "rb1":
                {
                    // Multiplies a Matrix by a Matrix using the overloaded * operator
                    // Returns a Matrix
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);

                    var isInvertible = matrix1.HasInverse;
                    // isInvertible is equal to True    

                    // Displaying Results
                    syntaxString = "isInvertible = matrix1.HasInverse;";
                    resultType = "Boolean";
                    operationString = "Checking if matrix1 is invertible";
                    ShowResults(isInvertible.ToString(), syntaxString, resultType, operationString);

                    break;
                }
                case "rb2":
                {
                    // Translates a Matrix
                    // Returns a Matrix
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    const double offsetX = 15;
                    const double offsetY = 25;

                    matrix1.Translate(offsetX, offsetY);
                    // matrix1 is not equal to 

                    //Displaying Results
                    syntaxString = "matrix1.Translate(offsetX, offsetY);";
                    resultType = "Void";
                    operationString = "Translating a Matrix by a Point";
                    ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);

                    break;
                }
                case "rb3":
                {
                    // Prepend a Tranlsation to a Matrix
                    // Returns a Matrix
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    const double offsetX = 15;
                    const double offsetY = 25;

                    matrix1.TranslatePrepend(offsetX, offsetY);
                    // matrix1 is not equal to 

                    //Displaying Results
                    syntaxString = " matrix1.TranslatePrepend(offsetX, offsetY);";
                    resultType = "Void";
                    operationString = "Prepending Translating a matrix";
                    ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb4":
                {
                    // Sets a Matrix to an identity matrix
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);

                    matrix1.SetIdentity();
                    // matrix1 is now equal to (1,0,0,1,0,0)

                    //Displaying Results
                    syntaxString = "matrix1.SetIdentity();";
                    resultType = "Void";
                    operationString = "Setting a matrix to an identity matrix";
                    ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb5":
                {
                    // Checks if a Matrix is an identity matrix
                    // Creates a Matrix
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);

                    // Sets matrix1 into an identity matrix
                    matrix1.SetIdentity();

                    var isIdentityMatrix = matrix1.IsIdentity;
                    // isIdentityMatrix is equal to True

                    //Displaying Results
                    syntaxString = "isIdentityMatrix = matrix1.IsIdentity;";
                    resultType = "Boolean";
                    operationString = "Determining if a Matrix is an identity matrix";
                    ShowResults(isIdentityMatrix.ToString(), syntaxString, resultType, operationString);
                    break;
                }


                case "rb6":
                {
                    // Changes a Matrix into an identity matrix
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    matrix1 = System.Windows.Media.Matrix.Identity;
                    // matrix1 is now equal to (1,0,0,1,0,0)
                    //Displaying Results
                    syntaxString = "matrix1 = Matrix.Identity;";
                    resultType = "Matrix";
                    operationString = "Gets an identity Matrix";
                    ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb7":
                {
                    // Converts a string representation of a matrix into a Matrix structure
                    var matrixResult = new System.Windows.Media.Matrix();

                    matrixResult = System.Windows.Media.Matrix.Parse("1,2,3,4,5,6");
                    // matrixResult is equal to (1,2,3,4,5,6)

                    //Displaying Results
                    syntaxString = "matrixResult = Matrix.Parse(\"1,2,3,4,5,6\");";
                    resultType = "Matrix";
                    operationString = "Convert a string into a Matrix structure";
                    ShowResults(matrixResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb8":
                {
                    // Checks if two Matrixes are equal using the static Equals method
                    // Returns a Boolean.
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12);
                    var areEqual = System.Windows.Media.Matrix.Equals(matrix1, matrix2);
                    // areEqual is equal to False

                    //Displaying Results
                    syntaxString = "areEqual = Matrix.Equals(matrix1, matrix2);";
                    resultType = "Boolean";
                    operationString = "Checking if the matrices are equal";
                    ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);

                    break;
                }
                case "rb8b":
                {
                    // Checks if an Object is equal to a Matrix using the static Equals method
                    // Returns a Boolean.
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12);

                    var areEqual = matrix1.Equals(matrix2);
                    // areEqual is equal to False

                    //Displaying Results
                    syntaxString = "areEqual = Matrix.Equals(matrix1, matrix2);";
                    resultType = "Boolean";
                    operationString = "Checking if the matrices are equal";
                    ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);

                    break;
                }

                case "rb9":
                {
                    // Checks if two Matrixes are equal using the overloaded == operator
                    // Returns a Boolean.    
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12);

                    var areEqual = matrix1 == matrix2;
                    // areEqual is equal to False

                    //Displaying Results
                    syntaxString = "areEqual = matrix1 == matrix2;";
                    resultType = "Boolean";
                    operationString = "Checking if the matrices are equal";
                    ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb10":
                {
                    // Checks if two Matrixes are not equal using the overloaded != operator
                    // Returns a Boolean.    
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12);

                    var areEqual = matrix1 != matrix2;
                    // areEqual is equal to False

                    //Displaying Results
                    syntaxString = "areEqual = matrix1 != matrix2;";
                    resultType = "Boolean";
                    operationString = "Checking if the matrices are not equal";
                    ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb11":
                {
                    // Inverts a Matrix
                    // Creating a Matrix structure
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    // Checking if matrix1 is invertible
                    if (matrix1.HasInverse)
                    {
                        // Inverting matrix1                         
                        matrix1.Invert();
                        // matrix1 is equal to (-0.04, 0.2 , 0.3, -0.1, 1, -2) 
                    }
                    //Displaying Results
                    syntaxString = "matrix1.Invert();";
                    resultType = "Void";
                    operationString = "Inverting a matrix";
                    ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb12":
                {
                    // Prepends a Matrix to another Matrix.
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12);
                    matrix1.Prepend(matrix2);
                    // matrix1 is equal to (70,100,150,220,255,370)     
                    //Displaying Results
                    syntaxString = "matrix1.Prepend(matrix2);";
                    resultType = "Void";
                    operationString = "Prepending a Matrix to another Matrix";
                    ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb13":
                {
                    // Appends a Matrix to another Matrix
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12);
                    matrix1.Append(matrix2);
                    // matrix1 is equal to (70,100,150,220,240,352)    
                    //Displaying Results
                    syntaxString = "matrix1.Append(matrix2);";
                    resultType = "Void";
                    operationString = "Appending a Matrix to another Matrix";
                    ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb14":
                {
                    // Rotates a Matrix by a specified angle
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    double rotateAngle = 90;

                    matrix1.Rotate(rotateAngle);
                    // matrix1 is equal to (-10,5,-20,15,-30,25)   

                    //Displaying Results
                    syntaxString = "matrix1.Rotate(rotateAngle);";
                    resultType = "Void";
                    operationString = "Rotating a Matrix";
                    ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb15":
                {
                    // Rotates a Matrix by a specified angle at a specific point
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    matrix1.RotateAt(90, 2, 4);
                    // matrix1 is equal to (-10,5,-20,15,-24,27)    
                    //Displaying Results
                    syntaxString = "matrix1.RotateAt(rotateAngle, rotateCenterX, rotateCenterY);";
                    resultType = "Void";
                    operationString = "Rotating a Matrix";
                    ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb16":
                {
                    // Prepends a Rotation to a Matrix
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    double rotateAngle = 90;
                    matrix1.RotatePrepend(rotateAngle);
                    // matrix1 is equal to (15,20,-5,-10,25,30)    
                    //Displaying Results
                    syntaxString = "matrix1.RotatePrepend(rotateAngle);";
                    resultType = "Void";
                    operationString = "Rotating a Matrix";
                    ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb17":
                {
                    // Prepends a Rotation at a specific point to a Matrix
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    matrix1.RotateAtPrepend(90, 2, 4);
                    // matrix1 is equal to  (15,20,-5,-10,85,130)
                    //Displaying Results
                    syntaxString = "matrix1.RotateAtPrepend(rotateAngle, rotateCenterX, rotateCenterY);";
                    resultType = "Void";
                    operationString = "Rotating a Matrix";
                    ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb18":
                {
                    // Scales a Matrix 
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    double scaleX = (1);
                    double scaleY = (2);

                    matrix1.Scale(scaleX, scaleY);
                    // matrix1 is equal to     

                    //Displaying Results
                    syntaxString = "matrix1.Scale(scaleX, scaleY);";
                    resultType = "Void";
                    operationString = "Scaling a Matrix";
                    ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb19":
                {
                    // Multiplies a Matrix by another Matrix
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12);
                    var matrixResult = new System.Windows.Media.Matrix();

                    matrixResult = System.Windows.Media.Matrix.Multiply(matrix2, matrix1);
                    // matrixResult is equal to (70, 100, 150, 220, 255, 370)    

                    //Displaying Results
                    syntaxString = "matrixResult = Matrix.Multiply(matrix2, matrix1);";
                    resultType = "Matrix";
                    operationString = "Multiplying matrix1 and matrix2";
                    ShowResults(matrixResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb20":
                {
                    // Multiplies a Matrix by another Matrix using the overloaded * operator
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12);
                    var matrixResult = new System.Windows.Media.Matrix();

                    matrixResult = matrix1*matrix2;
                    // matrixResult is equal to (70, 100, 150, 220, 240, 352)   

                    //Displaying Results
                    syntaxString = " matrixResult = matrix1 * matrix2;";
                    resultType = "Matrix";
                    operationString = "Multiplying matrix1 and matrix2";
                    ShowResults(matrixResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }


                case "rb21":
                {
                    // Appends a skew to a Matrix
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    double skewAngleX = 45;
                    double skewAngleY = 180;
                    matrix1.Skew(skewAngleX, skewAngleY);
                    // matrix1 is equal to (15, 10, 35, 20, 55, 30)
                    //Displaying Results
                    syntaxString = "matrix1.Skew(skewAngleX, skewAngleY);";
                    resultType = "Void";
                    operationString = "Multiplying matrix2 and matrix1";
                    ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb22":
                {
                    // Prepends a skew to a Matrix
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    double skewAngleX = 45;
                    double skewAngleY = 180;
                    matrix1.SkewPrepend(skewAngleX, skewAngleY);
                    // matrix1 is equal to (5, 10, 20, 30, 25, 30)
                    //Displaying Results
                    syntaxString = "matrix1.SkewPrepend(skewAngleX, skewAngleY);";
                    resultType = "Void";
                    operationString = "Multiplying matrix2 and matrix1";
                    ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                    break;
                }


                case "rb23":
                {
                    // Appends a scale to a Matrix
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    double scaleFactorX = 2;
                    double scaleFactorY = 4;
                    matrix1.Scale(scaleFactorX, scaleFactorY);
                    // matrix1 is equal to (10, 40, 30, 80, 50, 120)
                    //Displaying Results
                    syntaxString = "matrix1.Scale(scaleFactorX, scaleFactorY);";
                    resultType = "Void";
                    operationString = "Appending a scale to a matrix";
                    ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb24":
                {
                    // Appends a scale at a specific point to a Matrix
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    matrix1.ScaleAt(2, 4, 5, 10);
                    // matrix1 is equal to (10, 40, 30, 80, 45, 90)
                    //Displaying Results
                    syntaxString = " matrix1.ScaleAt(scaleFactorX, scaleFactorY, scaleCenterX, scaleCenterY);";
                    resultType = "Void";
                    operationString = "Appends a scale at a specific point to matrix1";
                    ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb25":
                {
                    // Prepends a scale to a Matrix
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    double scaleFactorX = 2;
                    double scaleFactorY = 4;
                    matrix1.ScalePrepend(scaleFactorX, scaleFactorY);
                    // matrix1 is equal to (10, 20, 60, 80, 25, 30)
                    //Displaying Results
                    syntaxString = "matrix1.ScalePrepend(scaleFactorX, scaleFactorY);";
                    resultType = "Void";
                    operationString = "Prepending a scale to matrix1";
                    ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb26":
                {
                    // Prepends a scale at a specific point to a Matrix
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);

                    matrix1.ScaleAtPrepend(2, 4, 5, 10);
                    // matrix1 is equal to (10, 20, 60, 80, -450, -620)

                    //Displaying Results
                    syntaxString = "matrix1.ScalePrependAt(scaleFactorX, scaleFactorY, centerPointX, centerPointY);";
                    resultType = "Void";
                    operationString = "Prepending a scale at a specific point to matrix1";
                    ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb29":
                {
                    // Transform a point by a matrix
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    var point1 = new Point(15, 25);
                    var pointResult = new Point();

                    pointResult = matrix1.Transform(point1);
                    // pointResult is equal to (475, 680)

                    //Displaying Results
                    syntaxString = "pointResult = matrix1.Transform(point1)";
                    resultType = "Point";
                    operationString = "Transforming a point1 by matrix1";
                    ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb30":
                {
                    // Transform a Vector by a Matrix
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    var vector1 = new Vector(15, 25);
                    new Vector();

                    matrix1.Transform(vector1);
                    // vectorResult is equal to (450, 650)

                    //Displaying Results
                    syntaxString = "vectorResult = matrix1.Transform(vector1);";
                    resultType = "Vector";
                    operationString = "Multiplying matrix2 and matrix1";
                    ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                    break;
                }

                case "rb31":
                {
                    // Transform an array of Points by a Matrix

                    // Creating a Matrix and an array of Pointers
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    var pointArray = new Point[2];

                    // Setting the Point's X and Y values
                    pointArray[0].X = 15;
                    pointArray[0].Y = 25;
                    pointArray[1].X = 30;
                    pointArray[1].Y = 35;

                    // Transforming the Points in pointArry by matrix1
                    matrix1.Transform(pointArray);

                    // pointArray[0] is equal to (475, 680)
                    // pointArray[1] is equal to (700, 1030)

                    //Displaying Results
                    syntaxString = "matrix1.Transform(pointArray);";
                    resultType = "void";
                    operationString = "Transforming an array of Points by matrix1";
                    ShowResults(pointArray[1].ToString(), syntaxString, resultType, operationString);
                    break;
                }
                case "rb32":
                {
                    // Transform an array of Vectors by a Matrix

                    // Creating  a Matrix and an array of Vectors
                    var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                    var vectorArray = new Vector[2];

                    // Setting the Vector's X and Y values
                    vectorArray[0].X = 15;
                    vectorArray[0].Y = 25;
                    vectorArray[1].X = 30;
                    vectorArray[1].Y = 35;

                    // Transforming the Vectors in vectorArray by matrix1
                    matrix1.Transform(vectorArray);

                    // VectorArray[0] is equal to (450, 650)
                    // VectorArray[1] is equal to (675, 1000)

                    //Displaying Results
                    syntaxString = " matrix1.Transform(vectorArray);";
                    resultType = "Void";
                    operationString = "Multiplying matrix2 and matrix1";
                    ShowResults(vectorArray[0].ToString(), syntaxString, resultType, operationString);
                    break;
                }
            } // end switch
        }
コード例 #10
0
        public void PerformOperation(object sender, RoutedEventArgs e)
        {
            var    li = sender as RadioButton;
            string syntaxString, resultType, operationString;

            switch (li?.Name)
            {
            // begin switch


            case "rb1":
            {
                // Multiplies a Matrix by a Matrix using the overloaded * operator
                // Returns a Matrix
                var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);

                var isInvertible = matrix1.HasInverse;
                // isInvertible is equal to True

                // Displaying Results
                syntaxString    = "isInvertible = matrix1.HasInverse;";
                resultType      = "Boolean";
                operationString = "Checking if matrix1 is invertible";
                ShowResults(isInvertible.ToString(), syntaxString, resultType, operationString);

                break;
            }

            case "rb2":
            {
                // Translates a Matrix
                // Returns a Matrix
                var          matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                const double offsetX = 15;
                const double offsetY = 25;

                matrix1.Translate(offsetX, offsetY);
                // matrix1 is not equal to

                //Displaying Results
                syntaxString    = "matrix1.Translate(offsetX, offsetY);";
                resultType      = "Void";
                operationString = "Translating a Matrix by a Point";
                ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);

                break;
            }

            case "rb3":
            {
                // Prepend a Tranlsation to a Matrix
                // Returns a Matrix
                var          matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                const double offsetX = 15;
                const double offsetY = 25;

                matrix1.TranslatePrepend(offsetX, offsetY);
                // matrix1 is not equal to

                //Displaying Results
                syntaxString    = " matrix1.TranslatePrepend(offsetX, offsetY);";
                resultType      = "Void";
                operationString = "Prepending Translating a matrix";
                ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb4":
            {
                // Sets a Matrix to an identity matrix
                var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);

                matrix1.SetIdentity();
                // matrix1 is now equal to (1,0,0,1,0,0)

                //Displaying Results
                syntaxString    = "matrix1.SetIdentity();";
                resultType      = "Void";
                operationString = "Setting a matrix to an identity matrix";
                ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb5":
            {
                // Checks if a Matrix is an identity matrix
                // Creates a Matrix
                var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);

                // Sets matrix1 into an identity matrix
                matrix1.SetIdentity();

                var isIdentityMatrix = matrix1.IsIdentity;
                // isIdentityMatrix is equal to True

                //Displaying Results
                syntaxString    = "isIdentityMatrix = matrix1.IsIdentity;";
                resultType      = "Boolean";
                operationString = "Determining if a Matrix is an identity matrix";
                ShowResults(isIdentityMatrix.ToString(), syntaxString, resultType, operationString);
                break;
            }


            case "rb6":
            {
                // Changes a Matrix into an identity matrix
                var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                matrix1 = System.Windows.Media.Matrix.Identity;
                // matrix1 is now equal to (1,0,0,1,0,0)
                //Displaying Results
                syntaxString    = "matrix1 = Matrix.Identity;";
                resultType      = "Matrix";
                operationString = "Gets an identity Matrix";
                ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb7":
            {
                // Converts a string representation of a matrix into a Matrix structure
                var matrixResult = new System.Windows.Media.Matrix();

                matrixResult = System.Windows.Media.Matrix.Parse("1,2,3,4,5,6");
                // matrixResult is equal to (1,2,3,4,5,6)

                //Displaying Results
                syntaxString    = "matrixResult = Matrix.Parse(\"1,2,3,4,5,6\");";
                resultType      = "Matrix";
                operationString = "Convert a string into a Matrix structure";
                ShowResults(matrixResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb8":
            {
                // Checks if two Matrixes are equal using the static Equals method
                // Returns a Boolean.
                var matrix1  = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                var matrix2  = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12);
                var areEqual = System.Windows.Media.Matrix.Equals(matrix1, matrix2);
                // areEqual is equal to False

                //Displaying Results
                syntaxString    = "areEqual = Matrix.Equals(matrix1, matrix2);";
                resultType      = "Boolean";
                operationString = "Checking if the matrices are equal";
                ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);

                break;
            }

            case "rb8b":
            {
                // Checks if an Object is equal to a Matrix using the static Equals method
                // Returns a Boolean.
                var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12);

                var areEqual = matrix1.Equals(matrix2);
                // areEqual is equal to False

                //Displaying Results
                syntaxString    = "areEqual = Matrix.Equals(matrix1, matrix2);";
                resultType      = "Boolean";
                operationString = "Checking if the matrices are equal";
                ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);

                break;
            }

            case "rb9":
            {
                // Checks if two Matrixes are equal using the overloaded == operator
                // Returns a Boolean.
                var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12);

                var areEqual = matrix1 == matrix2;
                // areEqual is equal to False

                //Displaying Results
                syntaxString    = "areEqual = matrix1 == matrix2;";
                resultType      = "Boolean";
                operationString = "Checking if the matrices are equal";
                ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb10":
            {
                // Checks if two Matrixes are not equal using the overloaded != operator
                // Returns a Boolean.
                var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12);

                var areEqual = matrix1 != matrix2;
                // areEqual is equal to False

                //Displaying Results
                syntaxString    = "areEqual = matrix1 != matrix2;";
                resultType      = "Boolean";
                operationString = "Checking if the matrices are not equal";
                ShowResults(areEqual.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb11":
            {
                // Inverts a Matrix
                // Creating a Matrix structure
                var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                // Checking if matrix1 is invertible
                if (matrix1.HasInverse)
                {
                    // Inverting matrix1
                    matrix1.Invert();
                    // matrix1 is equal to (-0.04, 0.2 , 0.3, -0.1, 1, -2)
                }
                //Displaying Results
                syntaxString    = "matrix1.Invert();";
                resultType      = "Void";
                operationString = "Inverting a matrix";
                ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb12":
            {
                // Prepends a Matrix to another Matrix.
                var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12);
                matrix1.Prepend(matrix2);
                // matrix1 is equal to (70,100,150,220,255,370)
                //Displaying Results
                syntaxString    = "matrix1.Prepend(matrix2);";
                resultType      = "Void";
                operationString = "Prepending a Matrix to another Matrix";
                ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb13":
            {
                // Appends a Matrix to another Matrix
                var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                var matrix2 = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12);
                matrix1.Append(matrix2);
                // matrix1 is equal to (70,100,150,220,240,352)
                //Displaying Results
                syntaxString    = "matrix1.Append(matrix2);";
                resultType      = "Void";
                operationString = "Appending a Matrix to another Matrix";
                ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb14":
            {
                // Rotates a Matrix by a specified angle
                var    matrix1     = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                double rotateAngle = 90;

                matrix1.Rotate(rotateAngle);
                // matrix1 is equal to (-10,5,-20,15,-30,25)

                //Displaying Results
                syntaxString    = "matrix1.Rotate(rotateAngle);";
                resultType      = "Void";
                operationString = "Rotating a Matrix";
                ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb15":
            {
                // Rotates a Matrix by a specified angle at a specific point
                var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                matrix1.RotateAt(90, 2, 4);
                // matrix1 is equal to (-10,5,-20,15,-24,27)
                //Displaying Results
                syntaxString    = "matrix1.RotateAt(rotateAngle, rotateCenterX, rotateCenterY);";
                resultType      = "Void";
                operationString = "Rotating a Matrix";
                ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb16":
            {
                // Prepends a Rotation to a Matrix
                var    matrix1     = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                double rotateAngle = 90;
                matrix1.RotatePrepend(rotateAngle);
                // matrix1 is equal to (15,20,-5,-10,25,30)
                //Displaying Results
                syntaxString    = "matrix1.RotatePrepend(rotateAngle);";
                resultType      = "Void";
                operationString = "Rotating a Matrix";
                ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb17":
            {
                // Prepends a Rotation at a specific point to a Matrix
                var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                matrix1.RotateAtPrepend(90, 2, 4);
                // matrix1 is equal to  (15,20,-5,-10,85,130)
                //Displaying Results
                syntaxString    = "matrix1.RotateAtPrepend(rotateAngle, rotateCenterX, rotateCenterY);";
                resultType      = "Void";
                operationString = "Rotating a Matrix";
                ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb18":
            {
                // Scales a Matrix
                var    matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                double scaleX  = (1);
                double scaleY  = (2);

                matrix1.Scale(scaleX, scaleY);
                // matrix1 is equal to

                //Displaying Results
                syntaxString    = "matrix1.Scale(scaleX, scaleY);";
                resultType      = "Void";
                operationString = "Scaling a Matrix";
                ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb19":
            {
                // Multiplies a Matrix by another Matrix
                var matrix1      = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                var matrix2      = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12);
                var matrixResult = new System.Windows.Media.Matrix();

                matrixResult = System.Windows.Media.Matrix.Multiply(matrix2, matrix1);
                // matrixResult is equal to (70, 100, 150, 220, 255, 370)

                //Displaying Results
                syntaxString    = "matrixResult = Matrix.Multiply(matrix2, matrix1);";
                resultType      = "Matrix";
                operationString = "Multiplying matrix1 and matrix2";
                ShowResults(matrixResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb20":
            {
                // Multiplies a Matrix by another Matrix using the overloaded * operator
                var matrix1      = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                var matrix2      = new System.Windows.Media.Matrix(2, 4, 6, 8, 10, 12);
                var matrixResult = new System.Windows.Media.Matrix();

                matrixResult = matrix1 * matrix2;
                // matrixResult is equal to (70, 100, 150, 220, 240, 352)

                //Displaying Results
                syntaxString    = " matrixResult = matrix1 * matrix2;";
                resultType      = "Matrix";
                operationString = "Multiplying matrix1 and matrix2";
                ShowResults(matrixResult.ToString(), syntaxString, resultType, operationString);
                break;
            }


            case "rb21":
            {
                // Appends a skew to a Matrix
                var    matrix1    = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                double skewAngleX = 45;
                double skewAngleY = 180;
                matrix1.Skew(skewAngleX, skewAngleY);
                // matrix1 is equal to (15, 10, 35, 20, 55, 30)
                //Displaying Results
                syntaxString    = "matrix1.Skew(skewAngleX, skewAngleY);";
                resultType      = "Void";
                operationString = "Multiplying matrix2 and matrix1";
                ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb22":
            {
                // Prepends a skew to a Matrix
                var    matrix1    = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                double skewAngleX = 45;
                double skewAngleY = 180;
                matrix1.SkewPrepend(skewAngleX, skewAngleY);
                // matrix1 is equal to (5, 10, 20, 30, 25, 30)
                //Displaying Results
                syntaxString    = "matrix1.SkewPrepend(skewAngleX, skewAngleY);";
                resultType      = "Void";
                operationString = "Multiplying matrix2 and matrix1";
                ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                break;
            }


            case "rb23":
            {
                // Appends a scale to a Matrix
                var    matrix1      = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                double scaleFactorX = 2;
                double scaleFactorY = 4;
                matrix1.Scale(scaleFactorX, scaleFactorY);
                // matrix1 is equal to (10, 40, 30, 80, 50, 120)
                //Displaying Results
                syntaxString    = "matrix1.Scale(scaleFactorX, scaleFactorY);";
                resultType      = "Void";
                operationString = "Appending a scale to a matrix";
                ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb24":
            {
                // Appends a scale at a specific point to a Matrix
                var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                matrix1.ScaleAt(2, 4, 5, 10);
                // matrix1 is equal to (10, 40, 30, 80, 45, 90)
                //Displaying Results
                syntaxString    = " matrix1.ScaleAt(scaleFactorX, scaleFactorY, scaleCenterX, scaleCenterY);";
                resultType      = "Void";
                operationString = "Appends a scale at a specific point to matrix1";
                ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb25":
            {
                // Prepends a scale to a Matrix
                var    matrix1      = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                double scaleFactorX = 2;
                double scaleFactorY = 4;
                matrix1.ScalePrepend(scaleFactorX, scaleFactorY);
                // matrix1 is equal to (10, 20, 60, 80, 25, 30)
                //Displaying Results
                syntaxString    = "matrix1.ScalePrepend(scaleFactorX, scaleFactorY);";
                resultType      = "Void";
                operationString = "Prepending a scale to matrix1";
                ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb26":
            {
                // Prepends a scale at a specific point to a Matrix
                var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);

                matrix1.ScaleAtPrepend(2, 4, 5, 10);
                // matrix1 is equal to (10, 20, 60, 80, -450, -620)

                //Displaying Results
                syntaxString    = "matrix1.ScalePrependAt(scaleFactorX, scaleFactorY, centerPointX, centerPointY);";
                resultType      = "Void";
                operationString = "Prepending a scale at a specific point to matrix1";
                ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb29":
            {
                // Transform a point by a matrix
                var matrix1     = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                var point1      = new Point(15, 25);
                var pointResult = new Point();

                pointResult = matrix1.Transform(point1);
                // pointResult is equal to (475, 680)

                //Displaying Results
                syntaxString    = "pointResult = matrix1.Transform(point1)";
                resultType      = "Point";
                operationString = "Transforming a point1 by matrix1";
                ShowResults(pointResult.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb30":
            {
                // Transform a Vector by a Matrix
                var matrix1 = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                var vector1 = new Vector(15, 25);
                new Vector();

                matrix1.Transform(vector1);
                // vectorResult is equal to (450, 650)

                //Displaying Results
                syntaxString    = "vectorResult = matrix1.Transform(vector1);";
                resultType      = "Vector";
                operationString = "Multiplying matrix2 and matrix1";
                ShowResults(matrix1.ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb31":
            {
                // Transform an array of Points by a Matrix

                // Creating a Matrix and an array of Pointers
                var matrix1    = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                var pointArray = new Point[2];

                // Setting the Point's X and Y values
                pointArray[0].X = 15;
                pointArray[0].Y = 25;
                pointArray[1].X = 30;
                pointArray[1].Y = 35;

                // Transforming the Points in pointArry by matrix1
                matrix1.Transform(pointArray);

                // pointArray[0] is equal to (475, 680)
                // pointArray[1] is equal to (700, 1030)

                //Displaying Results
                syntaxString    = "matrix1.Transform(pointArray);";
                resultType      = "void";
                operationString = "Transforming an array of Points by matrix1";
                ShowResults(pointArray[1].ToString(), syntaxString, resultType, operationString);
                break;
            }

            case "rb32":
            {
                // Transform an array of Vectors by a Matrix

                // Creating  a Matrix and an array of Vectors
                var matrix1     = new System.Windows.Media.Matrix(5, 10, 15, 20, 25, 30);
                var vectorArray = new Vector[2];

                // Setting the Vector's X and Y values
                vectorArray[0].X = 15;
                vectorArray[0].Y = 25;
                vectorArray[1].X = 30;
                vectorArray[1].Y = 35;

                // Transforming the Vectors in vectorArray by matrix1
                matrix1.Transform(vectorArray);

                // VectorArray[0] is equal to (450, 650)
                // VectorArray[1] is equal to (675, 1000)

                //Displaying Results
                syntaxString    = " matrix1.Transform(vectorArray);";
                resultType      = "Void";
                operationString = "Multiplying matrix2 and matrix1";
                ShowResults(vectorArray[0].ToString(), syntaxString, resultType, operationString);
                break;
            }
            } // end switch
        }
コード例 #11
0
ファイル: WindowRenderer.cs プロジェクト: netgrim/MapKit
        public override void Render(Feature feature)
        {
            if (_recursion > _window.MaxRecursion)
                return;
            RenderCount++;

            var geometry = feature.Geometry;
            //geometry = geometry.Envelope;

            if (geometry.OgcGeometryType != OgcGeometryType.Polygon &&
                geometry.OgcGeometryType != OgcGeometryType.MultiPolygon)
                return;

            if (feature.Fid != 6306)
                return;
            
            //evaluate fields
            var centerX = Evaluate(_centerXEvaluator, _centerX);
            var centerY = Evaluate(_centerYEvaluator, _centerY);
            var zoom = Evaluate(_zoomEvaluator, _zoom);
            var angle = Evaluate(_angleEvaluator, _angle);
            
            var centroid = geometry.Centroid.ToWinPoint();

            //temporary debug value
            //_zoom = (_zoom + 10) % 360;
            //centerX = centroid.X + 25;
            //centerY = centroid.Y;
            //zoom = 0.5;
            //angle = -_zoom;
            
            //clip path coordinates      
            var coordinates = ToWinPointArray(geometry.Coordinates);
            Renderer.Transform(coordinates);
            var coordinatesF = coordinates.ToPointFArray();
            var clipPath = new GraphicsPath();
            clipPath.AddPolygon(coordinatesF);

            //camera transform
            var camera = new WinMatrix();
            camera.Translate(-centroid.X, -centroid.Y);
            camera.Scale(1/zoom, 1/zoom);
            camera.Rotate(-angle);
            camera.Translate(centerX, centerY);

            //camera polygon
            coordinates = ToWinPointArray(geometry.Coordinates);
            camera.Transform(coordinates);

            var queryWindow = new Envelope();
            ExpendToInclude(queryWindow, coordinates);

            var oldMatrix = Renderer.Matrix;
            var invCamera = camera;
            invCamera.Invert();
            var newMatrix = invCamera * oldMatrix;

            var newTranslate = newMatrix;
            newTranslate.OffsetX = newTranslate.OffsetY = 0;
            newTranslate.Invert();
            newTranslate = newMatrix * newTranslate;

            Feature queryFeature = null;
            Feature windowTargetFeature = null;
            var newTransform = new System.Drawing.Drawing2D.Matrix((float)newMatrix.M11, (float)newMatrix.M12, (float)newMatrix.M21, (float)newMatrix.M22, 0f, 0f);
            var oldWindow = Renderer.Window;
            var savedState = Renderer.Graphics.Save();
            var oldModelView = Renderer.Translate;
            var oldZoom = Renderer.Zoom;
            //var oldAngle = Renderer.Angle;
            
            _recursion++;

            int i = 0;
            while (i < Renderers.Count)
            {
                var renderer = Renderers[i];
                var childNode = renderer.Node;
                if (childNode is WindowQuery)
                {
                    if (queryFeature == null)
                    {
                        queryFeature = new Feature(feature);
                        queryFeature.Geometry = Util.ToPolygon(queryWindow);
                    }

                    do
                        renderer.Render(queryFeature);
                    while (++i < Renderers.Count && (childNode = (renderer = Renderers[i]).Node) is WindowQuery);
                }
                else if (childNode is WindowTarget)
                {
                    if (windowTargetFeature == null)
                    {
                        windowTargetFeature = new Feature(feature);
                        windowTargetFeature.Geometry = new Polygon(new LinearRing(ToCoordinateArray(coordinates)));
                    }

                    do
                        renderer.Render(windowTargetFeature);
                    while (++i < Renderers.Count && (childNode = (renderer = Renderers[i]).Node) is WindowTarget);
                }
                else
                {
                    try
                    {
                        Renderer.Window = queryWindow;
                        if (_window.Clip)
                        {
                            var region = Renderer.Graphics.Clip;
                            if (region != null)
                            {
                                region.Intersect(clipPath);
                                Renderer.Graphics.Clip = region;
                            }
                            else
                                Renderer.Graphics.SetClip(clipPath);
                        }

                        Renderer.Matrix = newMatrix;
                        Renderer.Translate = newTranslate;
                        Renderer.Graphics.Transform = newTransform;
                        Renderer.Zoom *= zoom;
                        //Renderer.Angle += angle;

                        //Renderer.Graphics.Clear(Evaluate(_bgColorEvaluator, _bgColor));

                        do
                            renderer.Render(feature);
                        while (++i < Renderers.Count && !((childNode = (renderer = Renderers[i]).Node) is WindowQuery || childNode is WindowTarget));
                    }
                    finally
                    {
                        Renderer.Window = oldWindow;
                        Renderer.Graphics.Restore(savedState);
                        Renderer.Translate = oldModelView;
                        Renderer.Zoom = oldZoom;
                        //Renderer.Angle = oldAngle;
                        Renderer.Matrix = oldMatrix;
                        _recursion--;
                    }
                }
            }

            ////debug: render camera polygon
            //Renderer.Transform(coordinates);
            //coordinatesF = coordinates.ToPointFArray();
            //using (var brush = new SolidBrush(Color.FromArgb(50, Color.Red)))
            //    Renderer.Graphics.FillPolygon(brush, coordinatesF);

            ////debug: render camera envelope
            //var points = new[] { new WinPoint(queryWindow.MinX, queryWindow.MinY), new WinPoint(queryWindow.MaxX, queryWindow.MaxY) };
            //Renderer.Transform(points);
            //var size = points[1] - points[0];
            //using (var brush = new SolidBrush(Color.FromArgb(50, Color.Green)))
            //    Renderer.Graphics.FillRectangle(brush, (float)points[0].X, (float)points[0].Y, (float)size.X, (float)size.Y);
        }
コード例 #12
0
ファイル: Vector.cs プロジェクト: kobbst/X11_Xlib
 /// <summary>Transform the coordinate space of the specified vector using the specified
 /// System.Windows.Media.Matrix.</summary>
 /// <param name="vector">The vector structure to transform.<see cref="System.Windows.Vector"/></param>
 /// <param name="matrix">The transformation to apply to vector.<see cref="Matrix"/></param>
 /// <returns>The result of transforming vector by matrix.<see cref="System.Windows.Vector"/></returns>
 public static System.Windows.Vector Multiply(System.Windows.Vector vector, System.Windows.Media.Matrix matrix)
 {
     return(matrix.Transform(vector));
 }
コード例 #13
0
ファイル: Point.cs プロジェクト: kobbst/X11_Xlib
 /// <summary>Transform the specified System.Windows.Point structure by the specified
 /// System.Windows.Media.Matrix structure.</summary>
 /// <param name="point">The point to transform.<see cref="System.Windows.Point"/></param>
 /// <param name="matrix">The transformation matrix.<see cref="System.Windows.Media.Matrix"/></param>
 /// <returns>The transformed point.<see cref="Point"/></returns>
 public static System.Windows.Point Multiply(System.Windows.Point point, System.Windows.Media.Matrix matrix)
 {
     return(matrix.Transform(point));
 }