Tuesday, August 16, 2016

xna - Drawing image with an angle



Edit: the images below aren't supposed to have whitespace. I am just trying to show you that i am trying to create a rectangle from a 1x64 image, positioned as shown in the second picture


I know how to rotate an image like that in XNA


2


But how is it possible to draw a sprite in this angle this way ?


2


I can't seem to be able to find an answer on that and i'm sort on ideas



Answer



What you want is a skew matrix. XNA has no built-in mechanism for creating one. Fortunately we can write our own:


Matrix CreateSkewX(float angle)
{

Matrix skew = Matrix.Identity;
skew.M12 = (float)Math.Tan((double)angle);
return skew;
}

Matrix CreateSkewY(float angle)
{
Matrix skew = Matrix.Identity;
skew.M21 = (float)Math.Tan((double)angle);
return skew;

}

(Note: These are untested, and I might have X and Y reversed.)


Check out this answer for more details.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...