### Drawing a Texture using a matrix (OpenGL)

I am trying to make a more basic version of tiny tanks using SDL and OpenGL. To draw the textures to the screen I am using glBindTexture using GL_QUADS. It uses a 3 by 3 Matrix to know it's position, scale and rotation. For Example:
 ``123`` ``````m_00=32 m_01=0 m_02=0 m_10=0 m_11=32 m_12=0 m_20=64 m_21=128 m_22=0``````

This is meant to have the position of (64,128) and the scale of 32 by 32. If I draw this to the screen it will draw the texture to the screen fine. The problem comes when I try to rotate that image. I want it so that if I rotate it 90 degrees it looks the same just rotated but with my current code it the quad collapses in on itself then flips upside down and back to front and grows. I am unsure if this is a problem with my code to add rotation to the matrix or if the problem lies with the the points (corners) for the texture not taking in the matrix information in the right way.
For adding rotation to the Matrix I pass in a float to rotate it using
(Coordinates are in the form of row then column)
 ``12345`` ``````const float co = cosf(Angle); const float si = sinf(Angle); m_00 += co; m_01 += si; m_10 -= si; m_11 += co;``````

For the setting the corners of the Quad I am using:
 ``123456789`` ``````Vector2 centre (a_Matrix.m_20,a_Matrix.m_21); Vector2 tl ((a_Matrix.m_20-a_Matrix.m_10-a_Matrix.m_00), (a_Matrix.m_21-a_Matrix.m_11-a_Matrix.m_01)); Vector2 tr ((a_Matrix.m_20+a_Matrix.m_10+a_Matrix.m_00), (a_Matrix.m_21-a_Matrix.m_11-a_Matrix.m_01)); Vector2 br ((a_Matrix.m_20+a_Matrix.m_10+a_Matrix.m_00), (a_Matrix.m_21+a_Matrix.m_11+a_Matrix.m_01)); Vector2 bl ((a_Matrix.m_20-a_Matrix.m_10-a_Matrix.m_00), (a_Matrix.m_21+a_Matrix.m_11+a_Matrix.m_01));``````

I know this is not in a very understandable format but if anyone can work out what I am meant to do to rotate my image and if after that I could use some help with moving the image by what it thinks as up not the worlds up. (So a tank that has been rotated 90 degrees clockwise gets told to go forward it will be going to the worlds right but given the same function to move forward but only 45 degree clockwise rotation will make it go up right)

Thank you if you read this far, I hope that someone can assist me with the problems that I am having.
If you have two linear transformations (in your case are affine transformations, but I'm pretty sure the same principle applies) f and g, and you want to create a third one h such that h(x)=f(g(x)), then what you need to do is compute h's associated matrix by doing Mh=Mf.Mg, where . is matrix multiplication (if you don't know what matrix multiplication is, look it up. It's not intuitive).

You're getting an incorrect h because you're adding your matrices rather than multiplying them.
For the special case of
g=
(x0,0,0)
(0,x1,0)
(x2,x3,0)
f=
(x4,x5,0)
(x6,x7,0)
(0,0,1)
Note: You want the 1 on Mf's last row to avoid zeroing out the last row of the product. It would be a good idea to add it to Mg as well, otherwise it won't be safe to use it as a left hand multiplicand.

h=f.g=
(x0*x4,x1*x5)
(x0*x6,x1*x7)
(x2,x3,1)

If none of this made any sense, I recommend a book on linear algebra.
Topic archived. No new replies allowed.