To make a simple transformation like a rotation I want to use linear algebra -multiplying the vec4 vertex_position by a mat4 transformation

If alpha is the angle of rotation, then the mat4 is structured like this:

|first      |second    |third |forth|
|cos(alpha) |sin(alpha)|0     |0    |
|sin(alpha) |cos(alpha)|0     |0    |
|0          |0         |0     |0    |
|0          |0         |0     |0    |

This matrix represents a rotation in the xy plane.

The transformation doesn't work though - can anyone spot my mistake?


1 Answer 1


Usually you should include more details than just "doesn't work" (symptoms, example input-output, etc), but here the errors are pretty obvious:

  • Missing negative sign (for a rotation matrix, your columns should remain orthogonal, so if you took the dot product of the first two columns you should get zero)

  • Missing ones in the z & w axes (if you're not rotating those axes, pass them through unchanged. w in particular can cause unexpected behaviour if zeroed out, as it's important to how vertices are translated & projected in 3D rendering)

All told you probably want something more like this:

|cos(alpha)   -sin(alpha)   0    0  |
|sin(alpha)    cos(alpha)   0    0  |
|    0             0        1    0  |
|    0             0        0    1  |

You must log in to answer this question.

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