I understand mathematically how transformation matrices work, in that a transformation matrix multiplied by a vector results in a new vector, and we use the matrices for rotation, translation, etc. I also understand that in 3D, the transformation matrices are applied to every vertex of each model in order to transform them, although that's basically the extent of my understanding vis-a-vis 3D transforms, and maybe even that understanding is a little wrong/simplistic.

However, many game engines/graphics rending libraries are designed with the intention of rendering 2D graphics (ex: Flash, XNA, SDL, Allegro), although I know at least some of them are really 3D under the hood. These engines allow the programmer to use transformation matrices to manipulate 2D entities, to do something like implementing a camera, for example. But I don't understand what the transformation matrices I'm plugging in to the engine are being multiplied by in order to perform the transformation. For a while I assumed it was applying the transformation matrix to each pixel of the original image, but that doesn't seem right to me.

So what vectors are the transformation matrices being multiplied by in the 2D transformations? Was I right, and it's really a per-pixel operation? Or does it do some kind of 3D magic under the hood?


1 Answer 1


If the engine is using the 3D graphics hardware under the hood, then it still has vertices, even if it's a 2D game. The models might be very simple—a rectangle for each sprite, for instance. But the matrices would still apply to the vertices, just as they do in a 3D game.

If the engine doesn't use 3D graphics hardware under the hood, but does all its own rasterization, then the matrices still apply to the position (and scale and rotation, if applicable) of each sprite. The engine would use these to work out where each sprite should be drawn on screen.

In a sense, the matrices do also apply to each pixel, indirectly, since a sprite's texture gets pulled along when the sprite or its vertices move. However, the engine would not literally be applying the matrix to the position of each individual pixel.

  • \$\begingroup\$ Okay, I get all that now, thanks! However, what if the engine doesn't do its own rasterization? For example, if an engine used only simple blitting? \$\endgroup\$
    – Sardonic
    Jul 14, 2014 at 15:12
  • \$\begingroup\$ @user2533993 Well, simple blitting is what I was thinking of when I said "doesn't use 3D graphics hardware". The blitting could be done by the engine itself, by an OS API, or by 2D graphics acceleration; it doesn't really matter. The point is that the matrices are used to calculate the on-screen position at which to blit the sprite. \$\endgroup\$ Jul 14, 2014 at 16:27

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .