Esempio n. 1
0
 public static bool Equals(MatrixF matrix1, MatrixF matrix2)
 {
     if (matrix1.IsDistinguishedIdentity || matrix2.IsDistinguishedIdentity)
     {
         return(matrix1.IsIdentity == matrix2.IsIdentity);
     }
     else
     {
         return(matrix1.M11.Equals(matrix2.M11) &&
                matrix1.M12.Equals(matrix2.M12) &&
                matrix1.M21.Equals(matrix2.M21) &&
                matrix1.M22.Equals(matrix2.M22) &&
                matrix1.OffsetX.Equals(matrix2.OffsetX) &&
                matrix1.OffsetY.Equals(matrix2.OffsetY));
     }
 }
Esempio n. 2
0
        internal static MatrixF CreateRotationRadians(Float angle, Float centerX, Float centerY)
        {
            MatrixF matrix = new MatrixF();

            Float sin = (Float)Math.Sin(angle);
            Float cos = (Float)Math.Cos(angle);
            Float dx  = (centerX * (1.0F - cos)) + (centerY * sin);
            Float dy  = (centerY * (1.0F - cos)) - (centerX * sin);

            matrix.SetMatrix(cos, sin,
                             -sin, cos,
                             dx, dy,
                             MatrixTypes.TRANSFORM_IS_UNKNOWN);

            return(matrix);
        }
Esempio n. 3
0
        internal void Pop()
        {
            var t = _transforms.Pop();

            if (t is MatrixF)
            {
                var m = (MatrixF)t;
                m.Invert();
                _matrix *= m;
            }
            if (t is float)
            {
                var d = (float)t;
                _opacity = 1;
                foreach (float item in _transforms.TakeWhile(_t => _t is float))
                {
                    _opacity *= item;
                }
            }
        }
Esempio n. 4
0
        private void _OnRenderSizeChanged(float width, float height)
        {
            MakeSureCurrentContext(_context);

            _worldToNDC = new MatrixF();
            _worldToNDC.Translate(_origin.X, _origin.Y);
            _worldToNDC.Scale(2 / width, 2 / height);
            _worldToNDC.Translate(-1, -1);
            _viewWidth  = (int)(width * _transformToDevice.M11);
            _viewHeight = (int)(height * _transformToDevice.M22);

            Viewport(0, 0, _viewWidth, _viewHeight);

            // for dashed line
            _lineshader.Use();
            _lineshader.SetVec2("screenSize", 1, new float[] { width, height });

            // for dashed cicle and arc
            _arcshader.Use();
            _arcshader.SetVec2("screenSize", 1, new float[] { width, height });
        }
Esempio n. 5
0
        private void _Init()
        {
            if (_isInit)
            {
                return;
            }
            _isInit = true;

            _transformToDevice = (MatrixF)PresentationSource.FromVisual(this).CompositionTarget.TransformToDevice;
            _context           = CreateContextCurrent(Handle);

            Init();
            Enable(GL_BLEND);
            Enable(GL_LINE_WIDTH);
            //Enable(GL_LINE_SMOOTH);
            Enable(GL_FRAMEBUFFER_SRGB); // Gamma Correction
            BlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
            StencilMask(1);
            _CreateResource();

            //_timer.Start(Timeout.Infinite, Timeout.Infinite);
        }
Esempio n. 6
0
 public void ResetView(bool isRefresh = true)
 {
     _view = MatrixF.Identity;
     _AfterTransform(isRefresh);
 }
Esempio n. 7
0
 public static VectorF Multiply(VectorF vector, MatrixF matrix)
 {
     return(matrix.Transform(vector));
 }
Esempio n. 8
0
 internal void PushTransform(MatrixF mat)
 {
     _Push(mat);
 }
Esempio n. 9
0
 private void _Push(MatrixF matrix)
 {
     _transforms.Push(matrix);
     _matrix *= matrix;
 }
