So I google and a little rewrite.
Code: Select all
matrix4 rotation_matrix;
{
f32 angle = ANGLE_VALUE;
f32 x = VECTOR_X;
f32 y = VECTOR_Y;
f32 z = VECTOR_Z;
f32 s = sin(angle);
f32 c = cos(angle);
f32 omc = 1.0 - c;
f32 xomc = x * omc;
f32 yomc = y * omc;
f32 zomc = z * omc;
f32 xxomc = x * xomc;
f32 xyomc = x * yomc;
f32 xzomc = x * zomc;
f32 yyomc = y * yomc;
f32 yzomc = y * zomc;
f32 zzomc = z * zomc;
f32 xs = x * s;
f32 ys = y * s;
f32 zs = z * s;
rotation_matrix[0] = xxomc + c;
rotation_matrix[1] = xyomc + zs;
rotation_matrix[2] = xzomc - ys;
rotation_matrix[3] = 0;
rotation_matrix[4] = xyomc - zs;
rotation_matrix[5] = yyomc + c;
rotation_matrix[6] = yzomc + xs;
rotation_matrix[7] = 0;
rotation_matrix[8] = xzomc + ys;
rotation_matrix[9] = yzomc - xs;
rotation_matrix[10] = zzomc + c;
rotation_matrix[11] = 0;
rotation_matrix[12] = 0;
rotation_matrix[13] = 0;
rotation_matrix[14] = 0;
rotation_matrix[15] = 1;
}