# Matrix Rotation with three Angles

I want to rotate a form with three given angles fo each of the three axis. But the GLM rotation function takes only one angle and a vector as arguments.

How can I convert between both formats?

GLM's rotation function uses Euler's rotation theorem, which implies that any rotation or sequence of rotations of a rigid body in a three-dimensional space is equivalent to a pure rotation about a single fixed axis.

However consecutive calls to GLMs rotate function just multiply the rotation so rotating a rigid body by Yaw, Pitch, Roll is as simple as this:

glRotateF(yaw, 0, 1, 0);
glRotateF(pitch, 1, 0, 0);
glRotateF(roll, 0, 0, 1);


Edit: please also read this article where they explain the differences and how you can go from Euler angles to Quaternions to Axis Angle :)

The angles used to build a rotation for each of the three axes are known as Tait-Bryan angles (often confused with Euler angles).

Wikipedia has all the formulas you need to convert Euler or Tait-Bryan angles into a rotation matrix.

Here is some code to build a rotation matrix from three Tait-Bryan angles and the order of the rotations:

/* i, j and k are the integers 0, 1 and 2 in any order.
* For instance passing 1, 2, 0 will first rotate around
* Y, then Z, then X.
* Make sure to convert from degrees to radians if necessary. */
mat3 tait_brian_to_matrix(float a, float b, float c,
int i, int j, int k)
{
mat3 ret;

float s0 = sin(a), c0 = cos(a);
float s1 = sin(b), c1 = cos(b);
float s2 = sin(c), c2 = cos(c);

ret[i][i] =   c1 * c2;
ret[k][k] =   c0 * c1;

if ((2 + i - j) % 3)
{
ret[j][i] = - c1 * s2;
ret[k][i] =   s1;

ret[i][j] =   c0 * s2 + s0 * s1 * c2;
ret[j][j] =   c0 * c2 - s0 * s1 * s2;
ret[k][j] = - s0 * c1;

ret[i][k] =   s0 * s2 - c0 * s1 * c2;
ret[j][k] =   s0 * c2 + c0 * s1 * s2;
}
else
{
ret[j][i] =   c1 * s2;
ret[k][i] = - s1;

ret[i][j] = - c0 * s2 + s0 * s1 * c2;
ret[j][j] =   c0 * c2 + s0 * s1 * s2;
ret[k][j] =   s0 * c1;

ret[i][k] =   s0 * s2 + c0 * s1 * c2;
ret[j][k] = - s0 * c2 + c0 * s1 * s2;
}
return ret;
}