I'm trying to convert 3 direction vectors (forward, right, up vectors) to 3 Euler angles (X, Y, and Z).
I figured I could do this by projecting each axis against the unit axis, then use arctan2 to extract the angle.
Visualization:
I project the input right vector against the unit right (red) and unit up (green), then take the arctan2 of the resulting X,Y to get an angle. I do this for each axis respectively (see code snippet).
This generates the correct Euler rotation for an axis when the input axis vector is parallel to the "plane" its projected against. Once it starts deviating, the result becomes incorrect. Often times its close, but still not correct,
glm::vec3 rotation;
rotation.x = glm::degrees(atan2f(glm::dot(glm::vec3(0, 0, 1), up),
glm::dot(glm::vec3(0, 1, 0), up)));
rotation.y = glm::degrees(atan2f(glm::dot(glm::vec3(1, 0, 0), forward),
glm::dot(glm::vec3(0, 0, 1), forward)));
rotation.z = glm::degrees(atan2f(glm::dot(glm::vec3(0, 1, 0), right),
glm::dot(glm::vec3(1, 0, 0), right)));
I know there exists formula for converting angles to axis. I can't seem to find much info on Google for the reverse of this.
I'm using the glm math library if that makes a difference.