Esempio n. 10
0
        internal static void TransformRect(ref RectF rect, ref MatrixF matrix)
        {
            if (rect.IsEmpty)
            {
                return;
            }

            MatrixTypes matrixType = matrix._type;

            // If the matrix is identity, don't worry.
            if (matrixType == MatrixTypes.TRANSFORM_IS_IDENTITY)
            {
                return;
            }

            // Scaling
            if (0 != (matrixType & MatrixTypes.TRANSFORM_IS_SCALING))
            {
                rect._x      *= matrix._m11;
                rect._y      *= matrix._m22;
                rect._width  *= matrix._m11;
                rect._height *= matrix._m22;

                // Ensure the width is always positive.  For example, if there was a reflection about the
                // y axis followed by a translation into the visual area, the width could be negative.
                if (rect._width < 0.0)
                {
                    rect._x    += rect._width;
                    rect._width = -rect._width;
                }

                // Ensure the height is always positive.  For example, if there was a reflection about the
                // x axis followed by a translation into the visual area, the height could be negative.
                if (rect._height < 0.0F)
                {
                    rect._y     += rect._height;
                    rect._height = -rect._height;
                }
            }

            // Translation
            if (0 != (matrixType & MatrixTypes.TRANSFORM_IS_TRANSLATION))
            {
                // X
                rect._x += matrix._offsetX;

                // Y
                rect._y += matrix._offsetY;
            }

            if (matrixType == MatrixTypes.TRANSFORM_IS_UNKNOWN)
            {
                // Al Bunny implementation.
                PointF point0 = matrix.Transform(rect.TopLeft);
                PointF point1 = matrix.Transform(rect.TopRight);
                PointF point2 = matrix.Transform(rect.BottomRight);
                PointF point3 = matrix.Transform(rect.BottomLeft);

                // Width and height is always positive here.
                rect._x = Math.Min(Math.Min(point0.X, point1.X), Math.Min(point2.X, point3.X));
                rect._y = Math.Min(Math.Min(point0.Y, point1.Y), Math.Min(point2.Y, point3.Y));

                rect._width  = Math.Max(Math.Max(point0.X, point1.X), Math.Max(point2.X, point3.X)) - rect._x;
                rect._height = Math.Max(Math.Max(point0.Y, point1.Y), Math.Max(point2.Y, point3.Y)) - rect._y;
            }
        }
Esempio n. 11
0
 public static RectF Transform(RectF rect, MatrixF matrix)
 {
     MathUtil.TransformRect(ref rect, ref matrix);
     return(rect);
 }
Esempio n. 12
0
 public bool Equals(MatrixF value)
 {
     return(MatrixF.Equals(this, value));
 }
Esempio n. 13
0
 public void Prepend(MatrixF matrix)
 {
     this = matrix * this;
 }
Esempio n. 14
0
 public void Append(MatrixF matrix)
 {
     this *= matrix;
 }
Esempio n. 15
0
 public static PointF Multiply(PointF point, MatrixF matrix)
 {
     return(matrix.Transform(point));
 }
Esempio n. 16
0
 public void PushTransform(MatrixF mat)
 {
     _transform.PushTransform(mat);
 }
Esempio n. 17
0
 internal StackTransform()
 {
     _opacity    = 1;
     _matrix     = new MatrixF();
     _transforms = new Stack <object>();
 }
Esempio n. 18
0
 public void Transform(MatrixF matrix)
 {
     MathUtil.TransformRect(ref this, ref matrix);
 }
