user2190126 user2190126 -4 years ago 109
C++ Question

Get the angle from a rotated matrix using glm?

I want to know how to get the angle from a rotated matrix, how do I calculate that? I am using glm c++.

For example
how do I get the angle from this matrix using c++?

[ 0 ][ 0 ][1][0]
[ x ][ y ][z][1]

Answer Source

This looks like an identity matrix that was rotated around Z axis. If that's always the case, you can get the angle back by applying glm::atan function on the first two elements of the first column:

float get_angle_in_rad(const glm::mat4 &matrix) {
    return glm::atan(matrix[0][1], matrix[0][0]);

See Rotation matrix for explanation.

Note that if the matrix represents more complicated tranformation than just rotation around Z axis, the value returned by this function will be bogus. Depending on your usecase you may want to keep the euler rotation angles separately, in addition to the transformation matrix.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download