euler.rst 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  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_xyz`
  51. #. :c:func:`glm_euler_zyx`
  52. #. :c:func:`glm_euler_zxy`
  53. #. :c:func:`glm_euler_xzy`
  54. #. :c:func:`glm_euler_yzx`
  55. #. :c:func:`glm_euler_yxz`
  56. #. :c:func:`glm_euler_by_order`
  57. Functions documentation
  58. ~~~~~~~~~~~~~~~~~~~~~~~
  59. .. c:function:: glm_euler_sq glm_euler_order(int ord[3])
  60. | packs euler angles order to glm_euler_sq enum.
  61. To use :c:func:`glm_euler_by_order` function you need *glm_euler_sq*. You
  62. can get it with this function.
  63. You can build param like this:
  64. | X = 0, Y = 1, Z = 2
  65. if you have ZYX order then you pass this: [2, 1, 0] = ZYX.
  66. if you have YXZ order then you pass this: [1, 0, 2] = YXZ
  67. As you can see first item specifies which axis will be first then the
  68. second one specifies which one will be next an so on.
  69. Parameters:
  70. | *[in]* **ord** euler angles order [Angle1, Angle2, Angle2]
  71. Returns:
  72. packed euler order
  73. .. c:function:: void glm_euler_angles(mat4 m, vec3 dest)
  74. | extract euler angles (in radians) using xyz order
  75. Parameters:
  76. | *[in]* **m** affine transform
  77. | *[out]* **dest** angles vector [x, y, z]
  78. .. c:function:: void glm_euler(vec3 angles, mat4 dest)
  79. | build rotation matrix from euler angles
  80. this is alias of glm_euler_xyz function
  81. Parameters:
  82. | *[in]* **angles** angles as vector [Xangle, Yangle, Zangle]
  83. | *[in]* **dest** rotation matrix
  84. .. c:function:: void glm_euler_xyz(vec3 angles, mat4 dest)
  85. | build rotation matrix from euler angles
  86. Parameters:
  87. | *[in]* **angles** angles as vector [Xangle, Yangle, Zangle]
  88. | *[in]* **dest** rotation matrix
  89. .. c:function:: void glm_euler_zyx(vec3 angles, mat4 dest)
  90. | build rotation matrix from euler angles
  91. Parameters:
  92. | *[in]* **angles** angles as vector [Xangle, Yangle, Zangle]
  93. | *[in]* **dest** rotation matrix
  94. .. c:function:: void glm_euler_zxy(vec3 angles, mat4 dest)
  95. | build rotation matrix from euler angles
  96. Parameters:
  97. | *[in]* **angles** angles as vector [Xangle, Yangle, Zangle]
  98. | *[in]* **dest** rotation matrix
  99. .. c:function:: void glm_euler_xzy(vec3 angles, mat4 dest)
  100. | build rotation matrix from euler angles
  101. Parameters:
  102. | *[in]* **angles** angles as vector [Xangle, Yangle, Zangle]
  103. | *[in]* **dest** rotation matrix
  104. .. c:function:: void glm_euler_yzx(vec3 angles, mat4 dest)
  105. build rotation matrix from euler angles
  106. Parameters:
  107. | *[in]* **angles** angles as vector [Xangle, Yangle, Zangle]
  108. | *[in]* **dest** rotation matrix
  109. .. c:function:: void glm_euler_yxz(vec3 angles, mat4 dest)
  110. | build rotation matrix from euler angles
  111. Parameters:
  112. | *[in]* **angles** angles as vector [Xangle, Yangle, Zangle]
  113. | *[in]* **dest** rotation matrix
  114. .. c:function:: void glm_euler_by_order(vec3 angles, glm_euler_sq ord, mat4 dest)
  115. | build rotation matrix from euler angles with given euler order.
  116. Use :c:func:`glm_euler_order` function to build *ord* parameter
  117. Parameters:
  118. | *[in]* **angles** angles as vector [Xangle, Yangle, Zangle]
  119. | *[in]* **ord** euler order
  120. | *[in]* **dest** rotation matrix