Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. /// @func p3d_matrix_to_euler(m)
  2. /// @desc Gets euler angles from the YXZ rotation matrix.
  3. /// @param {array} m The YXZ rotation matrix.
  4. /// @return {array} An array containing the euler angles `[rotX, rotY, rotZ]`.
  5. /// @source https://www.geometrictools.com/Documentation/EulerAngles.pdf
  6. var _thetaX, _thetaY, _thetaZ;
  7.  
  8. if (argument0[6] < 1)
  9. {
  10. if (argument0[6] > -1)
  11. {
  12. _thetaX = darcsin(-argument0[6]);
  13. _thetaY = darctan2(argument0[2], argument0[10]);
  14. _thetaZ = darctan2(argument0[4], argument0[5]);
  15. }
  16. else
  17. {
  18. _thetaX = 90;
  19. _thetaY = -darctan2(-argument0[1], argument0[0]);
  20. _thetaZ = 0;
  21. }
  22. }
  23. else
  24. {
  25. _thetaX = -90;
  26. _thetaY = darctan2(-argument0[1], argument0[0]);
  27. _thetaZ = 0;
  28. }
  29.  
  30. return [
  31. (_thetaX + 360) mod 360,
  32. (_thetaY + 360) mod 360,
  33. (_thetaZ + 360) mod 360
  34. ];
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement