Exemple #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="colour">An optional color to be applied multiplicatively.</param>
        /// <param name="viewport">An optional new viewport size.</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.Translate(ref target.Matrix, translation);
            }

            if (rotation != 0)
            {
                MatrixExtensions.Rotate(ref target.Matrix, rotation);
            }

            if (scale != Vector2.One)
            {
                MatrixExtensions.Scale(ref target.Matrix, scale);
            }

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

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

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

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

            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);
            }
        }