Пример #1
0
        /// <summary>
        /// Applies a transformation to the current DrawInfo.
        /// </summary>
        /// <param name="target">The DrawInfo instance to be filled with the result.</param>
        /// <param name="translation">The amount by which to translate the current position.</param>
        /// <param name="scale">The amount by which to scale.</param>
        /// <param name="rotation">The amount by which to rotate.</param>
        /// <param name="origin">The center of rotation and scale.</param>
        /// <param name="shear">The shear amounts for both directions.</param>
        /// <param name="colour">An optional color to be applied multiplicatively.</param>
        /// <param name="blending">An optional blending change.</param>
        public void ApplyTransform(ref DrawInfo target, Vector2 translation, Vector2 scale, float rotation, Vector2 shear, Vector2 origin, ColourInfo?colour = null, BlendingInfo?blending = null)
        {
            target.Matrix        = Matrix;
            target.MatrixInverse = MatrixInverse;

            if (translation != Vector2.Zero)
            {
                MatrixExtensions.TranslateFromLeft(ref target.Matrix, translation);
                MatrixExtensions.TranslateFromRight(ref target.MatrixInverse, -translation);
            }

            if (rotation != 0)
            {
                float radians = MathHelper.DegreesToRadians(rotation);
                MatrixExtensions.RotateFromLeft(ref target.Matrix, radians);
                MatrixExtensions.RotateFromRight(ref target.MatrixInverse, -radians);
            }

            if (shear != Vector2.Zero)
            {
                MatrixExtensions.ShearFromLeft(ref target.Matrix, -shear);
                MatrixExtensions.ShearFromRight(ref target.MatrixInverse, shear);
            }

            if (scale != Vector2.One)
            {
                Vector2 inverseScale = new Vector2(1.0f / scale.X, 1.0f / scale.Y);
                MatrixExtensions.ScaleFromLeft(ref target.Matrix, scale);
                MatrixExtensions.ScaleFromRight(ref target.MatrixInverse, inverseScale);
            }

            if (origin != Vector2.Zero)
            {
                MatrixExtensions.TranslateFromLeft(ref target.Matrix, -origin);
                MatrixExtensions.TranslateFromRight(ref target.MatrixInverse, origin);
            }

            //========================================================================================
            //== Uncomment the following 2 lines to use a ground-truth matrix inverse for debugging ==
            //========================================================================================
            //target.MatrixInverse = target.Matrix;
            //MatrixExtensions.FastInvert(ref target.MatrixInverse);

            if (colour != null)
            {
                target.Colour = new ColourInfo(ref this, colour.Value);
            }
            else
            {
                target.Colour = Colour;
            }

            target.Blending = blending == null ? Blending : blending.Value;
        }
Пример #2
0
        /// <summary>
        /// Applies a transformation to the current DrawInfo.
        /// </summary>
        /// <param name="target">The DrawInfo instance to be filled with the result.</param>
        /// <param name="translation">The amount by which to translate the current position.</param>
        /// <param name="scale">The amount by which to scale.</param>
        /// <param name="rotation">The amount by which to rotate.</param>
        /// <param name="origin">The center of rotation and scale.</param>
        /// <param name="colour">An optional color to be applied multiplicatively.</param>
        /// <param name="blending">An optional blending change.</param>
        public void ApplyTransform(ref DrawInfo target, Vector2 translation, Vector2 scale, float rotation, Vector2 origin, Color4?colour = null, BlendingInfo?blending = null)
        {
            target.Matrix        = Matrix;
            target.MatrixInverse = MatrixInverse;

            if (translation != Vector2.Zero)
            {
                MatrixExtensions.TranslateFromLeft(ref target.Matrix, translation);
                MatrixExtensions.TranslateFromRight(ref target.MatrixInverse, -translation);
            }

            if (rotation != 0)
            {
                MatrixExtensions.RotateFromLeft(ref target.Matrix, rotation);
                MatrixExtensions.RotateFromRight(ref target.MatrixInverse, -rotation);
            }

            if (scale != Vector2.One)
            {
                Vector2 inverseScale = new Vector2(1.0f / scale.X, 1.0f / scale.Y);
                MatrixExtensions.ScaleFromLeft(ref target.Matrix, scale);
                MatrixExtensions.ScaleFromRight(ref target.MatrixInverse, inverseScale);
            }

            if (origin != Vector2.Zero)
            {
                MatrixExtensions.TranslateFromLeft(ref target.Matrix, -origin);
                MatrixExtensions.TranslateFromRight(ref target.MatrixInverse, origin);
            }

            //target.MatrixInverse = target.Matrix;
            //MatrixExtensions.FastInvert(ref target.MatrixInverse);

            target.Colour = Colour;

            if (colour != null)
            {
                target.Colour.R *= colour.Value.R;
                target.Colour.G *= colour.Value.G;
                target.Colour.B *= colour.Value.B;
                target.Colour.A *= colour.Value.A;
            }

            if (blending == null)
            {
                Blending.Copy(ref target.Blending);
            }
            else
            {
                blending.Value.Copy(ref target.Blending);
            }
        }
Пример #3
0
        /// <summary>
        /// Applies a transformation to the current DrawInfo.
        /// </summary>
        /// <param name="translation">The amount by which to translate the current position.</param>
        /// <param name="scale">The amount by which to scale.</param>
        /// <param name="rotation">The amount by which to rotate.</param>
        /// <param name="shear">The shear amounts for both directions.</param>
        /// <param name="origin">The center of rotation and scale.</param>
        public void ApplyTransform(Vector2 translation, Vector2 scale, float rotation, Vector2 shear, Vector2 origin)
        {
            checkComponentValid(translation, nameof(translation));
            checkComponentValid(scale, nameof(scale));
            checkComponentValid(rotation, nameof(rotation));
            checkComponentValid(shear, nameof(shear));
            checkComponentValid(origin, nameof(origin));

            if (translation != Vector2.Zero)
            {
                MatrixExtensions.TranslateFromLeft(ref Matrix, translation);
                MatrixExtensions.TranslateFromRight(ref MatrixInverse, -translation);
            }

            if (rotation != 0)
            {
                float radians = MathHelper.DegreesToRadians(rotation);
                MatrixExtensions.RotateFromLeft(ref Matrix, radians);
                MatrixExtensions.RotateFromRight(ref MatrixInverse, -radians);
            }

            if (shear != Vector2.Zero)
            {
                MatrixExtensions.ShearFromLeft(ref Matrix, -shear);
                MatrixExtensions.ShearFromRight(ref MatrixInverse, shear);
            }

            if (scale != Vector2.One)
            {
                Vector2 inverseScale = new Vector2(1.0f / scale.X, 1.0f / scale.Y);
                MatrixExtensions.ScaleFromLeft(ref Matrix, scale);
                MatrixExtensions.ScaleFromRight(ref MatrixInverse, inverseScale);
            }

            if (origin != Vector2.Zero)
            {
                MatrixExtensions.TranslateFromLeft(ref Matrix, -origin);
                MatrixExtensions.TranslateFromRight(ref MatrixInverse, origin);
            }

            //========================================================================================
            //== Uncomment the following 2 lines to use a ground-truth matrix inverse for debugging ==
            //========================================================================================
            //target.MatrixInverse = target.Matrix;
            //MatrixExtensions.FastInvert(ref target.MatrixInverse);
        }