Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a texture, some 2D vertices, and a matrix. The matrix is used to calculate the texture coordinates for each vertex, but the problem is that the matrix comes with absolutely no documentation and I'm having trouble working out how to calculate the texture coords correctly. I have it partially working.

The matrix is in this format:

sx rx tx
ry sy ty

Where s means "scale", r means "rotate", and t means "translate".

If the matrix doesn't contain any rotation (i.e. ry = rx = 0), I can correctly calculate the texture coordinates u and v like this:

u = x/sx - tx
v = y/sy - ty

But I can't figure out how to put rx and ry into the equation and get the correct results. Normal matrix multiplication involves multiplying and adding but this one involves dividing and subtracting, so I know I'm missing something but I don't know what it is.

Here is one of the matrices with rotation:

26.191574096679688   7.0180206298828125  1579
-7.0180206298828125  26.191574096679688  1879

Here is one of the matrices without rotation:

27.115478515625  0                1867
0                27.115478515625  800 
share|improve this question
For 2D coordinates with rotations you need a 3x3 matrix, not a 3x2 matrix. So where's the last part? :) – Roy T. Aug 25 '12 at 9:29
It's assumed to be 0, 0, 1 I guess. – Tom Dalling Aug 25 '12 at 9:30
Plus, rotation only requires a 2x2 matrix. Translation requires a 3x3 matrix. – Tom Dalling Aug 25 '12 at 9:37
It is x*sx not x/sx, and it is +tx*1 not -tx*1 you might want to lookup matrix vector multiplication on wikipedia – Maik Semder Aug 25 '12 at 9:47
@Maik that gives incorrect results. It's not a straight matrix multiplication. Please read the question before commenting. – Tom Dalling Aug 25 '12 at 9:53
up vote 1 down vote accepted

As analyzed in the comments, the matrix was the inverse matrix. Inverting it gives the correct results. Here is the first example from the question:

scale = 27.115515  rot = -15 deg   trans = {1579, 1879}

26.191574096679688   7.0180206298828125  1579
-7.0180206298828125  26.191574096679688  1879

the inverse matrix to use is:

0.0356226228  -0.0095450654   -38.3129425048
0.0095450654   0.0356226228   -82.0065689086
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.