specific_euler_angles_f64.odin 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456
  1. package linalg
  2. import "core:math"
  3. @(require_results)
  4. euler_angles_from_matrix3_f64 :: proc "contextless" (m: Matrix3f64, order: Euler_Angle_Order) -> (t1, t2, t3: f64) {
  5. switch order {
  6. case .XYZ: t1, t2, t3 = euler_angles_xyz_from_matrix3(m)
  7. case .XZY: t1, t2, t3 = euler_angles_xzy_from_matrix3(m)
  8. case .YXZ: t1, t2, t3 = euler_angles_yxz_from_matrix3(m)
  9. case .YZX: t1, t2, t3 = euler_angles_yzx_from_matrix3(m)
  10. case .ZXY: t1, t2, t3 = euler_angles_zxy_from_matrix3(m)
  11. case .ZYX: t1, t2, t3 = euler_angles_zyx_from_matrix3(m)
  12. case .XYX: t1, t2, t3 = euler_angles_xyx_from_matrix3(m)
  13. case .XZX: t1, t2, t3 = euler_angles_xzx_from_matrix3(m)
  14. case .YXY: t1, t2, t3 = euler_angles_yxy_from_matrix3(m)
  15. case .YZY: t1, t2, t3 = euler_angles_yzy_from_matrix3(m)
  16. case .ZXZ: t1, t2, t3 = euler_angles_zxz_from_matrix3(m)
  17. case .ZYZ: t1, t2, t3 = euler_angles_zyz_from_matrix3(m)
  18. }
  19. return
  20. }
  21. @(require_results)
  22. euler_angles_from_matrix4_f64 :: proc "contextless" (m: Matrix4f64, order: Euler_Angle_Order) -> (t1, t2, t3: f64) {
  23. switch order {
  24. case .XYZ: t1, t2, t3 = euler_angles_xyz_from_matrix4(m)
  25. case .XZY: t1, t2, t3 = euler_angles_xzy_from_matrix4(m)
  26. case .YXZ: t1, t2, t3 = euler_angles_yxz_from_matrix4(m)
  27. case .YZX: t1, t2, t3 = euler_angles_yzx_from_matrix4(m)
  28. case .ZXY: t1, t2, t3 = euler_angles_zxy_from_matrix4(m)
  29. case .ZYX: t1, t2, t3 = euler_angles_zyx_from_matrix4(m)
  30. case .XYX: t1, t2, t3 = euler_angles_xyx_from_matrix4(m)
  31. case .XZX: t1, t2, t3 = euler_angles_xzx_from_matrix4(m)
  32. case .YXY: t1, t2, t3 = euler_angles_yxy_from_matrix4(m)
  33. case .YZY: t1, t2, t3 = euler_angles_yzy_from_matrix4(m)
  34. case .ZXZ: t1, t2, t3 = euler_angles_zxz_from_matrix4(m)
  35. case .ZYZ: t1, t2, t3 = euler_angles_zyz_from_matrix4(m)
  36. }
  37. return
  38. }
  39. @(require_results)
  40. euler_angles_from_quaternion_f64 :: proc "contextless" (m: Quaternionf64, order: Euler_Angle_Order) -> (t1, t2, t3: f64) {
  41. switch order {
  42. case .XYZ: t1, t2, t3 = euler_angles_xyz_from_quaternion(m)
  43. case .XZY: t1, t2, t3 = euler_angles_xzy_from_quaternion(m)
  44. case .YXZ: t1, t2, t3 = euler_angles_yxz_from_quaternion(m)
  45. case .YZX: t1, t2, t3 = euler_angles_yzx_from_quaternion(m)
  46. case .ZXY: t1, t2, t3 = euler_angles_zxy_from_quaternion(m)
  47. case .ZYX: t1, t2, t3 = euler_angles_zyx_from_quaternion(m)
  48. case .XYX: t1, t2, t3 = euler_angles_xyx_from_quaternion(m)
  49. case .XZX: t1, t2, t3 = euler_angles_xzx_from_quaternion(m)
  50. case .YXY: t1, t2, t3 = euler_angles_yxy_from_quaternion(m)
  51. case .YZY: t1, t2, t3 = euler_angles_yzy_from_quaternion(m)
  52. case .ZXZ: t1, t2, t3 = euler_angles_zxz_from_quaternion(m)
  53. case .ZYZ: t1, t2, t3 = euler_angles_zyz_from_quaternion(m)
  54. }
  55. return
  56. }
  57. @(require_results)
  58. matrix3_from_euler_angles_f64 :: proc "contextless" (t1, t2, t3: f64, order: Euler_Angle_Order) -> (m: Matrix3f64) {
  59. switch order {
  60. case .XYZ: return matrix3_from_euler_angles_xyz(t1, t2, t3) // m1, m2, m3 = X(t1), Y(t2), Z(t3);
  61. case .XZY: return matrix3_from_euler_angles_xzy(t1, t2, t3) // m1, m2, m3 = X(t1), Z(t2), Y(t3);
  62. case .YXZ: return matrix3_from_euler_angles_yxz(t1, t2, t3) // m1, m2, m3 = Y(t1), X(t2), Z(t3);
  63. case .YZX: return matrix3_from_euler_angles_yzx(t1, t2, t3) // m1, m2, m3 = Y(t1), Z(t2), X(t3);
  64. case .ZXY: return matrix3_from_euler_angles_zxy(t1, t2, t3) // m1, m2, m3 = Z(t1), X(t2), Y(t3);
  65. case .ZYX: return matrix3_from_euler_angles_zyx(t1, t2, t3) // m1, m2, m3 = Z(t1), Y(t2), X(t3);
  66. case .XYX: return matrix3_from_euler_angles_xyx(t1, t2, t3) // m1, m2, m3 = X(t1), Y(t2), X(t3);
  67. case .XZX: return matrix3_from_euler_angles_xzx(t1, t2, t3) // m1, m2, m3 = X(t1), Z(t2), X(t3);
  68. case .YXY: return matrix3_from_euler_angles_yxy(t1, t2, t3) // m1, m2, m3 = Y(t1), X(t2), Y(t3);
  69. case .YZY: return matrix3_from_euler_angles_yzy(t1, t2, t3) // m1, m2, m3 = Y(t1), Z(t2), Y(t3);
  70. case .ZXZ: return matrix3_from_euler_angles_zxz(t1, t2, t3) // m1, m2, m3 = Z(t1), X(t2), Z(t3);
  71. case .ZYZ: return matrix3_from_euler_angles_zyz(t1, t2, t3) // m1, m2, m3 = Z(t1), Y(t2), Z(t3);
  72. }
  73. return
  74. }
  75. @(require_results)
  76. matrix4_from_euler_angles_f64 :: proc "contextless" (t1, t2, t3: f64, order: Euler_Angle_Order) -> (m: Matrix4f64) {
  77. switch order {
  78. case .XYZ: return matrix4_from_euler_angles_xyz(t1, t2, t3) // m1, m2, m3 = X(t1), Y(t2), Z(t3);
  79. case .XZY: return matrix4_from_euler_angles_xzy(t1, t2, t3) // m1, m2, m3 = X(t1), Z(t2), Y(t3);
  80. case .YXZ: return matrix4_from_euler_angles_yxz(t1, t2, t3) // m1, m2, m3 = Y(t1), X(t2), Z(t3);
  81. case .YZX: return matrix4_from_euler_angles_yzx(t1, t2, t3) // m1, m2, m3 = Y(t1), Z(t2), X(t3);
  82. case .ZXY: return matrix4_from_euler_angles_zxy(t1, t2, t3) // m1, m2, m3 = Z(t1), X(t2), Y(t3);
  83. case .ZYX: return matrix4_from_euler_angles_zyx(t1, t2, t3) // m1, m2, m3 = Z(t1), Y(t2), X(t3);
  84. case .XYX: return matrix4_from_euler_angles_xyx(t1, t2, t3) // m1, m2, m3 = X(t1), Y(t2), X(t3);
  85. case .XZX: return matrix4_from_euler_angles_xzx(t1, t2, t3) // m1, m2, m3 = X(t1), Z(t2), X(t3);
  86. case .YXY: return matrix4_from_euler_angles_yxy(t1, t2, t3) // m1, m2, m3 = Y(t1), X(t2), Y(t3);
  87. case .YZY: return matrix4_from_euler_angles_yzy(t1, t2, t3) // m1, m2, m3 = Y(t1), Z(t2), Y(t3);
  88. case .ZXZ: return matrix4_from_euler_angles_zxz(t1, t2, t3) // m1, m2, m3 = Z(t1), X(t2), Z(t3);
  89. case .ZYZ: return matrix4_from_euler_angles_zyz(t1, t2, t3) // m1, m2, m3 = Z(t1), Y(t2), Z(t3);
  90. }
  91. return
  92. }
  93. @(require_results)
  94. quaternion_from_euler_angles_f64 :: proc "contextless" (t1, t2, t3: f64, order: Euler_Angle_Order) -> Quaternionf64 {
  95. X :: quaternion_from_euler_angle_x
  96. Y :: quaternion_from_euler_angle_y
  97. Z :: quaternion_from_euler_angle_z
  98. q1, q2, q3: Quaternionf64
  99. switch order {
  100. case .XYZ: q1, q2, q3 = X(t1), Y(t2), Z(t3)
  101. case .XZY: q1, q2, q3 = X(t1), Z(t2), Y(t3)
  102. case .YXZ: q1, q2, q3 = Y(t1), X(t2), Z(t3)
  103. case .YZX: q1, q2, q3 = Y(t1), Z(t2), X(t3)
  104. case .ZXY: q1, q2, q3 = Z(t1), X(t2), Y(t3)
  105. case .ZYX: q1, q2, q3 = Z(t1), Y(t2), X(t3)
  106. case .XYX: q1, q2, q3 = X(t1), Y(t2), X(t3)
  107. case .XZX: q1, q2, q3 = X(t1), Z(t2), X(t3)
  108. case .YXY: q1, q2, q3 = Y(t1), X(t2), Y(t3)
  109. case .YZY: q1, q2, q3 = Y(t1), Z(t2), Y(t3)
  110. case .ZXZ: q1, q2, q3 = Z(t1), X(t2), Z(t3)
  111. case .ZYZ: q1, q2, q3 = Z(t1), Y(t2), Z(t3)
  112. }
  113. return q1 * (q2 * q3)
  114. }
  115. // Quaternionf64s
  116. @(require_results)
  117. quaternion_from_euler_angle_x_f64 :: proc "contextless" (angle_x: f64) -> (q: Quaternionf64) {
  118. return quaternion_angle_axis_f64(angle_x, {1, 0, 0})
  119. }
  120. @(require_results)
  121. quaternion_from_euler_angle_y_f64 :: proc "contextless" (angle_y: f64) -> (q: Quaternionf64) {
  122. return quaternion_angle_axis_f64(angle_y, {0, 1, 0})
  123. }
  124. @(require_results)
  125. quaternion_from_euler_angle_z_f64 :: proc "contextless" (angle_z: f64) -> (q: Quaternionf64) {
  126. return quaternion_angle_axis_f64(angle_z, {0, 0, 1})
  127. }
  128. @(require_results)
  129. quaternion_from_pitch_yaw_roll_f64 :: proc "contextless" (pitch, yaw, roll: f64) -> Quaternionf64 {
  130. a, b, c := pitch, yaw, roll
  131. ca, sa := math.cos(a*0.5), math.sin(a*0.5)
  132. cb, sb := math.cos(b*0.5), math.sin(b*0.5)
  133. cc, sc := math.cos(c*0.5), math.sin(c*0.5)
  134. q: Quaternionf64
  135. q.x = sa*cb*cc - ca*sb*sc
  136. q.y = ca*sb*cc + sa*cb*sc
  137. q.z = ca*cb*sc - sa*sb*cc
  138. q.w = ca*cb*cc + sa*sb*sc
  139. return q
  140. }
  141. @(require_results)
  142. roll_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> f64 {
  143. return math.atan2(2 * q.x*q.y + q.w*q.z, q.w*q.w + q.x*q.x - q.y*q.y - q.z*q.z)
  144. }
  145. @(require_results)
  146. pitch_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> f64 {
  147. y := 2 * (q.y*q.z + q.w*q.w)
  148. x := q.w*q.w - q.x*q.x - q.y*q.y + q.z*q.z
  149. if abs(x) <= F64_EPSILON && abs(y) <= F64_EPSILON {
  150. return 2 * math.atan2(q.x, q.w)
  151. }
  152. return math.atan2(y, x)
  153. }
  154. @(require_results)
  155. yaw_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> f64 {
  156. return math.asin(clamp(-2 * (q.x*q.z - q.w*q.y), -1, 1))
  157. }
  158. @(require_results)
  159. pitch_yaw_roll_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> (pitch, yaw, roll: f64) {
  160. pitch = pitch_from_quaternion(q)
  161. yaw = yaw_from_quaternion(q)
  162. roll = roll_from_quaternion(q)
  163. return
  164. }
  165. @(require_results)
  166. euler_angles_xyz_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> (t1, t2, t3: f64) {
  167. return euler_angles_xyz_from_matrix4(matrix4_from_quaternion(q))
  168. }
  169. @(require_results)
  170. euler_angles_yxz_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> (t1, t2, t3: f64) {
  171. return euler_angles_yxz_from_matrix4(matrix4_from_quaternion(q))
  172. }
  173. @(require_results)
  174. euler_angles_xzx_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> (t1, t2, t3: f64) {
  175. return euler_angles_xzx_from_matrix4(matrix4_from_quaternion(q))
  176. }
  177. @(require_results)
  178. euler_angles_xyx_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> (t1, t2, t3: f64) {
  179. return euler_angles_xyx_from_matrix4(matrix4_from_quaternion(q))
  180. }
  181. @(require_results)
  182. euler_angles_yxy_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> (t1, t2, t3: f64) {
  183. return euler_angles_yxy_from_matrix4(matrix4_from_quaternion(q))
  184. }
  185. @(require_results)
  186. euler_angles_yzy_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> (t1, t2, t3: f64) {
  187. return euler_angles_yzy_from_matrix4(matrix4_from_quaternion(q))
  188. }
  189. @(require_results)
  190. euler_angles_zyz_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> (t1, t2, t3: f64) {
  191. return euler_angles_zyz_from_matrix4(matrix4_from_quaternion(q))
  192. }
  193. @(require_results)
  194. euler_angles_zxz_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> (t1, t2, t3: f64) {
  195. return euler_angles_zxz_from_matrix4(matrix4_from_quaternion(q))
  196. }
  197. @(require_results)
  198. euler_angles_xzy_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> (t1, t2, t3: f64) {
  199. return euler_angles_xzy_from_matrix4(matrix4_from_quaternion(q))
  200. }
  201. @(require_results)
  202. euler_angles_yzx_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> (t1, t2, t3: f64) {
  203. return euler_angles_yzx_from_matrix4(matrix4_from_quaternion(q))
  204. }
  205. @(require_results)
  206. euler_angles_zyx_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> (t1, t2, t3: f64) {
  207. return euler_angles_zyx_from_matrix4(matrix4_from_quaternion(q))
  208. }
  209. @(require_results)
  210. euler_angles_zxy_from_quaternion_f64 :: proc "contextless" (q: Quaternionf64) -> (t1, t2, t3: f64) {
  211. return euler_angles_zxy_from_matrix4(matrix4_from_quaternion(q))
  212. }
  213. // Matrix3
  214. @(require_results)
  215. matrix3_from_euler_angle_x_f64 :: proc "contextless" (angle_x: f64) -> (m: Matrix3f64) {
  216. cos_x, sin_x := math.cos(angle_x), math.sin(angle_x)
  217. m[0, 0] = 1
  218. m[1, 1] = +cos_x
  219. m[1, 2] = +sin_x
  220. m[2, 1] = -sin_x
  221. m[2, 2] = +cos_x
  222. return
  223. }
  224. @(require_results)
  225. matrix3_from_euler_angle_y_f64 :: proc "contextless" (angle_y: f64) -> (m: Matrix3f64) {
  226. cos_y, sin_y := math.cos(angle_y), math.sin(angle_y)
  227. m[0, 0] = +cos_y
  228. m[0, 2] = -sin_y
  229. m[1, 1] = 1
  230. m[2, 0] = +sin_y
  231. m[2, 2] = +cos_y
  232. return
  233. }
  234. @(require_results)
  235. matrix3_from_euler_angle_z_f64 :: proc "contextless" (angle_z: f64) -> (m: Matrix3f64) {
  236. cos_z, sin_z := math.cos(angle_z), math.sin(angle_z)
  237. m[0, 0] = +cos_z
  238. m[0, 1] = +sin_z
  239. m[1, 1] = +cos_z
  240. m[1, 0] = -sin_z
  241. m[2, 2] = 1
  242. return
  243. }
  244. @(require_results)
  245. matrix3_from_derived_euler_angle_x_f64 :: proc "contextless" (angle_x: f64, angular_velocity_x: f64) -> (m: Matrix3f64) {
  246. cos_x := math.cos(angle_x) * angular_velocity_x
  247. sin_x := math.sin(angle_x) * angular_velocity_x
  248. m[0, 0] = 1
  249. m[1, 1] = +cos_x
  250. m[1, 2] = +sin_x
  251. m[2, 1] = -sin_x
  252. m[2, 2] = +cos_x
  253. return
  254. }
  255. @(require_results)
  256. matrix3_from_derived_euler_angle_y_f64 :: proc "contextless" (angle_y: f64, angular_velocity_y: f64) -> (m: Matrix3f64) {
  257. cos_y := math.cos(angle_y) * angular_velocity_y
  258. sin_y := math.sin(angle_y) * angular_velocity_y
  259. m[0, 0] = +cos_y
  260. m[0, 2] = -sin_y
  261. m[1, 1] = 1
  262. m[2, 0] = +sin_y
  263. m[2, 2] = +cos_y
  264. return
  265. }
  266. @(require_results)
  267. matrix3_from_derived_euler_angle_z_f64 :: proc "contextless" (angle_z: f64, angular_velocity_z: f64) -> (m: Matrix3f64) {
  268. cos_z := math.cos(angle_z) * angular_velocity_z
  269. sin_z := math.sin(angle_z) * angular_velocity_z
  270. m[0, 0] = +cos_z
  271. m[0, 1] = +sin_z
  272. m[1, 1] = +cos_z
  273. m[1, 0] = -sin_z
  274. m[2, 2] = 1
  275. return
  276. }
  277. @(require_results)
  278. matrix3_from_euler_angles_xy_f64 :: proc "contextless" (angle_x, angle_y: f64) -> (m: Matrix3f64) {
  279. cos_x, sin_x := math.cos(angle_x), math.sin(angle_x)
  280. cos_y, sin_y := math.cos(angle_y), math.sin(angle_y)
  281. m[0, 0] = cos_y
  282. m[0, 1] = -sin_x * - sin_y
  283. m[0, 2] = -cos_x * - sin_y
  284. m[1, 1] = cos_x
  285. m[1, 2] = sin_x
  286. m[2, 0] = sin_y
  287. m[2, 1] = -sin_x * cos_y
  288. m[2, 2] = cos_x * cos_y
  289. return
  290. }
  291. @(require_results)
  292. matrix3_from_euler_angles_yx_f64 :: proc "contextless" (angle_y, angle_x: f64) -> (m: Matrix3f64) {
  293. cos_x, sin_x := math.cos(angle_x), math.sin(angle_x)
  294. cos_y, sin_y := math.cos(angle_y), math.sin(angle_y)
  295. m[0, 0] = cos_y
  296. m[0, 2] = -sin_y
  297. m[1, 0] = sin_y*sin_x
  298. m[1, 1] = cos_x
  299. m[1, 2] = cos_y*sin_x
  300. m[2, 0] = sin_y*cos_x
  301. m[2, 1] = -sin_x
  302. m[2, 2] = cos_y*cos_x
  303. return
  304. }
  305. @(require_results)
  306. matrix3_from_euler_angles_xz_f64 :: proc "contextless" (angle_x, angle_z: f64) -> (m: Matrix3f64) {
  307. return mul(matrix3_from_euler_angle_x(angle_x), matrix3_from_euler_angle_z(angle_z))
  308. }
  309. @(require_results)
  310. matrix3_from_euler_angles_zx_f64 :: proc "contextless" (angle_z, angle_x: f64) -> (m: Matrix3f64) {
  311. return mul(matrix3_from_euler_angle_z(angle_z), matrix3_from_euler_angle_x(angle_x))
  312. }
  313. @(require_results)
  314. matrix3_from_euler_angles_yz_f64 :: proc "contextless" (angle_y, angle_z: f64) -> (m: Matrix3f64) {
  315. return mul(matrix3_from_euler_angle_y(angle_y), matrix3_from_euler_angle_z(angle_z))
  316. }
  317. @(require_results)
  318. matrix3_from_euler_angles_zy_f64 :: proc "contextless" (angle_z, angle_y: f64) -> (m: Matrix3f64) {
  319. return mul(matrix3_from_euler_angle_z(angle_z), matrix3_from_euler_angle_y(angle_y))
  320. }
  321. @(require_results)
  322. matrix3_from_euler_angles_xyz_f64 :: proc "contextless" (t1, t2, t3: f64) -> (m: Matrix3f64) {
  323. c1 := math.cos(-t1)
  324. c2 := math.cos(-t2)
  325. c3 := math.cos(-t3)
  326. s1 := math.sin(-t1)
  327. s2 := math.sin(-t2)
  328. s3 := math.sin(-t3)
  329. m[0, 0] = c2 * c3
  330. m[1, 0] =-c1 * s3 + s1 * s2 * c3
  331. m[2, 0] = s1 * s3 + c1 * s2 * c3
  332. m[0, 1] = c2 * s3
  333. m[1, 1] = c1 * c3 + s1 * s2 * s3
  334. m[2, 1] =-s1 * c3 + c1 * s2 * s3
  335. m[0, 2] =-s2
  336. m[1, 2] = s1 * c2
  337. m[2, 2] = c1 * c2
  338. return
  339. }
  340. @(require_results)
  341. matrix3_from_euler_angles_yxz_f64 :: proc "contextless" (yaw, pitch, roll: f64) -> (m: Matrix3f64) {
  342. ch := math.cos(yaw)
  343. sh := math.sin(yaw)
  344. cp := math.cos(pitch)
  345. sp := math.sin(pitch)
  346. cb := math.cos(roll)
  347. sb := math.sin(roll)
  348. m[0, 0] = ch * cb + sh * sp * sb
  349. m[1, 0] = sb * cp
  350. m[2, 0] = -sh * cb + ch * sp * sb
  351. m[0, 1] = -ch * sb + sh * sp * cb
  352. m[1, 1] = cb * cp
  353. m[2, 1] = sb * sh + ch * sp * cb
  354. m[0, 2] = sh * cp
  355. m[1, 2] = -sp
  356. m[2, 2] = ch * cp
  357. return
  358. }
  359. @(require_results)
  360. matrix3_from_euler_angles_xzx_f64 :: proc "contextless" (t1, t2, t3: f64) -> (m: Matrix3f64) {
  361. c1 := math.cos(t1)
  362. s1 := math.sin(t1)
  363. c2 := math.cos(t2)
  364. s2 := math.sin(t2)
  365. c3 := math.cos(t3)
  366. s3 := math.sin(t3)
  367. m[0, 0] = c2
  368. m[1, 0] = c1 * s2
  369. m[2, 0] = s1 * s2
  370. m[0, 1] =-c3 * s2
  371. m[1, 1] = c1 * c2 * c3 - s1 * s3
  372. m[2, 1] = c1 * s3 + c2 * c3 * s1
  373. m[0, 2] = s2 * s3
  374. m[1, 2] =-c3 * s1 - c1 * c2 * s3
  375. m[2, 2] = c1 * c3 - c2 * s1 * s3
  376. return
  377. }
  378. @(require_results)
  379. matrix3_from_euler_angles_xyx_f64 :: proc "contextless" (t1, t2, t3: f64) -> (m: Matrix3f64) {
  380. c1 := math.cos(t1)
  381. s1 := math.sin(t1)
  382. c2 := math.cos(t2)
  383. s2 := math.sin(t2)
  384. c3 := math.cos(t3)
  385. s3 := math.sin(t3)
  386. m[0, 0] = c2
  387. m[1, 0] = s1 * s2
  388. m[2, 0] =-c1 * s2
  389. m[0, 1] = s2 * s3
  390. m[1, 1] = c1 * c3 - c2 * s1 * s3
  391. m[2, 1] = c3 * s1 + c1 * c2 * s3
  392. m[0, 2] = c3 * s2
  393. m[1, 2] =-c1 * s3 - c2 * c3 * s1
  394. m[2, 2] = c1 * c2 * c3 - s1 * s3
  395. return
  396. }
  397. @(require_results)
  398. matrix3_from_euler_angles_yxy_f64 :: proc "contextless" (t1, t2, t3: f64) -> (m: Matrix3f64) {
  399. c1 := math.cos(t1)
  400. s1 := math.sin(t1)
  401. c2 := math.cos(t2)
  402. s2 := math.sin(t2)
  403. c3 := math.cos(t3)
  404. s3 := math.sin(t3)
  405. m[0, 0] = c1 * c3 - c2 * s1 * s3
  406. m[1, 0] = s2* s3
  407. m[2, 0] =-c3 * s1 - c1 * c2 * s3
  408. m[0, 1] = s1 * s2
  409. m[1, 1] = c2
  410. m[2, 1] = c1 * s2
  411. m[0, 2] = c1 * s3 + c2 * c3 * s1
  412. m[1, 2] =-c3 * s2
  413. m[2, 2] = c1 * c2 * c3 - s1 * s3
  414. return
  415. }
  416. @(require_results)
  417. matrix3_from_euler_angles_yzy_f64 :: proc "contextless" (t1, t2, t3: f64) -> (m: Matrix3f64) {
  418. c1 := math.cos(t1)
  419. s1 := math.sin(t1)
  420. c2 := math.cos(t2)
  421. s2 := math.sin(t2)
  422. c3 := math.cos(t3)
  423. s3 := math.sin(t3)
  424. m[0, 0] = c1 * c2 * c3 - s1 * s3
  425. m[1, 0] = c3 * s2
  426. m[2, 0] =-c1 * s3 - c2 * c3 * s1
  427. m[0, 1] =-c1 * s2
  428. m[1, 1] = c2
  429. m[2, 1] = s1 * s2
  430. m[0, 2] = c3 * s1 + c1 * c2 * s3
  431. m[1, 2] = s2 * s3
  432. m[2, 2] = c1 * c3 - c2 * s1 * s3
  433. return
  434. }
  435. @(require_results)
  436. matrix3_from_euler_angles_zyz_f64 :: proc "contextless" (t1, t2, t3: f64) -> (m: Matrix3f64) {
  437. c1 := math.cos(t1)
  438. s1 := math.sin(t1)
  439. c2 := math.cos(t2)
  440. s2 := math.sin(t2)
  441. c3 := math.cos(t3)
  442. s3 := math.sin(t3)
  443. m[0, 0] = c1 * c2 * c3 - s1 * s3
  444. m[1, 0] = c1 * s3 + c2 * c3 * s1
  445. m[2, 0] =-c3 * s2
  446. m[0, 1] =-c3 * s1 - c1 * c2 * s3
  447. m[1, 1] = c1 * c3 - c2 * s1 * s3
  448. m[2, 1] = s2 * s3
  449. m[0, 2] = c1 * s2
  450. m[1, 2] = s1 * s2
  451. m[2, 2] = c2
  452. return
  453. }
  454. @(require_results)
  455. matrix3_from_euler_angles_zxz_f64 :: proc "contextless" (t1, t2, t3: f64) -> (m: Matrix3f64) {
  456. c1 := math.cos(t1)
  457. s1 := math.sin(t1)
  458. c2 := math.cos(t2)
  459. s2 := math.sin(t2)
  460. c3 := math.cos(t3)
  461. s3 := math.sin(t3)
  462. m[0, 0] = c1 * c3 - c2 * s1 * s3
  463. m[1, 0] = c3 * s1 + c1 * c2 * s3
  464. m[2, 0] = s2 *s3
  465. m[0, 1] =-c1 * s3 - c2 * c3 * s1
  466. m[1, 1] = c1 * c2 * c3 - s1 * s3
  467. m[2, 1] = c3 * s2
  468. m[0, 2] = s1 * s2
  469. m[1, 2] =-c1 * s2
  470. m[2, 2] = c2
  471. return
  472. }
  473. @(require_results)
  474. matrix3_from_euler_angles_xzy_f64 :: proc "contextless" (t1, t2, t3: f64) -> (m: Matrix3f64) {
  475. c1 := math.cos(t1)
  476. s1 := math.sin(t1)
  477. c2 := math.cos(t2)
  478. s2 := math.sin(t2)
  479. c3 := math.cos(t3)
  480. s3 := math.sin(t3)
  481. m[0, 0] = c2 * c3
  482. m[1, 0] = s1 * s3 + c1 * c3 * s2
  483. m[2, 0] = c3 * s1 * s2 - c1 * s3
  484. m[0, 1] =-s2
  485. m[1, 1] = c1 * c2
  486. m[2, 1] = c2 * s1
  487. m[0, 2] = c2 * s3
  488. m[1, 2] = c1 * s2 * s3 - c3 * s1
  489. m[2, 2] = c1 * c3 + s1 * s2 *s3
  490. return
  491. }
  492. @(require_results)
  493. matrix3_from_euler_angles_yzx_f64 :: proc "contextless" (t1, t2, t3: f64) -> (m: Matrix3f64) {
  494. c1 := math.cos(t1)
  495. s1 := math.sin(t1)
  496. c2 := math.cos(t2)
  497. s2 := math.sin(t2)
  498. c3 := math.cos(t3)
  499. s3 := math.sin(t3)
  500. m[0, 0] = c1 * c2
  501. m[1, 0] = s2
  502. m[2, 0] =-c2 * s1
  503. m[0, 1] = s1 * s3 - c1 * c3 * s2
  504. m[1, 1] = c2 * c3
  505. m[2, 1] = c1 * s3 + c3 * s1 * s2
  506. m[0, 2] = c3 * s1 + c1 * s2 * s3
  507. m[1, 2] =-c2 * s3
  508. m[2, 2] = c1 * c3 - s1 * s2 * s3
  509. return
  510. }
  511. @(require_results)
  512. matrix3_from_euler_angles_zyx_f64 :: proc "contextless" (t1, t2, t3: f64) -> (m: Matrix3f64) {
  513. c1 := math.cos(t1)
  514. s1 := math.sin(t1)
  515. c2 := math.cos(t2)
  516. s2 := math.sin(t2)
  517. c3 := math.cos(t3)
  518. s3 := math.sin(t3)
  519. m[0, 0] = c1 * c2
  520. m[1, 0] = c2 * s1
  521. m[2, 0] =-s2
  522. m[0, 1] = c1 * s2 * s3 - c3 * s1
  523. m[1, 1] = c1 * c3 + s1 * s2 * s3
  524. m[2, 1] = c2 * s3
  525. m[0, 2] = s1 * s3 + c1 * c3 * s2
  526. m[1, 2] = c3 * s1 * s2 - c1 * s3
  527. m[2, 2] = c2 * c3
  528. return
  529. }
  530. @(require_results)
  531. matrix3_from_euler_angles_zxy_f64 :: proc "contextless" (t1, t2, t3: f64) -> (m: Matrix3f64) {
  532. c1 := math.cos(t1)
  533. s1 := math.sin(t1)
  534. c2 := math.cos(t2)
  535. s2 := math.sin(t2)
  536. c3 := math.cos(t3)
  537. s3 := math.sin(t3)
  538. m[0, 0] = c1 * c3 - s1 * s2 * s3
  539. m[1, 0] = c3 * s1 + c1 * s2 * s3
  540. m[2, 0] =-c2 * s3
  541. m[0, 1] =-c2 * s1
  542. m[1, 1] = c1 * c2
  543. m[2, 1] = s2
  544. m[0, 2] = c1 * s3 + c3 * s1 * s2
  545. m[1, 2] = s1 * s3 - c1 * c3 * s2
  546. m[2, 2] = c2 * c3
  547. return
  548. }
  549. @(require_results)
  550. matrix3_from_yaw_pitch_roll_f64 :: proc "contextless" (yaw, pitch, roll: f64) -> (m: Matrix3f64) {
  551. ch := math.cos(yaw)
  552. sh := math.sin(yaw)
  553. cp := math.cos(pitch)
  554. sp := math.sin(pitch)
  555. cb := math.cos(roll)
  556. sb := math.sin(roll)
  557. m[0, 0] = ch * cb + sh * sp * sb
  558. m[1, 0] = sb * cp
  559. m[2, 0] = -sh * cb + ch * sp * sb
  560. m[0, 1] = -ch * sb + sh * sp * cb
  561. m[1, 1] = cb * cp
  562. m[2, 1] = sb * sh + ch * sp * cb
  563. m[0, 2] = sh * cp
  564. m[1, 2] = -sp
  565. m[2, 2] = ch * cp
  566. return m
  567. }
  568. @(require_results)
  569. euler_angles_xyz_from_matrix3_f64 :: proc "contextless" (m: Matrix3f64) -> (t1, t2, t3: f64) {
  570. T1 := math.atan2(m[1, 2], m[2, 2])
  571. C2 := math.sqrt(m[0, 0]*m[0, 0] + m[0, 1]*m[0, 1])
  572. T2 := math.atan2(-m[0, 2], C2)
  573. S1 := math.sin(T1)
  574. C1 := math.cos(T1)
  575. T3 := math.atan2(S1*m[2, 0] - C1*m[1, 0], C1*m[1, 1] - S1*m[2, 1])
  576. t1 = -T1
  577. t2 = -T2
  578. t3 = -T3
  579. return
  580. }
  581. @(require_results)
  582. euler_angles_yxz_from_matrix3_f64 :: proc "contextless" (m: Matrix3f64) -> (t1, t2, t3: f64) {
  583. T1 := math.atan2(m[0, 2], m[2, 2])
  584. C2 := math.sqrt(m[1, 0]*m[1, 0] + m[1, 1]*m[1, 1])
  585. T2 := math.atan2(-m[1, 2], C2)
  586. S1 := math.sin(T1)
  587. C1 := math.cos(T1)
  588. T3 := math.atan2(S1*m[2, 1] - C1*m[0, 1], C1*m[0, 0] - S1*m[2, 0])
  589. t1 = T1
  590. t2 = T2
  591. t3 = T3
  592. return
  593. }
  594. @(require_results)
  595. euler_angles_xzx_from_matrix3_f64 :: proc "contextless" (m: Matrix3f64) -> (t1, t2, t3: f64) {
  596. T1 := math.atan2(m[2, 0], m[1, 0])
  597. S2 := math.sqrt(m[0, 1]*m[0, 1] + m[0, 2]*m[0, 2])
  598. T2 := math.atan2(S2, m[0, 0])
  599. S1 := math.sin(T1)
  600. C1 := math.cos(T1)
  601. T3 := math.atan2(C1*m[2, 1] - S1*m[1, 1], C1*m[2, 2] - S1*m[1, 2])
  602. t1 = T1
  603. t2 = T2
  604. t3 = T3
  605. return
  606. }
  607. @(require_results)
  608. euler_angles_xyx_from_matrix3_f64 :: proc "contextless" (m: Matrix3f64) -> (t1, t2, t3: f64) {
  609. T1 := math.atan2(m[1, 0], -m[2, 0])
  610. S2 := math.sqrt(m[0, 1]*m[0, 1] + m[0, 2]*m[0, 2])
  611. T2 := math.atan2(S2, m[0, 0])
  612. S1 := math.sin(T1)
  613. C1 := math.cos(T1)
  614. T3 := math.atan2(-C1*m[1, 2] - S1*m[2, 2], C1*m[1, 1] + S1*m[2, 1])
  615. t1 = T1
  616. t2 = T2
  617. t3 = T3
  618. return
  619. }
  620. @(require_results)
  621. euler_angles_yxy_from_matrix3_f64 :: proc "contextless" (m: Matrix3f64) -> (t1, t2, t3: f64) {
  622. T1 := math.atan2(m[0, 1], m[2, 1])
  623. S2 := math.sqrt(m[1, 0]*m[1, 0] + m[1, 2]*m[1, 2])
  624. T2 := math.atan2(S2, m[1, 1])
  625. S1 := math.sin(T1)
  626. C1 := math.cos(T1)
  627. T3 := math.atan2(C1*m[0, 2] - S1*m[2, 2], C1*m[0, 0] - S1*m[2, 0])
  628. t1 = T1
  629. t2 = T2
  630. t3 = T3
  631. return
  632. }
  633. @(require_results)
  634. euler_angles_yzy_from_matrix3_f64 :: proc "contextless" (m: Matrix3f64) -> (t1, t2, t3: f64) {
  635. T1 := math.atan2(m[2, 1], -m[0, 1])
  636. S2 := math.sqrt(m[1, 0]*m[1, 0] + m[1, 2]*m[1, 2])
  637. T2 := math.atan2(S2, m[1, 1])
  638. S1 := math.sin(T1)
  639. C1 := math.cos(T1)
  640. T3 := math.atan2(-S1*m[0, 0] - C1*m[2, 0], S1*m[0, 2] + C1*m[2, 2])
  641. t1 = T1
  642. t2 = T2
  643. t3 = T3
  644. return
  645. }
  646. @(require_results)
  647. euler_angles_zyz_from_matrix3_f64 :: proc "contextless" (m: Matrix3f64) -> (t1, t2, t3: f64) {
  648. T1 := math.atan2(m[1, 2], m[0, 2])
  649. S2 := math.sqrt(m[2, 0]*m[2, 0] + m[2, 1]*m[2, 1])
  650. T2 := math.atan2(S2, m[2, 2])
  651. S1 := math.sin(T1)
  652. C1 := math.cos(T1)
  653. T3 := math.atan2(C1*m[1, 0] - S1*m[0, 0], C1*m[1, 1] - S1*m[0, 1])
  654. t1 = T1
  655. t2 = T2
  656. t3 = T3
  657. return
  658. }
  659. @(require_results)
  660. euler_angles_zxz_from_matrix3_f64 :: proc "contextless" (m: Matrix3f64) -> (t1, t2, t3: f64) {
  661. T1 := math.atan2(m[0, 2], -m[1, 2])
  662. S2 := math.sqrt(m[2, 0]*m[2, 0] + m[2, 1]*m[2, 1])
  663. T2 := math.atan2(S2, m[2, 2])
  664. S1 := math.sin(T1)
  665. C1 := math.cos(T1)
  666. T3 := math.atan2(-C1*m[0, 1] - S1*m[1, 1], C1*m[0, 0] + S1*m[1, 0])
  667. t1 = T1
  668. t2 = T2
  669. t3 = T3
  670. return
  671. }
  672. @(require_results)
  673. euler_angles_xzy_from_matrix3_f64 :: proc "contextless" (m: Matrix3f64) -> (t1, t2, t3: f64) {
  674. T1 := math.atan2(m[2, 1], m[1, 1])
  675. C2 := math.sqrt(m[0, 0]*m[0, 0] + m[0, 2]*m[0, 2])
  676. T2 := math.atan2(-m[0, 1], C2)
  677. S1 := math.sin(T1)
  678. C1 := math.cos(T1)
  679. T3 := math.atan2(S1*m[1, 0] - C1*m[2, 0], C1*m[2, 2] - S1*m[1, 2])
  680. t1 = T1
  681. t2 = T2
  682. t3 = T3
  683. return
  684. }
  685. @(require_results)
  686. euler_angles_yzx_from_matrix3_f64 :: proc "contextless" (m: Matrix3f64) -> (t1, t2, t3: f64) {
  687. T1 := math.atan2(-m[2, 0], m[0, 0])
  688. C2 := math.sqrt(m[1, 1]*m[1, 1] + m[1, 2]*m[1, 2])
  689. T2 := math.atan2(m[1, 0], C2)
  690. S1 := math.sin(T1)
  691. C1 := math.cos(T1)
  692. T3 := math.atan2(S1*m[0, 1] + C1*m[2, 1], S1*m[0, 2] + C1*m[2, 2])
  693. t1 = T1
  694. t2 = T2
  695. t3 = T3
  696. return
  697. }
  698. @(require_results)
  699. euler_angles_zyx_from_matrix3_f64 :: proc "contextless" (m: Matrix3f64) -> (t1, t2, t3: f64) {
  700. T1 := math.atan2(m[1, 0], m[0, 0])
  701. C2 := math.sqrt(m[2, 1]*m[2, 1] + m[2, 2]*m[2, 2])
  702. T2 := math.atan2(-m[2, 0], C2)
  703. S1 := math.sin(T1)
  704. C1 := math.cos(T1)
  705. T3 := math.atan2(S1*m[0, 2] - C1*m[1, 2], C1*m[1, 1] - S1*m[0, 1])
  706. t1 = T1
  707. t2 = T2
  708. t3 = T3
  709. return
  710. }
  711. @(require_results)
  712. euler_angles_zxy_from_matrix3_f64 :: proc "contextless" (m: Matrix3f64) -> (t1, t2, t3: f64) {
  713. T1 := math.atan2(-m[0, 1], m[1, 1])
  714. C2 := math.sqrt(m[2, 0]*m[2, 0] + m[2, 2]*m[2, 2])
  715. T2 := math.atan2(m[2, 1], C2)
  716. S1 := math.sin(T1)
  717. C1 := math.cos(T1)
  718. T3 := math.atan2(C1*m[0, 2] + S1*m[1, 2], C1*m[0, 0] + S1*m[1, 0])
  719. t1 = T1
  720. t2 = T2
  721. t3 = T3
  722. return
  723. }
  724. // Matrix4
  725. @(require_results)
  726. matrix4_from_euler_angle_x_f64 :: proc "contextless" (angle_x: f64) -> (m: Matrix4f64) {
  727. cos_x, sin_x := math.cos(angle_x), math.sin(angle_x)
  728. m[0, 0] = 1
  729. m[1, 1] = +cos_x
  730. m[1, 2] = +sin_x
  731. m[2, 1] = -sin_x
  732. m[2, 2] = +cos_x
  733. m[3, 3] = 1
  734. return
  735. }
  736. @(require_results)
  737. matrix4_from_euler_angle_y_f64 :: proc "contextless" (angle_y: f64) -> (m: Matrix4f64) {
  738. cos_y, sin_y := math.cos(angle_y), math.sin(angle_y)
  739. m[0, 0] = +cos_y
  740. m[0, 2] = -sin_y
  741. m[1, 1] = 1
  742. m[2, 0] = +sin_y
  743. m[2, 2] = +cos_y
  744. m[3, 3] = 1
  745. return
  746. }
  747. @(require_results)
  748. matrix4_from_euler_angle_z_f64 :: proc "contextless" (angle_z: f64) -> (m: Matrix4f64) {
  749. cos_z, sin_z := math.cos(angle_z), math.sin(angle_z)
  750. m[0, 0] = +cos_z
  751. m[0, 1] = +sin_z
  752. m[1, 1] = +cos_z
  753. m[1, 0] = -sin_z
  754. m[2, 2] = 1
  755. m[3, 3] = 1
  756. return
  757. }
  758. @(require_results)
  759. matrix4_from_derived_euler_angle_x_f64 :: proc "contextless" (angle_x: f64, angular_velocity_x: f64) -> (m: Matrix4f64) {
  760. cos_x := math.cos(angle_x) * angular_velocity_x
  761. sin_x := math.sin(angle_x) * angular_velocity_x
  762. m[0, 0] = 1
  763. m[1, 1] = +cos_x
  764. m[1, 2] = +sin_x
  765. m[2, 1] = -sin_x
  766. m[2, 2] = +cos_x
  767. m[3, 3] = 1
  768. return
  769. }
  770. @(require_results)
  771. matrix4_from_derived_euler_angle_y_f64 :: proc "contextless" (angle_y: f64, angular_velocity_y: f64) -> (m: Matrix4f64) {
  772. cos_y := math.cos(angle_y) * angular_velocity_y
  773. sin_y := math.sin(angle_y) * angular_velocity_y
  774. m[0, 0] = +cos_y
  775. m[0, 2] = -sin_y
  776. m[1, 1] = 1
  777. m[2, 0] = +sin_y
  778. m[2, 2] = +cos_y
  779. m[3, 3] = 1
  780. return
  781. }
  782. @(require_results)
  783. matrix4_from_derived_euler_angle_z_f64 :: proc "contextless" (angle_z: f64, angular_velocity_z: f64) -> (m: Matrix4f64) {
  784. cos_z := math.cos(angle_z) * angular_velocity_z
  785. sin_z := math.sin(angle_z) * angular_velocity_z
  786. m[0, 0] = +cos_z
  787. m[0, 1] = +sin_z
  788. m[1, 1] = +cos_z
  789. m[1, 0] = -sin_z
  790. m[2, 2] = 1
  791. m[3, 3] = 1
  792. return
  793. }
  794. @(require_results)
  795. matrix4_from_euler_angles_xy_f64 :: proc "contextless" (angle_x, angle_y: f64) -> (m: Matrix4f64) {
  796. cos_x, sin_x := math.cos(angle_x), math.sin(angle_x)
  797. cos_y, sin_y := math.cos(angle_y), math.sin(angle_y)
  798. m[0, 0] = cos_y
  799. m[0, 1] = -sin_x * - sin_y
  800. m[0, 2] = -cos_x * - sin_y
  801. m[1, 1] = cos_x
  802. m[1, 2] = sin_x
  803. m[2, 0] = sin_y
  804. m[2, 1] = -sin_x * cos_y
  805. m[2, 2] = cos_x * cos_y
  806. m[3, 3] = 1
  807. return
  808. }
  809. @(require_results)
  810. matrix4_from_euler_angles_yx_f64 :: proc "contextless" (angle_y, angle_x: f64) -> (m: Matrix4f64) {
  811. cos_x, sin_x := math.cos(angle_x), math.sin(angle_x)
  812. cos_y, sin_y := math.cos(angle_y), math.sin(angle_y)
  813. m[0, 0] = cos_y
  814. m[0, 2] = -sin_y
  815. m[1, 0] = sin_y*sin_x
  816. m[1, 1] = cos_x
  817. m[1, 2] = cos_y*sin_x
  818. m[2, 0] = sin_y*cos_x
  819. m[2, 1] = -sin_x
  820. m[2, 2] = cos_y*cos_x
  821. m[3, 3] = 1
  822. return
  823. }
  824. @(require_results)
  825. matrix4_from_euler_angles_xz_f64 :: proc "contextless" (angle_x, angle_z: f64) -> (m: Matrix4f64) {
  826. return mul(matrix4_from_euler_angle_x(angle_x), matrix4_from_euler_angle_z(angle_z))
  827. }
  828. @(require_results)
  829. matrix4_from_euler_angles_zx_f64 :: proc "contextless" (angle_z, angle_x: f64) -> (m: Matrix4f64) {
  830. return mul(matrix4_from_euler_angle_z(angle_z), matrix4_from_euler_angle_x(angle_x))
  831. }
  832. @(require_results)
  833. matrix4_from_euler_angles_yz_f64 :: proc "contextless" (angle_y, angle_z: f64) -> (m: Matrix4f64) {
  834. return mul(matrix4_from_euler_angle_y(angle_y), matrix4_from_euler_angle_z(angle_z))
  835. }
  836. @(require_results)
  837. matrix4_from_euler_angles_zy_f64 :: proc "contextless" (angle_z, angle_y: f64) -> (m: Matrix4f64) {
  838. return mul(matrix4_from_euler_angle_z(angle_z), matrix4_from_euler_angle_y(angle_y))
  839. }
  840. @(require_results)
  841. matrix4_from_euler_angles_xyz_f64 :: proc "contextless" (t1, t2, t3: f64) -> (m: Matrix4f64) {
  842. c1 := math.cos(-t1)
  843. c2 := math.cos(-t2)
  844. c3 := math.cos(-t3)
  845. s1 := math.sin(-t1)
  846. s2 := math.sin(-t2)
  847. s3 := math.sin(-t3)
  848. m[0, 0] = c2 * c3
  849. m[1, 0] =-c1 * s3 + s1 * s2 * c3
  850. m[2, 0] = s1 * s3 + c1 * s2 * c3
  851. m[3, 0] = 0
  852. m[0, 1] = c2 * s3
  853. m[1, 1] = c1 * c3 + s1 * s2 * s3
  854. m[2, 1] =-s1 * c3 + c1 * s2 * s3
  855. m[3, 1] = 0
  856. m[0, 2] =-s2
  857. m[1, 2] = s1 * c2
  858. m[2, 2] = c1 * c2
  859. m[3, 2] = 0
  860. m[0, 3] = 0
  861. m[1, 3] = 0
  862. m[2, 3] = 0
  863. m[3, 3] = 1
  864. return
  865. }
  866. @(require_results)
  867. matrix4_from_euler_angles_yxz_f64 :: proc "contextless" (yaw, pitch, roll: f64) -> (m: Matrix4f64) {
  868. ch := math.cos(yaw)
  869. sh := math.sin(yaw)
  870. cp := math.cos(pitch)
  871. sp := math.sin(pitch)
  872. cb := math.cos(roll)
  873. sb := math.sin(roll)
  874. m[0, 0] = ch * cb + sh * sp * sb
  875. m[1, 0] = sb * cp
  876. m[2, 0] = -sh * cb + ch * sp * sb
  877. m[3, 0] = 0
  878. m[0, 1] = -ch * sb + sh * sp * cb
  879. m[1, 1] = cb * cp
  880. m[2, 1] = sb * sh + ch * sp * cb
  881. m[3, 1] = 0
  882. m[0, 2] = sh * cp
  883. m[1, 2] = -sp
  884. m[2, 2] = ch * cp
  885. m[3, 2] = 0
  886. m[0, 3] = 0
  887. m[1, 3] = 0
  888. m[2, 3] = 0
  889. m[3, 3] = 1
  890. return
  891. }
  892. @(require_results)
  893. matrix4_from_euler_angles_xzx_f64 :: proc "contextless" (t1, t2, t3: f64) -> (m: Matrix4f64) {
  894. c1 := math.cos(t1)
  895. s1 := math.sin(t1)
  896. c2 := math.cos(t2)
  897. s2 := math.sin(t2)
  898. c3 := math.cos(t3)
  899. s3 := math.sin(t3)
  900. m[0, 0] = c2
  901. m[1, 0] = c1 * s2
  902. m[2, 0] = s1 * s2
  903. m[3, 0] = 0
  904. m[0, 1] =-c3 * s2
  905. m[1, 1] = c1 * c2 * c3 - s1 * s3
  906. m[2, 1] = c1 * s3 + c2 * c3 * s1
  907. m[3, 1] = 0
  908. m[0, 2] = s2 * s3
  909. m[1, 2] =-c3 * s1 - c1 * c2 * s3
  910. m[2, 2] = c1 * c3 - c2 * s1 * s3
  911. m[3, 2] = 0
  912. m[0, 3] = 0
  913. m[1, 3] = 0
  914. m[2, 3] = 0
  915. m[3, 3] = 1
  916. return
  917. }
  918. @(require_results)
  919. matrix4_from_euler_angles_xyx_f64 :: proc "contextless" (t1, t2, t3: f64) -> (m: Matrix4f64) {
  920. c1 := math.cos(t1)
  921. s1 := math.sin(t1)
  922. c2 := math.cos(t2)
  923. s2 := math.sin(t2)
  924. c3 := math.cos(t3)
  925. s3 := math.sin(t3)
  926. m[0, 0] = c2
  927. m[1, 0] = s1 * s2
  928. m[2, 0] =-c1 * s2
  929. m[3, 0] = 0
  930. m[0, 1] = s2 * s3
  931. m[1, 1] = c1 * c3 - c2 * s1 * s3
  932. m[2, 1] = c3 * s1 + c1 * c2 * s3
  933. m[3, 1] = 0
  934. m[0, 2] = c3 * s2
  935. m[1, 2] =-c1 * s3 - c2 * c3 * s1
  936. m[2, 2] = c1 * c2 * c3 - s1 * s3
  937. m[3, 2] = 0
  938. m[0, 3] = 0
  939. m[1, 3] = 0
  940. m[2, 3] = 0
  941. m[3, 3] = 1
  942. return
  943. }
  944. @(require_results)
  945. matrix4_from_euler_angles_yxy_f64 :: proc "contextless" (t1, t2, t3: f64) -> (m: Matrix4f64) {
  946. c1 := math.cos(t1)
  947. s1 := math.sin(t1)
  948. c2 := math.cos(t2)
  949. s2 := math.sin(t2)
  950. c3 := math.cos(t3)
  951. s3 := math.sin(t3)
  952. m[0, 0] = c1 * c3 - c2 * s1 * s3
  953. m[1, 0] = s2* s3
  954. m[2, 0] =-c3 * s1 - c1 * c2 * s3
  955. m[3, 0] = 0
  956. m[0, 1] = s1 * s2
  957. m[1, 1] = c2
  958. m[2, 1] = c1 * s2
  959. m[3, 1] = 0
  960. m[0, 2] = c1 * s3 + c2 * c3 * s1
  961. m[1, 2] =-c3 * s2
  962. m[2, 2] = c1 * c2 * c3 - s1 * s3
  963. m[3, 2] = 0
  964. m[0, 3] = 0
  965. m[1, 3] = 0
  966. m[2, 3] = 0
  967. m[3, 3] = 1
  968. return
  969. }
  970. @(require_results)
  971. matrix4_from_euler_angles_yzy_f64 :: proc "contextless" (t1, t2, t3: f64) -> (m: Matrix4f64) {
  972. c1 := math.cos(t1)
  973. s1 := math.sin(t1)
  974. c2 := math.cos(t2)
  975. s2 := math.sin(t2)
  976. c3 := math.cos(t3)
  977. s3 := math.sin(t3)
  978. m[0, 0] = c1 * c2 * c3 - s1 * s3
  979. m[1, 0] = c3 * s2
  980. m[2, 0] =-c1 * s3 - c2 * c3 * s1
  981. m[3, 0] = 0
  982. m[0, 1] =-c1 * s2
  983. m[1, 1] = c2
  984. m[2, 1] = s1 * s2
  985. m[3, 1] = 0
  986. m[0, 2] = c3 * s1 + c1 * c2 * s3
  987. m[1, 2] = s2 * s3
  988. m[2, 2] = c1 * c3 - c2 * s1 * s3
  989. m[3, 2] = 0
  990. m[0, 3] = 0
  991. m[1, 3] = 0
  992. m[2, 3] = 0
  993. m[3, 3] = 1
  994. return
  995. }
  996. @(require_results)
  997. matrix4_from_euler_angles_zyz_f64 :: proc "contextless" (t1, t2, t3: f64) -> (m: Matrix4f64) {
  998. c1 := math.cos(t1)
  999. s1 := math.sin(t1)
  1000. c2 := math.cos(t2)
  1001. s2 := math.sin(t2)
  1002. c3 := math.cos(t3)
  1003. s3 := math.sin(t3)
  1004. m[0, 0] = c1 * c2 * c3 - s1 * s3
  1005. m[1, 0] = c1 * s3 + c2 * c3 * s1
  1006. m[2, 0] =-c3 * s2
  1007. m[3, 0] = 0
  1008. m[0, 1] =-c3 * s1 - c1 * c2 * s3
  1009. m[1, 1] = c1 * c3 - c2 * s1 * s3
  1010. m[2, 1] = s2 * s3
  1011. m[3, 1] = 0
  1012. m[0, 2] = c1 * s2
  1013. m[1, 2] = s1 * s2
  1014. m[2, 2] = c2
  1015. m[3, 2] = 0
  1016. m[0, 3] = 0
  1017. m[1, 3] = 0
  1018. m[2, 3] = 0
  1019. m[3, 3] = 1
  1020. return
  1021. }
  1022. @(require_results)
  1023. matrix4_from_euler_angles_zxz_f64 :: proc "contextless" (t1, t2, t3: f64) -> (m: Matrix4f64) {
  1024. c1 := math.cos(t1)
  1025. s1 := math.sin(t1)
  1026. c2 := math.cos(t2)
  1027. s2 := math.sin(t2)
  1028. c3 := math.cos(t3)
  1029. s3 := math.sin(t3)
  1030. m[0, 0] = c1 * c3 - c2 * s1 * s3
  1031. m[1, 0] = c3 * s1 + c1 * c2 * s3
  1032. m[2, 0] = s2 *s3
  1033. m[3, 0] = 0
  1034. m[0, 1] =-c1 * s3 - c2 * c3 * s1
  1035. m[1, 1] = c1 * c2 * c3 - s1 * s3
  1036. m[2, 1] = c3 * s2
  1037. m[3, 1] = 0
  1038. m[0, 2] = s1 * s2
  1039. m[1, 2] =-c1 * s2
  1040. m[2, 2] = c2
  1041. m[3, 2] = 0
  1042. m[0, 3] = 0
  1043. m[1, 3] = 0
  1044. m[2, 3] = 0
  1045. m[3, 3] = 1
  1046. return
  1047. }
  1048. @(require_results)
  1049. matrix4_from_euler_angles_xzy_f64 :: proc "contextless" (t1, t2, t3: f64) -> (m: Matrix4f64) {
  1050. c1 := math.cos(t1)
  1051. s1 := math.sin(t1)
  1052. c2 := math.cos(t2)
  1053. s2 := math.sin(t2)
  1054. c3 := math.cos(t3)
  1055. s3 := math.sin(t3)
  1056. m[0, 0] = c2 * c3
  1057. m[1, 0] = s1 * s3 + c1 * c3 * s2
  1058. m[2, 0] = c3 * s1 * s2 - c1 * s3
  1059. m[3, 0] = 0
  1060. m[0, 1] =-s2
  1061. m[1, 1] = c1 * c2
  1062. m[2, 1] = c2 * s1
  1063. m[3, 1] = 0
  1064. m[0, 2] = c2 * s3
  1065. m[1, 2] = c1 * s2 * s3 - c3 * s1
  1066. m[2, 2] = c1 * c3 + s1 * s2 *s3
  1067. m[3, 2] = 0
  1068. m[0, 3] = 0
  1069. m[1, 3] = 0
  1070. m[2, 3] = 0
  1071. m[3, 3] = 1
  1072. return
  1073. }
  1074. @(require_results)
  1075. matrix4_from_euler_angles_yzx_f64 :: proc "contextless" (t1, t2, t3: f64) -> (m: Matrix4f64) {
  1076. c1 := math.cos(t1)
  1077. s1 := math.sin(t1)
  1078. c2 := math.cos(t2)
  1079. s2 := math.sin(t2)
  1080. c3 := math.cos(t3)
  1081. s3 := math.sin(t3)
  1082. m[0, 0] = c1 * c2
  1083. m[1, 0] = s2
  1084. m[2, 0] =-c2 * s1
  1085. m[3, 0] = 0
  1086. m[0, 1] = s1 * s3 - c1 * c3 * s2
  1087. m[1, 1] = c2 * c3
  1088. m[2, 1] = c1 * s3 + c3 * s1 * s2
  1089. m[3, 1] = 0
  1090. m[0, 2] = c3 * s1 + c1 * s2 * s3
  1091. m[1, 2] =-c2 * s3
  1092. m[2, 2] = c1 * c3 - s1 * s2 * s3
  1093. m[3, 2] = 0
  1094. m[0, 3] = 0
  1095. m[1, 3] = 0
  1096. m[2, 3] = 0
  1097. m[3, 3] = 1
  1098. return
  1099. }
  1100. @(require_results)
  1101. matrix4_from_euler_angles_zyx_f64 :: proc "contextless" (t1, t2, t3: f64) -> (m: Matrix4f64) {
  1102. c1 := math.cos(t1)
  1103. s1 := math.sin(t1)
  1104. c2 := math.cos(t2)
  1105. s2 := math.sin(t2)
  1106. c3 := math.cos(t3)
  1107. s3 := math.sin(t3)
  1108. m[0, 0] = c1 * c2
  1109. m[1, 0] = c2 * s1
  1110. m[2, 0] =-s2
  1111. m[3, 0] = 0
  1112. m[0, 1] = c1 * s2 * s3 - c3 * s1
  1113. m[1, 1] = c1 * c3 + s1 * s2 * s3
  1114. m[2, 1] = c2 * s3
  1115. m[3, 1] = 0
  1116. m[0, 2] = s1 * s3 + c1 * c3 * s2
  1117. m[1, 2] = c3 * s1 * s2 - c1 * s3
  1118. m[2, 2] = c2 * c3
  1119. m[3, 2] = 0
  1120. m[0, 3] = 0
  1121. m[1, 3] = 0
  1122. m[2, 3] = 0
  1123. m[3, 3] = 1
  1124. return
  1125. }
  1126. @(require_results)
  1127. matrix4_from_euler_angles_zxy_f64 :: proc "contextless" (t1, t2, t3: f64) -> (m: Matrix4f64) {
  1128. c1 := math.cos(t1)
  1129. s1 := math.sin(t1)
  1130. c2 := math.cos(t2)
  1131. s2 := math.sin(t2)
  1132. c3 := math.cos(t3)
  1133. s3 := math.sin(t3)
  1134. m[0, 0] = c1 * c3 - s1 * s2 * s3
  1135. m[1, 0] = c3 * s1 + c1 * s2 * s3
  1136. m[2, 0] =-c2 * s3
  1137. m[3, 0] = 0
  1138. m[0, 1] =-c2 * s1
  1139. m[1, 1] = c1 * c2
  1140. m[2, 1] = s2
  1141. m[3, 1] = 0
  1142. m[0, 2] = c1 * s3 + c3 * s1 * s2
  1143. m[1, 2] = s1 * s3 - c1 * c3 * s2
  1144. m[2, 2] = c2 * c3
  1145. m[3, 2] = 0
  1146. m[0, 3] = 0
  1147. m[1, 3] = 0
  1148. m[2, 3] = 0
  1149. m[3, 3] = 1
  1150. return
  1151. }
  1152. @(require_results)
  1153. matrix4_from_yaw_pitch_roll_f64 :: proc "contextless" (yaw, pitch, roll: f64) -> (m: Matrix4f64) {
  1154. ch := math.cos(yaw)
  1155. sh := math.sin(yaw)
  1156. cp := math.cos(pitch)
  1157. sp := math.sin(pitch)
  1158. cb := math.cos(roll)
  1159. sb := math.sin(roll)
  1160. m[0, 0] = ch * cb + sh * sp * sb
  1161. m[1, 0] = sb * cp
  1162. m[2, 0] = -sh * cb + ch * sp * sb
  1163. m[3, 0] = 0
  1164. m[0, 1] = -ch * sb + sh * sp * cb
  1165. m[1, 1] = cb * cp
  1166. m[2, 1] = sb * sh + ch * sp * cb
  1167. m[3, 1] = 0
  1168. m[0, 2] = sh * cp
  1169. m[1, 2] = -sp
  1170. m[2, 2] = ch * cp
  1171. m[3, 2] = 0
  1172. m[0, 3] = 0
  1173. m[1, 3] = 0
  1174. m[2, 3] = 0
  1175. m[3, 3] = 1
  1176. return m
  1177. }
  1178. @(require_results)
  1179. euler_angles_xyz_from_matrix4_f64 :: proc "contextless" (m: Matrix4f64) -> (t1, t2, t3: f64) {
  1180. T1 := math.atan2(m[1, 2], m[2, 2])
  1181. C2 := math.sqrt(m[0, 0]*m[0, 0] + m[0, 1]*m[0, 1])
  1182. T2 := math.atan2(-m[0, 2], C2)
  1183. S1 := math.sin(T1)
  1184. C1 := math.cos(T1)
  1185. T3 := math.atan2(S1*m[2, 0] - C1*m[1, 0], C1*m[1, 1] - S1*m[2, 1])
  1186. t1 = -T1
  1187. t2 = -T2
  1188. t3 = -T3
  1189. return
  1190. }
  1191. @(require_results)
  1192. euler_angles_yxz_from_matrix4_f64 :: proc "contextless" (m: Matrix4f64) -> (t1, t2, t3: f64) {
  1193. T1 := math.atan2(m[0, 2], m[2, 2])
  1194. C2 := math.sqrt(m[1, 0]*m[1, 0] + m[1, 1]*m[1, 1])
  1195. T2 := math.atan2(-m[1, 2], C2)
  1196. S1 := math.sin(T1)
  1197. C1 := math.cos(T1)
  1198. T3 := math.atan2(S1*m[2, 1] - C1*m[0, 1], C1*m[0, 0] - S1*m[2, 0])
  1199. t1 = T1
  1200. t2 = T2
  1201. t3 = T3
  1202. return
  1203. }
  1204. @(require_results)
  1205. euler_angles_xzx_from_matrix4_f64 :: proc "contextless" (m: Matrix4f64) -> (t1, t2, t3: f64) {
  1206. T1 := math.atan2(m[2, 0], m[1, 0])
  1207. S2 := math.sqrt(m[0, 1]*m[0, 1] + m[0, 2]*m[0, 2])
  1208. T2 := math.atan2(S2, m[0, 0])
  1209. S1 := math.sin(T1)
  1210. C1 := math.cos(T1)
  1211. T3 := math.atan2(C1*m[2, 1] - S1*m[1, 1], C1*m[2, 2] - S1*m[1, 2])
  1212. t1 = T1
  1213. t2 = T2
  1214. t3 = T3
  1215. return
  1216. }
  1217. @(require_results)
  1218. euler_angles_xyx_from_matrix4_f64 :: proc "contextless" (m: Matrix4f64) -> (t1, t2, t3: f64) {
  1219. T1 := math.atan2(m[1, 0], -m[2, 0])
  1220. S2 := math.sqrt(m[0, 1]*m[0, 1] + m[0, 2]*m[0, 2])
  1221. T2 := math.atan2(S2, m[0, 0])
  1222. S1 := math.sin(T1)
  1223. C1 := math.cos(T1)
  1224. T3 := math.atan2(-C1*m[1, 2] - S1*m[2, 2], C1*m[1, 1] + S1*m[2, 1])
  1225. t1 = T1
  1226. t2 = T2
  1227. t3 = T3
  1228. return
  1229. }
  1230. @(require_results)
  1231. euler_angles_yxy_from_matrix4_f64 :: proc "contextless" (m: Matrix4f64) -> (t1, t2, t3: f64) {
  1232. T1 := math.atan2(m[0, 1], m[2, 1])
  1233. S2 := math.sqrt(m[1, 0]*m[1, 0] + m[1, 2]*m[1, 2])
  1234. T2 := math.atan2(S2, m[1, 1])
  1235. S1 := math.sin(T1)
  1236. C1 := math.cos(T1)
  1237. T3 := math.atan2(C1*m[0, 2] - S1*m[2, 2], C1*m[0, 0] - S1*m[2, 0])
  1238. t1 = T1
  1239. t2 = T2
  1240. t3 = T3
  1241. return
  1242. }
  1243. @(require_results)
  1244. euler_angles_yzy_from_matrix4_f64 :: proc "contextless" (m: Matrix4f64) -> (t1, t2, t3: f64) {
  1245. T1 := math.atan2(m[2, 1], -m[0, 1])
  1246. S2 := math.sqrt(m[1, 0]*m[1, 0] + m[1, 2]*m[1, 2])
  1247. T2 := math.atan2(S2, m[1, 1])
  1248. S1 := math.sin(T1)
  1249. C1 := math.cos(T1)
  1250. T3 := math.atan2(-S1*m[0, 0] - C1*m[2, 0], S1*m[0, 2] + C1*m[2, 2])
  1251. t1 = T1
  1252. t2 = T2
  1253. t3 = T3
  1254. return
  1255. }
  1256. @(require_results)
  1257. euler_angles_zyz_from_matrix4_f64 :: proc "contextless" (m: Matrix4f64) -> (t1, t2, t3: f64) {
  1258. T1 := math.atan2(m[1, 2], m[0, 2])
  1259. S2 := math.sqrt(m[2, 0]*m[2, 0] + m[2, 1]*m[2, 1])
  1260. T2 := math.atan2(S2, m[2, 2])
  1261. S1 := math.sin(T1)
  1262. C1 := math.cos(T1)
  1263. T3 := math.atan2(C1*m[1, 0] - S1*m[0, 0], C1*m[1, 1] - S1*m[0, 1])
  1264. t1 = T1
  1265. t2 = T2
  1266. t3 = T3
  1267. return
  1268. }
  1269. @(require_results)
  1270. euler_angles_zxz_from_matrix4_f64 :: proc "contextless" (m: Matrix4f64) -> (t1, t2, t3: f64) {
  1271. T1 := math.atan2(m[0, 2], -m[1, 2])
  1272. S2 := math.sqrt(m[2, 0]*m[2, 0] + m[2, 1]*m[2, 1])
  1273. T2 := math.atan2(S2, m[2, 2])
  1274. S1 := math.sin(T1)
  1275. C1 := math.cos(T1)
  1276. T3 := math.atan2(-C1*m[0, 1] - S1*m[1, 1], C1*m[0, 0] + S1*m[1, 0])
  1277. t1 = T1
  1278. t2 = T2
  1279. t3 = T3
  1280. return
  1281. }
  1282. @(require_results)
  1283. euler_angles_xzy_from_matrix4_f64 :: proc "contextless" (m: Matrix4f64) -> (t1, t2, t3: f64) {
  1284. T1 := math.atan2(m[2, 1], m[1, 1])
  1285. C2 := math.sqrt(m[0, 0]*m[0, 0] + m[0, 2]*m[0, 2])
  1286. T2 := math.atan2(-m[0, 1], C2)
  1287. S1 := math.sin(T1)
  1288. C1 := math.cos(T1)
  1289. T3 := math.atan2(S1*m[1, 0] - C1*m[2, 0], C1*m[2, 2] - S1*m[1, 2])
  1290. t1 = T1
  1291. t2 = T2
  1292. t3 = T3
  1293. return
  1294. }
  1295. @(require_results)
  1296. euler_angles_yzx_from_matrix4_f64 :: proc "contextless" (m: Matrix4f64) -> (t1, t2, t3: f64) {
  1297. T1 := math.atan2(-m[2, 0], m[0, 0])
  1298. C2 := math.sqrt(m[1, 1]*m[1, 1] + m[1, 2]*m[1, 2])
  1299. T2 := math.atan2(m[1, 0], C2)
  1300. S1 := math.sin(T1)
  1301. C1 := math.cos(T1)
  1302. T3 := math.atan2(S1*m[0, 1] + C1*m[2, 1], S1*m[0, 2] + C1*m[2, 2])
  1303. t1 = T1
  1304. t2 = T2
  1305. t3 = T3
  1306. return
  1307. }
  1308. @(require_results)
  1309. euler_angles_zyx_from_matrix4_f64 :: proc "contextless" (m: Matrix4f64) -> (t1, t2, t3: f64) {
  1310. T1 := math.atan2(m[1, 0], m[0, 0])
  1311. C2 := math.sqrt(m[2, 1]*m[2, 1] + m[2, 2]*m[2, 2])
  1312. T2 := math.atan2(-m[2, 0], C2)
  1313. S1 := math.sin(T1)
  1314. C1 := math.cos(T1)
  1315. T3 := math.atan2(S1*m[0, 2] - C1*m[1, 2], C1*m[1, 1] - S1*m[0, 1])
  1316. t1 = T1
  1317. t2 = T2
  1318. t3 = T3
  1319. return
  1320. }
  1321. @(require_results)
  1322. euler_angles_zxy_from_matrix4_f64 :: proc "contextless" (m: Matrix4f64) -> (t1, t2, t3: f64) {
  1323. T1 := math.atan2(-m[0, 1], m[1, 1])
  1324. C2 := math.sqrt(m[2, 0]*m[2, 0] + m[2, 2]*m[2, 2])
  1325. T2 := math.atan2(m[2, 1], C2)
  1326. S1 := math.sin(T1)
  1327. C1 := math.cos(T1)
  1328. T3 := math.atan2(C1*m[0, 2] + S1*m[1, 2], C1*m[0, 0] + S1*m[1, 0])
  1329. t1 = T1
  1330. t2 = T2
  1331. t3 = T3
  1332. return
  1333. }