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;

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);

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

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.

  • \$\begingroup\$ Seams locical, but unfortunately doesn't work out for me... \$\endgroup\$
    – Addi
    Mar 7 '15 at 20:47
  • \$\begingroup\$ What doesn't work out? \$\endgroup\$ Mar 8 '15 at 1:41
  • \$\begingroup\$ Putting the values in different matrices and multiplying them. It gives the same result. \$\endgroup\$
    – Addi
    Mar 8 '15 at 7:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.