Jump to content
• Advertisement

# Stuck on a matrix construction problem.

This topic is 3942 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

I have this sprite based game I have been working on, and everything was fine until I decided to make some non-square sprites. I then saw how horrably messed up something is about my matrix math. I am sure I messed up something very basic. Before I get into the details of the problem some context to this question: The quads I am using:
private static Vector4 VecUpperLeft = new Vector4(-0.5f, 0.5f, 1 , 1 );
private static Vector4 VecUpperRight = new Vector4(0.5f, 0.5f, 1, 1);
private static Vector4 VecLowerLeft = new Vector4(-0.5f, -0.5f, 1, 1);
private static Vector4 VecLowerRight = new Vector4(0.5f, -0.5f, 1, 1);
The paramters are as follows: X, Y, Z, and W (I have no idea what it means, examples have it as 1 all the time). The basic transformation:
 // V0: Upper Left corner
Verts[RenderSpriteVertIndex + 0].Position = Vector4.Transform(VecUpperLeft, ASprite.shMatrix);
The parameters: Vector4, and a Matrix. I do that with each point of the quad for each of my sprites. Now the 'magic' part, where my matrix is made and probably made wrong somehow:
shMatrix = Matrix.Transformation2D(VecZero, RotVisibleAngle, MyScaledSize, VecZero, RotVisibleAngle, DrawnPositon);
Paramters: ScalingCenter, ScalingRotation, Scaling, RotationCenter, RotationAngle, Position Everything but the Rotations are Vector2 (2d vectors). VecZero is just a 0,0 vector. Now everything is 'cool' as long as one of two things is true. 1. MyScaledSize is square. IE: 40x40, 64x64 etc... 2. I do not rotate the sprite. The effect of rotating a sprite by 45 degrees is a very distorted rectangle that doesn't look like it should be at 45 degrees. There is another weird effect to, which is a bit hard to describe, but Ill try. Imagine you have a simple 'pipe' texture. It is just a horizontal strip that would look like a shiny metallic pipe that has the light source near the top. So what you want to do is create a 'box' that has this texture as the frame, so you will want create 4 quads for the edges with the texture stretched. You will need to rotate the texture (or quad) by 90 degrees for the virtical segments because the texture is horizontal in nature. Naturally I just made a sprite that was like 100 x 32 (for example) and then wanted to rotate it by 90 degrees and I would have my graphical pipe segment. Now here is the effect I get with my above matrix stuff. If I leave the sprite unrotated, it looks fine, except of course it is a horizontal bar when we want a vertical one. If I rotate the sprite by 90 degrees, then I will notice that the 'width' of the sprite is still horzontal although the texture is now 'vertical'. If I rotate it by 45 degrees, you can definitly see a warped quad that looks like it may be sheared or something, or maybe it was rotated in 3D space a bit when it is strictly 2D. It is hard to tell. Doing some playing around I know if I remove my "ScalingRotation" and just make it a 0 value, the sprite rotates and looks right. However, the square sprites become a bit distorted when they rotate because they aspect ratio is applied in the wrong direction. IE: if you had an aspect ration of 2:1 (simpler numbers) that would mean a square sprite would really need to be half as wide as it was tall. If you rotated it by 90 degrees without rotating the scaling, then you would have the aspect ratio in the wrong direction. Anyway, I am pretty sure the problem is a conflict between the scaling rotation and the quad rotation. I just do not know what to do about it and am hoping someone here can straiten all this out for me.

#### Share this post

##### Share on other sites
Advertisement

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
2. 2
frob
15
3. 3
4. 4
5. 5
Rutin
12
• Advertisement

• 12
• 12
• 58
• 14
• 15
• ### Forum Statistics

• Total Topics
632115
• Total Posts
3004197

×

## Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!