Exemplo n.º 1
0
        /// <summary>
        /// Returns the transform for this group's coordinate system
        /// </summary>
        /// <returns>The transform.</returns>
        protected Matrix2D computeTransform()
        {
            var mat = Matrix2D.Identity;

            if (originX != 0 || originY != 0)
            {
                mat = Matrix2D.Multiply(mat, Matrix2D.CreateTranslation(-originX, -originY, 0));
            }

            if (rotation != 0)
            {
                mat = Matrix2D.Multiply(mat, Matrix2D.CreateRotationZ(MathHelper.ToRadians(rotation)));
            }

            if (scaleX != 1 || scaleY != 1)
            {
                mat = Matrix2D.Multiply(mat, Matrix2D.CreateScale(scaleX, scaleY));
            }

            mat = Matrix2D.Multiply(mat, Matrix2D.CreateTranslation(x + originX, y + originY, 0));

            // Find the first parent that transforms
            Group parentGroup = parent;

            while (parentGroup != null)
            {
                if (parentGroup.transform)
                {
                    break;
                }
                parentGroup = parentGroup.parent;
            }

            if (parentGroup != null)
            {
                mat = Matrix2D.Multiply(mat, parentGroup.computeTransform());
            }

            return(mat);
        }