Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// @func p3d_matrix_to_euler(m)
- /// @desc Gets euler angles from the YXZ rotation matrix.
- /// @param {array} m The YXZ rotation matrix.
- /// @return {array} An array containing the euler angles `[rotX, rotY, rotZ]`.
- /// @source https://www.geometrictools.com/Documentation/EulerAngles.pdf
- var _thetaX, _thetaY, _thetaZ;
- if (argument0[6] < 1)
- {
- if (argument0[6] > -1)
- {
- _thetaX = darcsin(-argument0[6]);
- _thetaY = darctan2(argument0[2], argument0[10]);
- _thetaZ = darctan2(argument0[4], argument0[5]);
- }
- else
- {
- _thetaX = 90;
- _thetaY = -darctan2(-argument0[1], argument0[0]);
- _thetaZ = 0;
- }
- }
- else
- {
- _thetaX = -90;
- _thetaY = darctan2(-argument0[1], argument0[0]);
- _thetaZ = 0;
- }
- return [
- (_thetaX + 360) mod 360,
- (_thetaY + 360) mod 360,
- (_thetaZ + 360) mod 360
- ];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement