# 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+cos(rot.x);
transform = -sin(rot.x);
transform = sin(rot.x);
transform = 1+cos(rot.x);

transform = cos(rot.y);
transform = sin(rot.y);
transform = -sin(rot.y);
transform = cos(rot.y);

transform = cos(rot.z);
transform = -sin(rot.z);
transform = sin(rot.z);
transform = cos(rot.z);

//translation
transform += bone * intensity;
transform += bone * intensity;
transform += bone * intensity;

//scale
transform = 1 + (bone - 1) * intensity;
transform = 1 + (bone - 1) * intensity;
transform = 1 + (bone - 1) * intensity;

}


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

transform = 1+cos(rot.x);
...
transform = 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...