openglmatrixcoordinatescoordinate-transformationhomogenous-transformation

How do I convert a 2D transformation matrix (for homogeneous coordinates) into 3D in the z=0 plane?


I have a 3x3 transformation matrix for 2D homogeneous coordinates:

a b c
d e f
g h i

I'd like to pass this to OpenGL (using glMultMatrix) in a 2D application, but OpenGL takes 4x4 matrices for 3D homogeneous coordinates. I'd like all coordinates transformed by my 4x4 matrix to end up with x and y the same as for the 3x3 matrix and with z=0.

I've tried to work it out. For a vector x, y, 1 I'd end up with the transformed vector ax + by + c, dx + ey + f, gx + hy + i, so that means for a vector x, y, 0, 1, I'd want to end up with the tranformed vector ax + by + c, dx + ey + f, 0, ?. One matrix that would do this is (as far as I can tell):

a b 0 c
d e 0 f
0 0 1 0
0 0 0 1

Is this correct? Does it work? I don't think this is the only matrix that will give the result I'm looking for, but I don't quite understand what should or shouldn't go in the third and fourth rows (and the fourth column).


Solution

  • If you want the z-coordinate to be 0, you have to pass a zero-row. Also, include the perspective part in the last row:

    a b 0 c
    d e 0 f
    0 0 0 0
    g h 0 i