0
votes

i can't figure out how to extract the rotation around the global y-axis from the model matrix of my object.

I have the current model matrix from my object as an glm::mat4 and i need to cancel out the rotation around the y-axis.

Are there any functions in glm i haven't noticed?

1

1 Answers

0
votes

You have to convert the rotation part of the matrix to Euler angles. It is not a trivial operation. I don't know if "glm" have a function for that, but there is a code (other methods may exists) to convert rotation part of a 4x4 matrix to X, Y and Z Euler angles:

function Matrix4ToEuler(OutEuler, InMatrix4) 
{
  let cy = Math.sqrt(InMatrix4[0] * InMatrix4[0] + InMatrix4[1] * InMatrix4[1]);

  if(cy > 0.001) {

    OutEuler.x = Math.atan2(InMatrix4[6], InMatrix4[10]);
    OutEuler.y = Math.atan2(-InMatrix4[2], cy);
    OutEuler.z = Math.atan2(InMatrix4[1], InMatrix4[0]);

  } else {

    OutEuler.x = Math.atan2(-InMatrix4[9], InMatrix4[5]);
    OutEuler.y = Math.atan2(-InMatrix4[2], cy);
    OutEuler.z = 0;

  }
}