# Rotation going wrong

I'm calculating matrices by hand. Translations are fine:

`````` void Translate (float x, float y, float z, float[4][4] m) {
Identity (m);
m[3][0] = x;
m[3][1] = y;
m[3][2] = z;
}
``````

If I multiply a vector with this matrix, I get the correct transformation. My problem now is Rotations. I copied the definition from the OpenGL reference on glRotation, but I can't get it right. Can you spot my mistake?

``````void Rotate (float angle, float x, float y, float z, float[4][4] m) {
float c = cos (angle);
float s = sin (angle);
m[0][0] = x*x*(1-c)+c;
m[0][1] = y*x*(1-c)+z*s;
m[0][2] = x*z*(1-c)-y*s;
m[0][3] = 0;
m[1][0] = x*y*(1-c)-z*s;
m[1][1] = y*y*(1-c)+c;
m[1][2] = y*z*(1-c)+x*s;
m[1][3] = 0;
m[2][0] = x*z*(1-c)+y*s;
m[2][1] = y*z*(1-c)-x*s;
m[2][2] = z*z*(1-c)+c;
m[2][3] = 0;
m[3][0] = 0;
m[3][1] = 0;
m[3][2] = 0;
m[3][3] = 1;
}
``````

I don't know what else is relevant, so, if you're kind enough to lend me a hand on this and if I just don't present enough info, just say it.

Thank you for taking the time to read this question.

EDIT The trouble I'm having is the following: If I do `Rotate (180,0,0,0)`, the vertexes are inverted as intended but the resulting triangle (in this case) is smaller.

Screenshot:

-
Are your matrices column major or row major? – sarahm Apr 29 '12 at 12:46
@sarahm: Column major; at least, that is what I think was doing. – AndrewM Apr 29 '12 at 14:31
Are you really intending to rotate around the nonsense axis denoted by the null vector? – Lars Viklund Apr 29 '12 at 18:26

• you do not appear to ensure `(x,y,z)` is a unit vector; if the caller does not take care of this, you should divide each component by `sqrt(x²+y²+z²)`.
• the OpenGL convention is to have angles in degrees, and you are using `cos()` and `sin()` directly.