Пример #1
0
        /// <summary>
        /// Map the transform into a Matrix describing this transformation
        /// </summary>
        /// <returns>(double[])The generated Matrix (x1,y1,x2,y2,offset1,offset2) </returns>
        public Matrix2D ConvertTransformsToMatrix()
        {
            Matrix2D matrix = new Matrix2D();

            foreach (DrawingTransform transform in _transformList)
            {
                switch (transform.TransformType)
                {
                case TranformType.Translate:
                    matrix.T1 += transform.Data[0];
                    matrix.T2 += transform.Data[1];
                    break;

                case TranformType.Scale:
                    matrix.X1 *= transform.Data[0];
                    matrix.Y1 *= transform.Data[0];
                    matrix.T1 *= transform.Data[0];
                    matrix.X2 *= transform.Data[1];
                    matrix.Y2 *= transform.Data[1];
                    matrix.T2 *= transform.Data[1];
                    break;

                case TranformType.Rotate:
                    double   angle = transform.Data[0];
                    double   sin   = Math.Sin(angle);
                    double   cos   = Math.Cos(angle);
                    Matrix2D temp  = (Matrix2D)matrix.Clone();
                    matrix.X1 = temp.X1 * cos + temp.X2 * sin;
                    matrix.X2 = temp.Y1 * cos + temp.Y2 * sin;
                    matrix.T1 = temp.T1 * cos + temp.T2 * sin;
                    matrix.Y1 = -temp.X1 * sin + temp.X2 * cos;
                    matrix.Y2 = -temp.Y1 * sin + temp.Y2 * cos;
                    matrix.T2 = -temp.T1 * sin + temp.T2 * cos;
                    break;

                default:
                    throw new RenderingVerificationException("Unsupported transform type passed in");
                }
            }
            return(matrix);
        }
Пример #2
0
        /// <summary>
        /// Perform all Transformation from the list
        /// </summary>
        /// <returns>The resulting matrix after all the transform</returns>
        public double[] ApplyTransforms()
        {
//                    double[] matrix = new double[] { 1f, 0f, 0f, 1f, 0f, 0f };
            Matrix2D matrix = new Matrix2D();

            foreach (DrawingTransform transform in _transformList)
            {
                switch (transform.TransformType)
                {
                case TranformType.Translate:
                    matrix.T1 += transform.Data[0];
                    matrix.T2 += transform.Data[1];
//                                matrix[4] += transform.Data[0];
//                                matrix[5] += transform.Data[1];
                    break;

                case TranformType.Scale:
                    matrix.X1 *= transform.Data[0];
                    matrix.Y1 *= transform.Data[0];
                    matrix.T1 *= transform.Data[0];
                    matrix.X2 *= transform.Data[1];
                    matrix.Y2 *= transform.Data[1];
                    matrix.T2 *= transform.Data[1];
//                                matrix[0] *= transform.Data[0];
//                                matrix[1] *= transform.Data[0];
//                                matrix[4] *= transform.Data[1];
//                                matrix[2] *= transform.Data[1];
//                                matrix[3] *= transform.Data[1];
//                                matrix[5] *= transform.Data[0];
                    break;

                case TranformType.Rotate:
                    double angle = transform.Data[0];
                    double sin   = Math.Sin(angle);
                    double cos   = Math.Cos(angle);

                    Matrix2D temp = (Matrix2D)matrix.Clone();
                    matrix.X1 = temp.X1 * cos + temp.X2 * sin;
                    matrix.X2 = temp.Y1 * cos + temp.Y2 * sin;
                    matrix.T1 = temp.T1 * cos + temp.T2 * sin;
                    matrix.Y1 = -temp.X1 * sin + temp.X2 * cos;
                    matrix.Y2 = -temp.Y1 * sin + temp.Y2 * cos;
                    matrix.T2 = -temp.T1 * sin + temp.T2 * cos;

//                                double[] temp = (double[])matrix.Clone();
//
//                                matrix[0] = temp[0] * cos - temp[2] * sin;
//                                matrix[1] = temp[1] * cos - temp[3] * sin;
//                                matrix[4] = temp[4] * cos - temp[5] * sin;
//                                matrix[2] = temp[0] * sin + temp[2] * cos;
//                                matrix[3] = temp[1] * sin + temp[3] * cos;
//                                matrix[5] = temp[4] * sin + temp[5] * cos;
                    break;

                default:
                    throw new Exception("Unsupported transform type passed in");
                }
            }

            Matrix = matrix;
            return(matrix);
        }