Esempio n. 19
0
        internal static void MultiplyMatrix(ref MatrixF matrix1, ref MatrixF matrix2)
        {
            MatrixTypes type1 = matrix1._type;
            MatrixTypes type2 = matrix2._type;

            // Check for idents

            // If the second is ident, we can just return
            if (type2 == MatrixTypes.TRANSFORM_IS_IDENTITY)
            {
                return;
            }

            // If the first is ident, we can just copy the memory across.
            if (type1 == MatrixTypes.TRANSFORM_IS_IDENTITY)
            {
                matrix1 = matrix2;
                return;
            }

            // Optimize for translate case, where the second is a translate
            if (type2 == MatrixTypes.TRANSFORM_IS_TRANSLATION)
            {
                // 2 additions
                matrix1._offsetX += matrix2._offsetX;
                matrix1._offsetY += matrix2._offsetY;

                // If matrix 1 wasn't unknown we added a translation
                if (type1 != MatrixTypes.TRANSFORM_IS_UNKNOWN)
                {
                    matrix1._type |= MatrixTypes.TRANSFORM_IS_TRANSLATION;
                }

                return;
            }

            // Check for the first value being a translate
            if (type1 == MatrixTypes.TRANSFORM_IS_TRANSLATION)
            {
                // Save off the old offsets
                float offsetX = matrix1._offsetX;
                float offsetY = matrix1._offsetY;

                // Copy the matrix
                matrix1 = matrix2;

                matrix1._offsetX = offsetX * matrix2._m11 + offsetY * matrix2._m21 + matrix2._offsetX;
                matrix1._offsetY = offsetX * matrix2._m12 + offsetY * matrix2._m22 + matrix2._offsetY;

                if (type2 == MatrixTypes.TRANSFORM_IS_UNKNOWN)
                {
                    matrix1._type = MatrixTypes.TRANSFORM_IS_UNKNOWN;
                }
                else
                {
                    matrix1._type = MatrixTypes.TRANSFORM_IS_SCALING | MatrixTypes.TRANSFORM_IS_TRANSLATION;
                }
                return;
            }

            // The following code combines the type of the transformations so that the high nibble
            // is "this"'s type, and the low nibble is mat's type.  This allows for a switch rather
            // than nested switches.

            // trans1._type |  trans2._type
            //  7  6  5  4   |  3  2  1  0
            int combinedType = ((int)type1 << 4) | (int)type2;

            switch (combinedType)
            {
            case 34:      // S * S
                // 2 multiplications
                matrix1._m11 *= matrix2._m11;
                matrix1._m22 *= matrix2._m22;
                return;

            case 35:      // S * S|T
                matrix1._m11    *= matrix2._m11;
                matrix1._m22    *= matrix2._m22;
                matrix1._offsetX = matrix2._offsetX;
                matrix1._offsetY = matrix2._offsetY;

                // Transform set to Translate and Scale
                matrix1._type = MatrixTypes.TRANSFORM_IS_TRANSLATION | MatrixTypes.TRANSFORM_IS_SCALING;
                return;

            case 50:     // S|T * S
                matrix1._m11     *= matrix2._m11;
                matrix1._m22     *= matrix2._m22;
                matrix1._offsetX *= matrix2._m11;
                matrix1._offsetY *= matrix2._m22;
                return;

            case 51:     // S|T * S|T
                matrix1._m11    *= matrix2._m11;
                matrix1._m22    *= matrix2._m22;
                matrix1._offsetX = matrix2._m11 * matrix1._offsetX + matrix2._offsetX;
                matrix1._offsetY = matrix2._m22 * matrix1._offsetY + matrix2._offsetY;
                return;

            case 36:     // S * U
            case 52:     // S|T * U
            case 66:     // U * S
            case 67:     // U * S|T
            case 68:     // U * U
                matrix1 = new MatrixF(
                    matrix1._m11 * matrix2._m11 + matrix1._m12 * matrix2._m21,
                    matrix1._m11 * matrix2._m12 + matrix1._m12 * matrix2._m22,

                    matrix1._m21 * matrix2._m11 + matrix1._m22 * matrix2._m21,
                    matrix1._m21 * matrix2._m12 + matrix1._m22 * matrix2._m22,

                    matrix1._offsetX * matrix2._m11 + matrix1._offsetY * matrix2._m21 + matrix2._offsetX,
                    matrix1._offsetX * matrix2._m12 + matrix1._offsetY * matrix2._m22 + matrix2._offsetY);
                return;
            }
        }