Say that I have this interface:
interface Drawable {
Vector2 DrawPosition { get; }
Texture2D Texture { get; }
float Rotation { get; }
Vector2 Origin { get; }
Vector2 Scale { get; }
bool FlipHorizontally { get; }
}
and in a class that extends Microsoft.Xna.Framework.Game, I override Draw(GameTime) and this code is somewhere in there:
Drawable d = ...;
spriteBatch.Begin();
spriteBatch.Draw(d.Texture, d.DrawPosition, new Rectangle(0, 0, d.Texture.Width, d.Texture.Height), Color.White, d.Rotation, d.Origin, d.Scale, d.FlipHorizontally ? SpriteEffects.FlipHorizontally : SpriteEffects.None, 0);
spriteBatch.End();
This uses the SpriteBatch.Draw(Texture2D texture, Vector2 position, Nullable sourceRectangle, Color color, float rotation, Vector2 origin, Vector2 scale, SpriteEffects effects, float layerDepth) overload.
Say I had a set of vertices that makes a rough outline of the image that is returned by d.Texture (that is, if I open up the image in Microsoft Paint and pencil every point from the set of vertices, it would fit pretty closely). If I wanted to plot these points so that they go over the textures using GraphicsDevice.DrawUserPrimitives(), would there be a way to transform the vertices using only matrices? The key thing is that it could only use matrices, and I have no other alternatives for drawing because I actually need to use the transformed vertices for other things as well. I already tried something like
Matrix.CreateTranslation(new Vector3(-d.Origin, 0))
* Matrix.CreateScale(new Vector3(d.Scale, 0))
* Matrix.CreateRotationZ(d.Rotation)
* Matrix.CreateTranslation(new Vector3(d.DrawPosition, 0)));
but it fails pretty hard. Is there a solution to this problem?