# Matrix Rotation Only Works On one Axis At A Time

I have this function in my vertex shader. It makes a transformation matix out of a transformation matrix, a rotation and an intensity. It works just fine when setting the rotation of one of the axis (Vector3f rotation = new Vector3f(90, 0, 0);), but when rotating it on multible axis it gives a strange result, that is basicly rotated, but the higher the rotation, the flatter it gets and the model inverts inverts itself if it's too high. this is the function:

void createTransform(in mat4 bone,in vec3 bone_rotation,in float intensity, out mat4 transform)
{
//norm is the identity matrix.
transform = norm;

//rotation
vec3 rot = vec3(bone_rotation.x * intensity, bone_rotation.y * intensity, bone_rotation.z * intensity);
mat4 rotation = norm;

transform[1][1] = 1+cos(rot.x);
transform[2][1] = -sin(rot.x);
transform[1][2] = sin(rot.x);
transform[2][2] = 1+cos(rot.x);

transform[0][0] = cos(rot.y);
transform[2][0] = sin(rot.y);
transform[0][2] = -sin(rot.y);
transform[2][2] = cos(rot.y);

transform[0][0] = cos(rot.z);
transform[1][0] = -sin(rot.z);
transform[0][1] = sin(rot.z);
transform[1][1] = cos(rot.z);

//translation
transform[3][0] += bone[3][0] * intensity;
transform[3][1] += bone[3][1] * intensity;
transform[3][2] += bone[3][2] * intensity;

//scale
transform[0][0] = 1 + (bone[0][0] - 1) * intensity;
transform[1][1] = 1 + (bone[1][1] - 1) * intensity;
transform[2][2] = 1 + (bone[2][2] - 1) * intensity;

}


This is a plain old bug, you're reassigning different values to the same spots, like

transform[1][1] = 1+cos(rot.x);
...
transform[1][1] = cos(rot.z);


What you need to do is combine the rotations in the order you want them applied, like

transformX[][]... assigned only from rot.x
transformY[][]... assigned only from rot.y
transformZ[][]... assigned only from rot.z
transform = transformX * transformY * transformZ


You could pack this down into fewer assignments, but that's the concept.

• Seams locical, but unfortunately doesn't work out for me...