euler.rst 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. .. default-domain:: C
  2. euler angles
  3. ============
  4. Header: cglm/euler.h
  5. You may wonder what **glm_euler_sq** type ( **_sq** stands for sequence ) and
  6. :c:func:`glm_euler_by_order` do.
  7. I used them to convert euler angles in one coordinate system to another. For
  8. instance if you have **Z_UP** euler angles and if you want to convert it
  9. to **Y_UP** axis then :c:func:`glm_euler_by_order` is your friend. For more
  10. information check :c:func:`glm_euler_order` documentation
  11. You must pass arrays as array, if you use C compiler then you can use something
  12. like this:
  13. .. code-block:: c
  14. float pitch, yaw, roll;
  15. mat4 rot;
  16. /* pitch = ...; yaw = ...; roll = ... */
  17. glm_euler((vec3){pitch, yaw, roll}, rot);
  18. Rotation Conveniention
  19. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  20. Current *cglm*'s euler functions uses these convention:
  21. * Tait–Bryan angles (x-y-z convention)
  22. * Intrinsic rotations (pitch, yaw and roll).
  23. This is reserve order of extrinsic (elevation, heading and bank) rotation
  24. * Right hand rule (actually all rotations in *cglm* use **RH**)
  25. * All angles used in *cglm* are **RADIANS** not degrees
  26. **NOTE**: The default :c:func:`glm_euler` function is the short name of
  27. :c:func:`glm_euler_xyz` this is why you can't see :c:func:`glm_euler_xyz`.
  28. When you see an euler function which doesn't have any X, Y, Z suffix then
  29. assume that uses **_xyz** (or instead it accept order as parameter).
  30. If rotation doesn't work properly, your options:
  31. 1. If you use (or paste) degrees convert it to radians before calling an euler function
  32. .. code-block:: c
  33. float pitch, yaw, roll;
  34. mat4 rot;
  35. /* pitch = degrees; yaw = degrees; roll = degrees */
  36. glm_euler((vec3){glm_rad(pitch), glm_rad(yaw), glm_rad(roll)}, rot);
  37. 2. Convention mismatch. You may have extrinsic angles,
  38. if you do (if you must) then consider to use reverse order e.g if you have
  39. **xyz** extrinsic then use **zyx**
  40. 3. *cglm* may implemented it wrong, consider to create an issue to report it
  41. or pull request to fix it
  42. Table of contents (click to go):
  43. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  44. Types:
  45. 1. glm_euler_sq
  46. Functions:
  47. 1. :c:func:`glm_euler_order`
  48. #. :c:func:`glm_euler_angles`
  49. #. :c:func:`glm_euler`
  50. #. :c:func:`glm_euler_zyx`
  51. #. :c:func:`glm_euler_zxy`
  52. #. :c:func:`glm_euler_xzy`
  53. #. :c:func:`glm_euler_yzx`
  54. #. :c:func:`glm_euler_yxz`
  55. #. :c:func:`glm_euler_by_order`
  56. Functions documentation
  57. ~~~~~~~~~~~~~~~~~~~~~~~
  58. .. c:function:: glm_euler_sq glm_euler_order(int ord[3])
  59. | packs euler angles order to glm_euler_sq enum.
  60. To use :c:func:`glm_euler_by_order` function you need *glm_euler_sq*. You
  61. can get it with this function.
  62. You can build param like this:
  63. | X = 0, Y = 1, Z = 2
  64. if you have ZYX order then you pass this: [2, 1, 0] = ZYX.
  65. if you have YXZ order then you pass this: [1, 0, 2] = YXZ
  66. As you can see first item specifies which axis will be first then the
  67. second one specifies which one will be next an so on.
  68. Parameters:
  69. | *[in]* **ord** euler angles order [Angle1, Angle2, Angle2]
  70. Returns:
  71. packed euler order
  72. .. c:function:: void glm_euler_angles(mat4 m, vec3 dest)
  73. | extract euler angles (in radians) using xyz order
  74. Parameters:
  75. | *[in]* **m** affine transform
  76. | *[out]* **dest** angles vector [x, y, z]
  77. .. c:function:: void glm_euler(vec3 angles, mat4 dest)
  78. | build rotation matrix from euler angles
  79. Parameters:
  80. | *[in]* **angles** angles as vector [Ex, Ey, Ez]
  81. | *[in]* **dest** rotation matrix
  82. .. c:function:: void glm_euler_zyx(vec3 angles, mat4 dest)
  83. | build rotation matrix from euler angles
  84. Parameters:
  85. | *[in]* **angles** angles as vector [Ez, Ey, Ex]
  86. | *[in]* **dest** rotation matrix
  87. .. c:function:: void glm_euler_zxy(vec3 angles, mat4 dest)
  88. | build rotation matrix from euler angles
  89. Parameters:
  90. | *[in]* **angles** angles as vector [Ez, Ex, Ey]
  91. | *[in]* **dest** rotation matrix
  92. .. c:function:: void glm_euler_xzy(vec3 angles, mat4 dest)
  93. | build rotation matrix from euler angles
  94. Parameters:
  95. | *[in]* **angles** angles as vector [Ex, Ez, Ey]
  96. | *[in]* **dest** rotation matrix
  97. .. c:function:: void glm_euler_yzx(vec3 angles, mat4 dest)
  98. build rotation matrix from euler angles
  99. Parameters:
  100. | *[in]* **angles** angles as vector [Ey, Ez, Ex]
  101. | *[in]* **dest** rotation matrix
  102. .. c:function:: void glm_euler_yxz(vec3 angles, mat4 dest)
  103. | build rotation matrix from euler angles
  104. Parameters:
  105. | *[in]* **angles** angles as vector [Ey, Ex, Ez]
  106. | *[in]* **dest** rotation matrix
  107. .. c:function:: void glm_euler_by_order(vec3 angles, glm_euler_sq ord, mat4 dest)
  108. | build rotation matrix from euler angles with given euler order.
  109. Use :c:func:`glm_euler_order` function to build *ord* parameter
  110. Parameters:
  111. | *[in]* **angles** angles as vector (ord parameter spceifies angles order)
  112. | *[in]* **ord** euler order
  113. | *[in]* **dest** rotation matrix