rotation_misc.inc 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281
  1. #if defined _inc_rotation_misc
  2. #undef _inc_rotation_misc
  3. #endif
  4. #if defined _rotation_misc_included
  5. #endinput
  6. #endif
  7. #define _rotation_misc_included
  8. #include "rotation.inc"
  9. // unfinished or random functions
  10. // misc - Get real / offset position of attached vehicle objects
  11. stock GetVehicleObjectPositionWorld(vehicleid,
  12. Float: att_X, Float: att_Y, Float: att_Z, Float: att_rotX, Float: att_rotY, Float: att_rotZ,
  13. &Float: X, &Float: Y, &Float: Z, &Float: rotX, &Float: rotY, &Float: rotZ
  14. ) {
  15. if(GetVehiclePos(vehicleid, X, Y, Z)) {
  16. new
  17. Float: w,
  18. Float: x,
  19. Float: y,
  20. Float: z,
  21. Float: matrix1[4][4],
  22. Float: matrix2[4][4];
  23. GetVehicleRotationQuat(vehicleid, w, x, y, z);
  24. GetRotationMatrixFromEuler(matrix1, att_rotX, att_rotY, att_rotZ);
  25. GetRotationMatrixFromQuat(matrix2, w, x, y, z);
  26. MatrixRotate(matrix2, att_X, att_Y, att_Z, 0.0, X, Y, Z);
  27. RotateMatrixWithMatrix(matrix1, matrix2);
  28. GetEulerFromMatrix(matrix1, rotX, rotY, rotZ);
  29. return true;
  30. }
  31. return false;
  32. }
  33. stock GetVehicleObjectPositionOffset(vehicleid,
  34. Float: X, Float: Y, Float: Z, Float: rotX, Float: rotY, Float: rotZ,
  35. &Float: att_X, &Float: att_Y, &Float: att_Z, &Float: att_rotX, &Float: att_rotY, &Float: att_rotZ
  36. ) {
  37. if(GetVehiclePos(vehicleid, att_X, att_Y, att_Z)) {
  38. new
  39. Float: w,
  40. Float: x,
  41. Float: y,
  42. Float: z,
  43. Float: matrix1[4][4],
  44. Float: matrix2[4][4];
  45. GetVehicleRotationQuat(vehicleid, w, x, y, z);
  46. GetRotationMatrixFromEuler(matrix1, rotX, rotY, rotZ);
  47. GetRotationMatrixFromQuat(matrix2, -w, x, y, z);
  48. X -= att_X;
  49. Y -= att_Y;
  50. Z -= att_Z;
  51. att_X = matrix2[0][0] * X + matrix2[0][1] * Y + matrix2[0][2] * Z;
  52. att_Y = matrix2[1][0] * X + matrix2[1][1] * Y + matrix2[1][2] * Z;
  53. att_Z = matrix2[2][0] * X + matrix2[2][1] * Y + matrix2[2][2] * Z;
  54. RotateMatrixWithMatrix(matrix1, matrix2);
  55. GetEulerFromMatrix(matrix1, att_rotX, att_rotY, att_rotZ);
  56. return true;
  57. }
  58. return false;
  59. }
  60. stock MatrixMulMatrix(Float: A[][], Float: B[][], Float: C[][], a1 = sizeof A, a2 = sizeof A[], b1 = sizeof B, b2 = sizeof B[], c1 = sizeof C, c2 = sizeof C[]) {
  61. if(a1 == c1 && a2 == b1 && b2 == c2) {
  62. for(a1 = 0; a1 < c1; ++a1) {
  63. for(b2 = 0; b2 < c2; ++b2) {
  64. for(C[a1][b2] = Float: a2 = 0; a2 < b1; ++a2) {
  65. C[a1][b2] += A[a1][a2] * B[a2][b2];
  66. }
  67. }
  68. }
  69. }
  70. }
  71. stock GetRotMatX(Float: matrix[][], Float: angle) {
  72. matrix[0][0] = 1.0;
  73. matrix[0][1] = 0.0;
  74. matrix[0][2] = 0.0;
  75. matrix[1][0] = 0.0;
  76. matrix[2][0] = 0.0;
  77. matrix[2][2] = matrix[1][1] = floatcos(angle, degrees);
  78. matrix[1][2] = -(matrix[2][1] = floatsin(angle, degrees));
  79. }
  80. stock GetRotMatY(Float: matrix[][], Float: angle) {
  81. matrix[1][1] = 1.0;
  82. matrix[0][1] = 0.0;
  83. matrix[1][0] = 0.0;
  84. matrix[1][2] = 0.0;
  85. matrix[2][1] = 0.0;
  86. matrix[2][2] = matrix[0][0] = floatcos(angle, degrees);
  87. matrix[2][0] = -(matrix[0][2] = floatsin(angle, degrees));
  88. }
  89. stock GetRotMatZ(Float: matrix[][], Float: angle) {
  90. matrix[2][2] = 1.0;
  91. matrix[0][2] = 0.0;
  92. matrix[1][2] = 0.0;
  93. matrix[2][0] = 0.0;
  94. matrix[2][1] = 0.0;
  95. matrix[1][1] = matrix[0][0] = floatcos(angle, degrees);
  96. matrix[0][1] = -(matrix[1][0] = floatsin(angle, degrees));
  97. }
  98. stock MatrixSub(Float: A[][], Float: B[][], Float: C[][], a1 = sizeof A, a2 = sizeof A[], b1 = sizeof B, b2 = sizeof B[], c1 = sizeof C, c2 = sizeof C[]) {
  99. if(a1 == b1 && b1 == c1 && a2 == b2 && b2 == c2) {
  100. for(a1 = 0; a1 < b1; ++a1) {
  101. for(a2 = 0; a2 < b2; ++a2) {
  102. C[a1][a2] = A[a1][a2] - B[a1][a2];
  103. }
  104. }
  105. }
  106. }
  107. stock GetRotFromFlight(Float: pitch, Float: roll, Float: yaw, & Float: rX, & Float: rY, & Float: rZ) {
  108. new
  109. Float: cosY = floatcos(roll, degrees),
  110. Float: sinX = floatsin(pitch, degrees);
  111. rX = cosY * sinX;
  112. if(rX > 0.9999) {
  113. rX = 90.0;
  114. rY = 0.0;
  115. rZ = yaw;
  116. } else if(rX < -0.9999) {
  117. rX = -90.0;
  118. rY = 0.0;
  119. rZ = yaw;
  120. } else {
  121. new
  122. Float: cosX = floatcos(pitch, degrees),
  123. Float: cosZ = floatcos(yaw, degrees),
  124. Float: sinY = floatsin(roll, degrees),
  125. Float: sinZ = floatsin(yaw, degrees);
  126. rX = asin(rX);
  127. rY = atan2(sinY, cosY * cosX);
  128. rZ = atan2(cosX * sinZ - cosZ * sinY * sinX, cosZ * cosX + sinZ * sinY * sinX);
  129. }
  130. }
  131. stock GetFlightFromRot(Float: rX, Float: rY, Float: rZ, & Float: pitch, & Float: roll, & Float: yaw) {
  132. new
  133. Float: cosX = floatcos(rX, degrees),
  134. Float: sinY = floatsin(rY, degrees);
  135. roll = cosX * sinY;
  136. if(roll < -0.9999) {
  137. pitch = 0.0;
  138. roll = 90.0;
  139. yaw = rZ;
  140. } else if(roll > 0.9999) {
  141. pitch = 0.0;
  142. roll = -90.0;
  143. yaw = rZ;
  144. } else {
  145. new
  146. Float: cosY = floatcos(rY, degrees),
  147. Float: cosZ = floatcos(rZ, degrees),
  148. Float: sinX = floatsin(rX, degrees),
  149. Float: sinZ = floatsin(rZ, degrees);
  150. roll = asin(roll);
  151. pitch = atan2(sinX, cosX * cosY);
  152. yaw = atan2(sinZ * cosY + cosZ * sinX * sinY, cosZ * cosY - sinZ * sinX * sinY);
  153. }
  154. }
  155. // (w + xi + yj + zk)(ai + bj + ck)(w - xi - yj - zk)
  156. // ((ai + bj + ck)w + (-a + bk -cj)x + (-ak - b + ci)y + (aj - bi -c)z)(w - xi - yj - zk)
  157. // ((-a*x - b*y - c*z) + (w*a - b*z + c*y)i + (a*z + w*b - c*x)j + (-a*y + b*x + w*c)k) * (w - xi - yj - zk)
  158. // ((-a*x*w - b*y*w - c*z*w) + (w^2*a - b*z*w + c*y*w)i + (a*z*w + w^2*b - c*x*w)j + (-a*y*w + b*x*w + w^2*c)k) +
  159. // ((a*x^2 + b*y*x + c*z*x)i + (w*a*x - b*z*x + c*y*x) + (a*z*x + w*b*x - c*x^2)k + (a*y*x - b*x^2 - w*c*x)j) +
  160. // ((a*x*y + b*y^2 + c*z*y)j + (-w*a*y + b*z*y - c*y^2)k + (a*z*y + w*b*y - c*x*y) + (-a*y^2 + b*x*y + w*c*y)i) +
  161. // ((a*x*z + b*y*z + c*z^2)k + (w*a*z - b*z^2 + c*y*z)j + (-a*z^2 - w*b*z + c*x*z)i + (-a*y*z + b*x*z + w*c*z))
  162. // ((-a*x*w - b*y*w - c*z*w) + (w*a*x - b*z*x + c*y*x) + (a*z*y + w*b*y - c*x*y) + (-a*y*z + b*x*z + w*c*z)) +
  163. // ((w^2*a - b*z*w + c*y*w) + (a*x^2 + b*y*x + c*z*x) + (-a*y^2 + b*x*y + w*c*y) + (-a*z^2 - w*b*z + c*x*z))i +
  164. // ((a*z*w + w^2*b - c*x*w) + (a*y*x - b*x^2 - w*c*x) + (a*x*y + b*y^2 + c*z*y) + (w*a*z - b*z^2 + c*y*z))j +
  165. // ((-a*y*w + b*x*w + w^2*c) + (a*z*x + w*b*x - c*x^2) + (-w*a*y + b*z*y - c*y^2) + (a*x*z + b*y*z + c*z^2))k
  166. // (w^2*a + a*x^2 - a*y^2 - a*z^2 + 2*((c*y*w + c*x*z + b*y*x) - b*z*w))i +
  167. // (w^2*b - b*x^2 + b*y^2 - b*z^2 + 2*((a*z*w + a*y*x + c*z*y) - c*x*w))j +
  168. // (w^2*c - c*x^2 - c*y^2 + c*z^2 + 2*((b*x*w + b*z*y + a*x*z) - a*y*w))k
  169. stock QuatMul(Float: w1, Float: x1, Float: y1, Float: z1, Float: w2, Float: x2, Float: y2, Float: z2, & Float: w, & Float: x, & Float: y, & Float: z) {
  170. // v1v2 = (v1 x v2) - (v1 . v2) | (w1, v1)(w2, v2) = (w1 * w2 - v1 . v2), (w1 * v2) + (w2 * v1) + (v1 x v2)
  171. w = (w1*w2 - x1*x2 - y1*y2 - z1*z2);
  172. x = (w1*x2 + w2*x1 + y1*z2 - z1*y2);
  173. y = (w1*y2 + w2*y1 + z1*x2 - x1*z2);
  174. z = (w1*z2 + w2*z1 + x1*y2 - y1*x2);
  175. }
  176. stock CrossProduct(Float: x1, Float: y1, Float: z1, Float: x2, Float: y2, Float: z2, & Float: x, & Float: y, & Float: z) {
  177. x = y1 * z2 - z1 * y2;
  178. y = z1 * x2 - x1 * z2;
  179. z = x1 * y2 - y1 * x2;
  180. }
  181. stock QuatRotateVector(Float: w, Float: i, Float: j, Float: k, Float: X, Float: Y, Float: Z, & Float: x, & Float: y, & Float: z) {
  182. // q * v * q^-1
  183. // x = (w*w*X + X*i*i - X*j*j - X*k*k + 2.0*((Z*j*w + Z*i*k + Y*j*i) - Y*k*w));
  184. // y = (w*w*Y - Y*i*i + Y*j*j - Y*k*k + 2.0*((X*k*w + X*j*i + Z*k*j) - Z*i*w));
  185. // z = (w*w*Z - Z*i*i - Z*j*j + Z*k*k + 2.0*((Y*i*w + Y*k*j + X*i*k) - X*j*w));
  186. // after a lot of computing you get to the formula "v1 + 2*(w*(v1 x v2) + v1x(v1 x v2));" but only valid with versors (unit quaternion)
  187. // x = (X + 2.0*(w*(j*Z - k*Y) + j*(i*Y - j*X) - k*(k*X - i*Z)));
  188. // y = (Y + 2.0*(w*(k*X - i*Z) + k*(j*Z - k*Y) - i*(i*Y - j*X)));
  189. // z = (Z + 2.0*(w*(i*Y - j*X) + i*(k*X - i*Z) - j*(j*Z - k*Y)));
  190. // x = (X + 2.0*(w*(j*Z - k*Y) + i*(j*Y + k*Z) - X*(j*j + k*k)));
  191. // y = (Y + 2.0*(w*(k*X - i*Z) + k*(j*Z - k*Y) - i*(i*Y - j*X)));
  192. // z = (Z + 2.0*(w*(i*Y - j*X) + i*(k*X - i*Z) - j*(j*Z - k*Y)));
  193. // 18 muls, 12 adds
  194. // CrossProduct(i, j, k, X, Y, Z, x, y, z);
  195. // CrossProduct(i, j, k, x, y, z, i, j, k);
  196. // x = (X + 2.0 * (w * x + i));
  197. // y = (Y + 2.0 * (w * y + j));
  198. // z = (Z + 2.0 * (w * z + k));
  199. // 15 muls, 15 adds
  200. CrossProduct(i, j, k, X, Y, Z, x, y, z);
  201. CrossProduct(
  202. i + i,
  203. j + j,
  204. k + k,
  205. x + w * X,
  206. y + w * Y,
  207. z + w * Z,
  208. x, y, z
  209. );
  210. x += X;
  211. y += Y;
  212. z += Z;
  213. }
  214. stock GetVehicleRelativePos(vehicleid, & Float: x, & Float: y, & Float: z, Float: oX = 0.0, Float: oY = 0.0, Float: oZ = 0.0) {
  215. if(GetVehiclePos(vehicleid, x, y, z) && ((_: oX != 0) || (_: oY != 0) || (_: oZ != 0))) {
  216. new
  217. Float: qW,
  218. Float: qX,
  219. Float: qY,
  220. Float: qZ
  221. ;
  222. GetVehicleRotationQuat(vehicleid, qW, qX, qY, qZ);
  223. QuatRotateVector(qW, -qX, -qY, -qZ, oX, oY, oZ, qX, qY, qZ);
  224. x += qX;
  225. y += qY;
  226. z += qZ;
  227. return true;
  228. }
  229. return false;
  230. }
  231. stock QuatForwardVector(Float: w, Float: i, Float: j, Float: k, & Float: x, & Float: y, & Float: z) {
  232. x = 2.0 * (j * i - k * w);
  233. y = 1.0 - 2.0 * (k * k + i * i);
  234. z = 2.0 * (i * w + j * k);
  235. }
  236. stock GetVehicleForwardVector(vehicleid, & Float: x, & Float: y, & Float: z) {
  237. if(GetVehicleRotationQuat(vehicleid, Float: vehicleid, x, y, z)) {
  238. QuatForwardVector(Float: vehicleid, -x, -y, -z, x, y, z);
  239. return true;
  240. }
  241. return false;
  242. }
  243. stock QuatRightVector(Float: w, Float: i, Float: j, Float: k, & Float: x, & Float: y, & Float: z) {
  244. x = 1.0 - 2.0 * (j * j + k * k);
  245. y = 2.0 * (k * w + i * j);
  246. z = 2.0 * (i * k - j * w);
  247. }
  248. stock GetVehicleRightVector(vehicleid, & Float: x, & Float: y, & Float: z) {
  249. if(GetVehicleRotationQuat(vehicleid, Float: vehicleid, x, y, z)) {
  250. QuatRightVector(Float: vehicleid, -x, -y, -z, x, y, z);
  251. return true;
  252. }
  253. return false;
  254. }
  255. stock QuatUpVector(Float: w, Float: i, Float: j, Float: k, & Float: x, & Float: y, & Float: z) {
  256. x = 2.0 * (j * w + k * i);
  257. y = 2.0 * (k * j - i * w);
  258. z = 1.0 - 2.0 * (i * i + j * j);
  259. }
  260. stock GetVehicleUpVector(vehicleid, & Float: x, & Float: y, & Float: z) {
  261. if(GetVehicleRotationQuat(vehicleid, Float: vehicleid, x, y, z)) {
  262. QuatUpVector(Float: vehicleid, -x, -y, -z, x, y, z);
  263. return true;
  264. }
  265. return false;
  266. }
  267. stock EulerVectorToQuat(Float: X, Float: Y, Float: Z, Float: angle, & Float: w, & Float: i, & Float: j, & Float: k, anglemode: mode = degrees) {
  268. if((w = VectorSize(X, Y, Z)) != 1.0) {
  269. X /= w;
  270. Y /= w;
  271. Z /= w;
  272. }
  273. angle /= 2.0;
  274. w = floatsin(angle, mode);
  275. i = X * w;
  276. j = Y * w;
  277. k = Z * w;
  278. w = floatcos(angle, mode);
  279. }
  280. // stock GetEulerFromEuler(Float: oX, Float: oY, Float: oZ, eulermode: omode, & Float: rX, & Float: rY, & Float: rZ, eulermode: mode = euler_samp) {
  281. // // new Float: matrix[3][3]; //
  282. // // GetRotationMatrixFromEuler(matrix, oX, oY, oZ, omode);
  283. // // GetEulerFromMatrix(matrix, rX, rY, rZ, mode);
  284. // GetQuatFromEuler(oX, oY, oZ, rX, oX, oY, oZ, omode);
  285. // GetEulerFromQuat(rX, oX, oY, oZ, rX, rY, rZ, mode);
  286. // #emit retn // tried to unravel these but to much work
  287. // new
  288. // Float: cosX = floatcos(oX, degrees),
  289. // Float: sinY = floatsin(oY, degrees),
  290. // Float: cosY = floatcos(oY, degrees),
  291. // Float: cosZ = floatcos(oZ, degrees),
  292. // Float: sinX = floatsin(oX, degrees),
  293. // Float: sinZ = floatsin(oZ, degrees);
  294. // switch(omode) {
  295. // /*
  296. // matrix[1][1] = cosX * cosY;
  297. // matrix[1][2] = -sinX;
  298. // matrix[2][1] = cosY * sinX;
  299. // matrix[2][2] = cosX;
  300. // */
  301. // case euler_xzx: {
  302. // switch(mode) {
  303. // case euler_xzx: {
  304. // rX = oX;
  305. // rY = oZ;
  306. // rZ = oZ;
  307. // }
  308. // case euler_xyx: {
  309. // rX = oX + 90.0;
  310. // rY = oY;
  311. // rZ = oZ - 90.0;
  312. // }
  313. // case euler_yxy: {
  314. // rY = cosX * cosY * cosZ - sinX * sinZ;
  315. // if(rY > 0.9999) {
  316. // rX = atan2(sinY * sinZ, cosY);
  317. // rY = 0.0;
  318. // rZ = 0.0;
  319. // } else if(rY < -0.9999) {
  320. // rX = -atan2(sinY * sinZ, cosY);
  321. // rY = 180.0;
  322. // rZ = 0.0;
  323. // } else {
  324. // rX = atan2(-cosZ * sinY, cosX * sinZ + cosY * cosZ * sinX);
  325. // rY = acos(rY);
  326. // rZ = atan2(cosX * sinY, cosZ * sinX + cosX * cosY * sinZ);
  327. // }
  328. // }
  329. // case euler_yzy: {
  330. // rY = cosX * cosY * cosZ - sinX * sinZ;
  331. // if(rY > 0.9999) {
  332. // rX = atan2(sinY * sinZ, cosY);
  333. // rY = 0.0;
  334. // rZ = 0.0;
  335. // } else if(rY < -0.9999) {
  336. // rX = atan2(sinY * sinZ, -cosY);
  337. // rY = 180.0;
  338. // rZ = 0.0;
  339. // } else {
  340. // rX = atan2(cosX * sinZ + cosY * cosZ * sinX, cosZ * sinY);
  341. // rY = acos(rY);
  342. // rZ = -atan2(cosZ * sinX + cosX * cosY * sinZ, cosX * sinY);
  343. // }
  344. // }
  345. // case euler_zyz: {
  346. // rY = cosX * cosZ - cosY * sinX * sinZ;
  347. // if(rY > 0.9999) {
  348. // rX = atan2(cosX * sinY, cosY);
  349. // rY = 0.0;
  350. // rZ = 0.0;
  351. // } else if(rY < -0.9999) {
  352. // rX = atan2(cosX * sinY, cosY);
  353. // rY = 180.0;
  354. // rZ = 0.0;
  355. // } else {
  356. // rX = -atan2(cosZ * sinX + cosX * cosY * sinZ, sinY * sinZ);
  357. // rY = acos(rY);
  358. // rZ = atan2(cosX * sinZ + cosY * cosZ * sinX, -sinX * sinY);
  359. // }
  360. // }
  361. // case euler_zxz: {
  362. // rY = cosX * cosZ - cosY * sinX * sinZ;
  363. // if(rY > 0.9999) {
  364. // rX = atan2(cosX * sinY, cosY);
  365. // rY = 0.0;
  366. // rZ = 0.0;
  367. // } else if(rY < -0.9999) {
  368. // rX = atan2(cosX * sinY, cosY);
  369. // rY = 180.0;
  370. // rZ = 0.0;
  371. // } else {
  372. // rX = atan2(sinY * sinZ, cosZ * sinX + cosX * cosY * sinZ);
  373. // rY = acos(rY);
  374. // rZ = atan2(sinX * sinY, cosX * sinZ + cosY * cosZ * sinX);
  375. // }
  376. // }
  377. // case euler_xzy: {
  378. // rZ = cosZ * sinY;
  379. // if(rZ > 0.9999) {
  380. // rX = oX;
  381. // rY = 0.0;
  382. // rZ = 90.0;
  383. // } else if(rZ < -0.9999) {
  384. // rX = oX;
  385. // rY = 0.0;
  386. // rZ = -90.0;
  387. // } else {
  388. // rX = atan2(cosX * sinZ + cosY * cosZ * sinX, cosX * cosY * cosZ - sinX * sinZ);
  389. // rY = atan2(sinY * sinZ, cosY);
  390. // rZ = asin(rZ);
  391. // }
  392. // }
  393. // case euler_xyz: {
  394. // rY = sinY * sinZ;
  395. // if(rY > 0.9999) {
  396. // rX = 90.0 + oX;
  397. // rY = 90.0;
  398. // rZ = 0.0;
  399. // } else if(rY < -0.9999) {
  400. // rX = 90.0 + oX;
  401. // rY = -90.0;
  402. // rZ = 0.0;
  403. // } else {
  404. // rX = atan2(cosZ * sinX + cosX * cosY * sinZ, cosX * cosZ - cosY * sinX * sinZ);
  405. // rY = asin(rY);
  406. // rZ = atan2(cosZ * sinY, cosY);
  407. // }
  408. // }
  409. // case euler_yxz: {
  410. // rX = cosZ * sinX + cosX * cosY * sinZ;
  411. // if(rX > 0.9999) {
  412. // rX = 90.0;
  413. // rY = -atan2(cosZ * sinY, cosY);
  414. // rZ = 0.0;
  415. // } else if(rX < -0.9999) {
  416. // rX = -90.0;
  417. // rY = atan2(cosZ * sinY, cosY);
  418. // rZ = 0.0;
  419. // } else {
  420. // rX = asin(rX);
  421. // rY = atan2(sinY * sinZ, cosX * cosZ - cosY * sinX * sinZ);
  422. // rZ = atan2(cosX * sinY, cosX * cosY * cosZ - sinX * sinZ);
  423. // }
  424. // }
  425. // case euler_yzx: {
  426. // rZ = cosX * sinY;
  427. // if(rZ > 0.9999) {
  428. // rX = 0.0;
  429. // rY = oZ;
  430. // rZ = 90.0;
  431. // } else if(rZ < -0.9999) {
  432. // rX = 0.0;
  433. // rY = 180.0 - oZ;
  434. // rZ = -90.0;
  435. // } else {
  436. // rX = atan2(cosZ * sinX + cosX * cosY * sinZ, cosX * cosY * cosZ - sinX * sinZ);
  437. // rY = -atan2(sinX * sinY, cosY);
  438. // rZ = asin(rZ);
  439. // }
  440. // }
  441. // case euler_zyx: {
  442. // rY = sinX * sinY;
  443. // if(rY < -0.9999) {
  444. // rX = 0.0;
  445. // rY = 90.0;
  446. // rZ = 90.0 - oZ;
  447. // } else if(rY > 0.9999) {
  448. // rX = 0.0;
  449. // rY = -90.0;
  450. // rZ = oZ - 90.0;
  451. // } else {
  452. // rX = atan2(cosX * sinZ + cosY * cosZ * sinX, cosX * cosZ - cosY * sinX * sinZ);
  453. // rY = -asin(rY);
  454. // rZ = atan2(cosX * sinY, cosY);
  455. // }
  456. // }
  457. // case euler_zxy: {
  458. // rX = cosX * sinZ + cosY * cosZ * sinX;
  459. // if(rX > 0.9999) {
  460. // rX = 90.0;
  461. // rY = 0.0;
  462. // rZ = atan2(cosX * sinY, cosY);
  463. // } else if(rX < -0.9999) {
  464. // rX = -90.0;
  465. // rY = 0.0;
  466. // rZ = atan2(cosX * sinY, cosY);
  467. // } else {
  468. // rX = asin(rX);
  469. // rY = -atan2(sinX * sinY, cosX * cosZ - cosY * sinX * sinZ);
  470. // rZ = atan2(cosZ * sinY, cosX * cosY * cosZ - sinX * sinZ);
  471. // }
  472. // }
  473. // }
  474. // }
  475. // /*
  476. // matrix[1][1] = cosX;
  477. // matrix[1][2] = - cosY * sinX;
  478. // matrix[2][1] = sinX;
  479. // matrix[2][2] = cosX * cosY;
  480. // */
  481. // case euler_xyx: {
  482. // switch(mode) {
  483. // case euler_xzx: {
  484. // rX = oX - 90.0;
  485. // rY = oY;
  486. // rZ = oZ + 90.0;
  487. // }
  488. // case euler_xyx: {
  489. // rX = oX;
  490. // rY = oY;
  491. // rZ = oZ;
  492. // }
  493. // case euler_yxy: {
  494. // rY = cosX * cosZ - cosY * sinX * sinZ;
  495. // if(rY > 0.9999) {
  496. // rX = atan2(cosX * sinY, cosY); // -20, 00
  497. // rY = 0.0;
  498. // rZ = 0.0;
  499. // } else if(rY < -0.9999) {
  500. // rX = atan2(cosX * sinY, cosY);
  501. // rY = 180.0;
  502. // rZ = 0.0;
  503. // } else {
  504. // rX = atan2(sinY * sinZ, cosZ * sinX + cosX * cosY * sinZ);
  505. // rY = acos(rY);
  506. // rZ = atan2(sinX * sinY, cosX * sinZ + cosY * cosZ * sinX);
  507. // }
  508. // }
  509. // case euler_yzy: {
  510. // rY = cosX * cosZ - cosY * sinX * sinZ;
  511. // if(rY > 0.9999) {
  512. // rX = atan2(cosX * sinY, cosY); // -20, 00
  513. // rY = 0.0;
  514. // rZ = 0.0;
  515. // } else if(rY < -0.9999) {
  516. // rX = atan2(cosX * sinY, cosY);
  517. // rY = 180.0;
  518. // rZ = 0.0;
  519. // } else {
  520. // rX = atan2(cosZ * sinX + cosX * cosY * sinZ, -sinY * sinZ);
  521. // rY = acos(rY);
  522. // rZ = -atan2(cosX * sinZ + cosY * cosZ * sinX, sinX * sinY);
  523. // }
  524. // }
  525. // case euler_zyz: {
  526. // rY = cosX * cosY * cosZ - sinX * sinZ;
  527. // if(rY > 0.9999) {
  528. // rX = atan2(sinX * sinY, cosY); // -01, 11
  529. // rY = 0.0;
  530. // rZ = 0.0;
  531. // } else if(rY < -0.9999) {
  532. // rX = atan2(sinX * sinY, cosY);
  533. // rY = 180.0;
  534. // rZ = 0.0;
  535. // } else {
  536. // rX = -atan2(cosX * sinZ + cosY * cosZ * sinX, cosZ * sinY);
  537. // rY = acos(rY);
  538. // rZ = atan2(cosZ * sinX + cosX * cosY * sinZ, cosX * sinY);
  539. // }
  540. // }
  541. // case euler_zxz: {
  542. // rY = cosX * cosY * cosZ - sinX * sinZ;
  543. // if(rY > 0.9999) {
  544. // rX = atan2(sinX * sinY, cosY); // -01, 11
  545. // rY = 0.0;
  546. // rZ = 0.0;
  547. // } else if(rY < -0.9999) {
  548. // rX = atan2(sinX * sinY, cosY);
  549. // rY = 180.0;
  550. // rZ = 0.0;
  551. // } else {
  552. // rX = atan2(cosZ * sinY, cosX * sinZ + cosY * cosZ * sinX);
  553. // rY = acos(rY);
  554. // rZ = -atan2(cosX * sinY, cosZ * sinX + cosX * cosY * sinZ);
  555. // }
  556. // }
  557. // case euler_xzy: {
  558. // rZ = sinY * sinZ;
  559. // if(rZ < -0.9999) {
  560. // rX = oX - 90.0; // -12, 22
  561. // rY = 0.0;
  562. // rZ = 90.0;
  563. // } else if(rZ > 0.9999) {
  564. // rX = oX - 90.0;
  565. // rY = 0.0;
  566. // rZ = -90.0;
  567. // } else {
  568. // rX = atan2(cosZ * sinX + cosX * cosY * sinZ, cosX * cosZ - cosY * sinX * sinZ);
  569. // rY = atan2(cosZ * sinY, cosY);
  570. // rZ = -asin(rZ);
  571. // }
  572. // }
  573. // case euler_xyz: {
  574. // rY = cosZ * sinY;
  575. // if(rY > 0.9999) {
  576. // rX = oX; // 10, -20
  577. // rY = 90.0;
  578. // rZ = 0.0;
  579. // } else if(rY < -0.9999) {
  580. // rX = oX;
  581. // rY = -90.0;
  582. // rZ = 0.0;
  583. // } else {
  584. // rX = atan2(cosX * sinZ + cosY * cosZ * sinX, cosX * cosY * cosZ - sinX * sinZ);
  585. // rY = asin(rY);
  586. // rZ = -atan2(sinY * sinZ, cosY);
  587. // }
  588. // }
  589. // case euler_yxz: {
  590. // rX = cosX * sinZ + cosY * cosZ * sinX;
  591. // if(rX > 0.9999) {
  592. // rX = 90.0;
  593. // rY = atan2(cosX * sinY, cosY); // -20, 00
  594. // rZ = 0.0;
  595. // } else if(rX < -0.9999) {
  596. // rX = -90.0;
  597. // rY = atan2(cosX * sinY, cosY);
  598. // rZ = 0.0;
  599. // } else {
  600. // rX = asin(rX);
  601. // rY = atan2(cosZ * sinY, cosX * cosY * cosZ - sinX * sinZ);
  602. // rZ = atan2(sinX * sinY, cosX * cosZ - cosY * sinX * sinZ);
  603. // }
  604. // }
  605. // case euler_yzx: {
  606. // rZ = sinX * sinY;
  607. // if(rZ > 0.9999) {
  608. // rX = 0.0;
  609. // rY = 90.0 + oZ; // 21, -01
  610. // rZ = 90.0;
  611. // } else if(rZ < -0.9999) {
  612. // rX = 0.0;
  613. // rY = 90.0 - oZ;
  614. // rZ = -90.0;
  615. // } else {
  616. // rX = atan2(cosX * sinZ + cosY * cosZ * sinX, cosX * cosZ - cosY * sinX * sinZ);
  617. // rY = atan2(cosX * sinY, cosY);
  618. // rZ = asin(rZ);
  619. // }
  620. // }
  621. // case euler_zyx: { // pitch roll yaw
  622. // rY = cosX * sinY;
  623. // if(rY > 0.9999) {
  624. // rX = 0.0;
  625. // rY = 90.0;
  626. // rZ = -oZ; // -01, 11
  627. // } else if(rY < -0.9999) {
  628. // rX = 0.0;
  629. // rY = -90.0;
  630. // rZ = oZ;
  631. // } else {
  632. // rX = atan2(cosZ * sinX + cosX * cosY * sinZ, cosX * cosY * cosZ - sinX * sinZ);
  633. // rY = asin(rY);
  634. // rZ = atan2(sinX * sinY, cosY);
  635. // }
  636. // }
  637. // case euler_zxy: { // sa-mp
  638. // rX = cosZ * sinX + cosX * cosY * sinZ;
  639. // if(rX > 0.9999) {
  640. // rX = 90.0;
  641. // rY = 0.0;
  642. // rZ = atan2(sinX * sinY, cosY); // 02, -12
  643. // } else if(rX < -0.9999) {
  644. // rX = -90.0;
  645. // rY = 0.0;
  646. // rZ = atan2(sinX * sinY, cosY);
  647. // } else {
  648. // rX = asin(rX);
  649. // rY = atan2(cosX * sinY, cosX * cosY * cosZ - sinX * sinZ);
  650. // rZ = -atan2(sinY * sinZ, cosX * cosZ - cosY * sinX * sinZ);
  651. // }
  652. // }
  653. // }
  654. // }
  655. // /*
  656. // matrix[0][0] = cosX;
  657. // matrix[0][2] = cosY * sinX;
  658. // matrix[2][0] = -sinX;
  659. // matrix[2][2] = cosX * cosY;
  660. // */
  661. // case euler_yxy: {
  662. // switch(mode) {
  663. // case euler_xzx: {
  664. // rY = cosX * cosZ - cosY * sinX * sinZ;
  665. // if(rY > 0.9999) {
  666. // rX = atan2(cosX * sinY, cosY); // -12, 22
  667. // rY = 0.0;
  668. // rZ = 0.0;
  669. // } else if(rY < -0.9999) {
  670. // rX = atan2(cosX * sinY, cosY);
  671. // rY = 180.0;
  672. // rZ = 0.0;
  673. // } else {
  674. // rX = -atan2(cosZ * sinX + cosX * cosY * sinZ, sinY * sinZ);
  675. // rY = acos(rY);
  676. // rZ = atan2(cosX * sinZ + cosY * cosZ * sinX, -sinX * sinY);
  677. // }
  678. // }
  679. // case euler_xyx: {
  680. // rY = cosX * cosZ - cosY * sinX * sinZ;
  681. // if(rY > 0.9999) {
  682. // rX = atan2(cosX * sinY, cosY); // -12, 22
  683. // rY = 0.0;
  684. // rZ = 0.0;
  685. // } else if(rY < -0.9999) {
  686. // rX = atan2(cosX * sinY, cosY);
  687. // rY = 180.0;
  688. // rZ = 0.0;
  689. // } else {
  690. // rX = atan2(sinY * sinZ, cosZ * sinX + cosX * cosY * sinZ);
  691. // rY = acos(rY);
  692. // rZ = atan2(sinX * sinY, cosX * sinZ + cosY * cosZ * sinX);
  693. // }
  694. // }
  695. // case euler_yxy: {
  696. // rX = oX;
  697. // rY = oY;
  698. // rZ = oZ;
  699. // }
  700. // case euler_yzy: {
  701. // rX = oX + 90.0;
  702. // rY = oY;
  703. // rZ = oZ - 90.0;
  704. // }
  705. // case euler_zyz: {
  706. // rY = cosX * cosY * cosZ - sinX * sinZ;
  707. // if(rY > 0.9999) {
  708. // rX = -atan2(sinX * sinY, cosY); // -01, 11
  709. // rY = 0.0;
  710. // rZ = 0.0;
  711. // } else if(rY < -0.9999) {
  712. // rX = -atan2(sinX * sinY, cosY);
  713. // rY = 180.0;
  714. // rZ = 0.0;
  715. // } else {
  716. // rX = -atan2(cosZ * sinY, cosX * sinZ + cosY * cosZ * sinX);
  717. // rY = acos(rY);
  718. // rZ = atan2(cosX * sinY, cosZ * sinX + cosX * cosY * sinZ);
  719. // }
  720. // }
  721. // case euler_zxz: {
  722. // rY = cosX * cosY * cosZ - sinX * sinZ;
  723. // if(rY > 0.9999) {
  724. // rX = -atan2(sinX * sinY, cosY); // -01, 11
  725. // rY = 0.0;
  726. // rZ = 0.0;
  727. // } else if(rY < -0.9999) {
  728. // rX = -atan2(sinX * sinY, cosY);
  729. // rY = 180.0;
  730. // rZ = 0.0;
  731. // } else {
  732. // rX = atan2(cosX * sinZ + cosY * cosZ * sinX, cosZ * sinY);
  733. // rY = acos(rY);
  734. // rZ = -atan2(cosZ * sinX + cosX * cosY * sinZ, cosX * sinY);
  735. // }
  736. // }
  737. // case euler_xzy: {
  738. // rZ = sinX * sinY;
  739. // if(rZ < -0.9999) {
  740. // rX = 90.0 - oZ; // -12, 22
  741. // rY = 0.0;
  742. // rZ = 90.0;
  743. // } else if(rZ > 0.9999) {
  744. // rX = 90.0 + oZ;
  745. // rY = 0.0;
  746. // rZ = -90.0;
  747. // } else {
  748. // rX = atan2(cosX * sinY, cosY);
  749. // rY = atan2(cosX * sinZ + cosY * cosZ * sinX, cosX * cosZ - cosY * sinX * sinZ);
  750. // rZ = -asin(rZ);
  751. // }
  752. // }
  753. // case euler_xyz: {
  754. // rY = cosX * sinZ + cosY * cosZ * sinX;
  755. // if(rY > 0.9999) {
  756. // rX = atan2(cosX * sinY, cosY); // 10, -20
  757. // rY = 90.0;
  758. // rZ = 0.0;
  759. // } else if(rY < -0.9999) {
  760. // rX = atan2(cosX * sinY, cosY);
  761. // rY = -90.0;
  762. // rZ = 0.0;
  763. // } else {
  764. // rX = atan2(cosZ * sinY, cosX * cosY * cosZ - sinX * sinZ);
  765. // rY = asin(rY);
  766. // rZ = -atan2(sinX * sinY, cosX * cosZ - cosY * sinX * sinZ);
  767. // }
  768. // }
  769. // case euler_yxz: {
  770. // rX = cosZ * sinY;
  771. // if(rX > 0.9999) {
  772. // rX = 90.0;
  773. // rY = oX; // -20, 00
  774. // rZ = 0.0;
  775. // } else if(rX < -0.9999) {
  776. // rX = -90.0;
  777. // rY = oX;
  778. // rZ = 0.0;
  779. // } else {
  780. // rX = asin(rX);
  781. // rY = atan2(cosX * sinZ + cosY * cosZ * sinX, cosX * cosY * cosZ - sinX * sinZ);
  782. // rZ = atan2(sinY * sinZ, cosY);
  783. // }
  784. // }
  785. // case euler_yzx: {
  786. // rZ = sinY * sinZ;
  787. // if(rZ > 0.9999) {
  788. // rX = 0.0;
  789. // rY = 90.0 + oX; // 21, -01
  790. // rZ = 90.0;
  791. // } else if(rZ < -0.9999) {
  792. // rX = 0.0;
  793. // rY = 90.0 + oX;
  794. // rZ = -90.0;
  795. // } else {
  796. // rX = atan2(cosZ * sinY, cosY);
  797. // rY = atan2(cosZ * sinX + cosX * cosY * sinZ, cosX * cosZ - cosY * sinX * sinZ);
  798. // rZ = asin(rZ);
  799. // }
  800. // }
  801. // case euler_zyx: { // pitch roll yaw
  802. // rY = cosZ * sinX + cosX * cosY * sinZ;
  803. // if(rY > 0.9999) {
  804. // rX = 0.0;
  805. // rY = 90.0;
  806. // rZ = -atan2(sinX * sinY, cosY); // -01, 11
  807. // } else if(rY < -0.9999) {
  808. // rX = 0.0;
  809. // rY = -90.0;
  810. // rZ = -atan2(sinX * sinY, cosY);
  811. // } else {
  812. // rX = atan2(cosX * sinY, cosX * cosY * cosZ - sinX * sinZ);
  813. // rY = asin(rY);
  814. // rZ = atan2(sinY * sinZ, cosX * cosZ - cosY * sinX * sinZ);
  815. // }
  816. // }
  817. // case euler_zxy: { // sa-mp
  818. // rX = cosX * sinY;
  819. // if(rX > 0.9999) {
  820. // rX = 90.0;
  821. // rY = 0.0;
  822. // rZ = oZ; // 02, -12
  823. // } else if(rX < -0.9999) {
  824. // rX = -90.0;
  825. // rY = 0.0;
  826. // rZ = 180.0 - oZ;
  827. // } else {
  828. // rX = asin(rX);
  829. // rY = atan2(cosZ * sinX + cosX * cosY * sinZ, cosX * cosY * cosZ - sinX * sinZ);
  830. // rZ = -atan2(sinX * sinY, cosY);
  831. // }
  832. // }
  833. // }
  834. // }
  835. // /*
  836. // matrix[0][0] = cosX * cosY * cosZ - sinX * sinZ;
  837. // matrix[0][1] = -cosX * sinY;
  838. // matrix[0][2] = cosZ * sinX + cosX * cosY * sinZ;
  839. // matrix[1][0] = cosZ * sinY;
  840. // matrix[1][1] = cosY;
  841. // matrix[1][2] = sinY * sinZ;
  842. // matrix[2][0] = -cosX * sinZ - cosY * cosZ * sinX;
  843. // matrix[2][1] = sinX * sinY;
  844. // matrix[2][2] = cosX * cosZ - cosY * sinX * sinZ;
  845. // rZ = 0 rY = 0 / 180
  846. // matrix[0][0] = cosX * cosY;
  847. // matrix[0][2] = sinX;
  848. // matrix[2][0] = - cosY * sinX;
  849. // matrix[2][2] = cosX;
  850. // */
  851. // case euler_yzy: {
  852. // switch(mode) {
  853. // case euler_xzx: {}
  854. // case euler_xyx: {}
  855. // case euler_yxy: {}
  856. // case euler_yzy: {
  857. // rX = oX;
  858. // rY = oZ;
  859. // rZ = oZ;
  860. // }
  861. // case euler_zyz: {}
  862. // case euler_zxz: {}
  863. // case euler_xzy: {}
  864. // case euler_xyz: {}
  865. // case euler_yxz: {}
  866. // case euler_yzx: {}
  867. // case euler_zyx: {}
  868. // case euler_zxy: {}
  869. // }
  870. // }
  871. // /*
  872. // matrix[0][0] = cosX * cosY * cosZ - sinX * sinZ;
  873. // matrix[0][1] = -cosZ * sinX - cosX * cosY * sinZ;
  874. // matrix[0][2] = cosX * sinY;
  875. // matrix[1][0] = cosX * sinZ + cosY * cosZ * sinX;
  876. // matrix[1][1] = cosX * cosZ - cosY * sinX * sinZ;
  877. // matrix[1][2] = sinX * sinY;
  878. // matrix[2][0] = -cosZ * sinY;
  879. // matrix[2][1] = sinY * sinZ;
  880. // matrix[2][2] = cosY;
  881. // rZ = 0 rY = 0 / 180
  882. // matrix[0][0] = cosX * cosY;
  883. // matrix[0][1] = -sinX;
  884. // matrix[1][0] = cosY * sinX;
  885. // matrix[1][1] = cosX;
  886. // */
  887. // case euler_zyz: {
  888. // switch(mode) {
  889. // case euler_xzx: {}
  890. // case euler_xyx: {}
  891. // case euler_yxy: {}
  892. // case euler_yzy: {}
  893. // case euler_zyz: {
  894. // rX = oX;
  895. // rY = oZ;
  896. // rZ = oZ;
  897. // }
  898. // case euler_zxz: {}
  899. // case euler_xzy: {}
  900. // case euler_xyz: {}
  901. // case euler_yxz: {}
  902. // case euler_yzx: {}
  903. // case euler_zyx: {}
  904. // case euler_zxy: {}
  905. // }
  906. // }
  907. // /*
  908. // matrix[0][0] = cosX * cosZ - cosY * sinX * sinZ;
  909. // matrix[0][1] = -cosX * sinZ - cosY * cosZ * sinX;
  910. // matrix[0][2] = sinX * sinY;
  911. // matrix[1][0] = cosZ * sinX + cosX * cosY * sinZ;
  912. // matrix[1][1] = cosX * cosY * cosZ - sinX * sinZ;
  913. // matrix[1][2] = -cosX * sinY;
  914. // matrix[2][0] = sinY * sinZ;
  915. // matrix[2][1] = cosZ * sinY;
  916. // matrix[2][2] = cosY;
  917. // rZ = 0.0 rY = 0 / 180
  918. // matrix[0][0] = cosX;
  919. // matrix[0][1] = -cosY * sinX;
  920. // matrix[1][0] = sinX;
  921. // matrix[1][1] = cosX * cosY;
  922. // */
  923. // case euler_zxz: {
  924. // switch(mode) {
  925. // case euler_xzx: {}
  926. // case euler_xyx: {}
  927. // case euler_yxy: {}
  928. // case euler_yzy: {}
  929. // case euler_zyz: {}
  930. // case euler_zxz: {
  931. // rX = oX;
  932. // rY = oZ;
  933. // rZ = oZ;
  934. // }
  935. // case euler_xzy: {}
  936. // case euler_xyz: {}
  937. // case euler_yxz: {}
  938. // case euler_yzx: {}
  939. // case euler_zyx: {}
  940. // case euler_zxy: {}
  941. // }
  942. // }
  943. // /*
  944. // matrix[0][0] = cosZ * cosY;
  945. // matrix[0][1] = -sinZ;
  946. // matrix[0][2] = cosZ * sinY;
  947. // matrix[1][0] = sinX * sinY + cosX * cosY * sinZ;
  948. // matrix[1][1] = cosX * cosZ;
  949. // matrix[1][2] = cosX * sinZ * sinY - cosY * sinX;
  950. // matrix[2][0] = cosY * sinX * sinZ - cosX * sinY;
  951. // matrix[2][1] = cosZ * sinX;
  952. // matrix[2][2] = cosX * cosY + sinX * sinZ * sinY;
  953. // rY = 0 rZ = 90 / -90
  954. // matrix[1][0] = cosX * sinZ;
  955. // matrix[1][2] = -sinX;
  956. // matrix[2][0] = sinX * sinZ;
  957. // matrix[2][2] = cosX;
  958. // */
  959. // case euler_xzy: {
  960. // switch(mode) {
  961. // case euler_xzx: {}
  962. // case euler_xyx: {}
  963. // case euler_yxy: {}
  964. // case euler_yzy: {}
  965. // case euler_zyz: {}
  966. // case euler_zxz: {}
  967. // case euler_xzy: {
  968. // rX = oX;
  969. // rY = oZ;
  970. // rZ = oZ;
  971. // }
  972. // case euler_xyz: {}
  973. // case euler_yxz: {}
  974. // case euler_yzx: {}
  975. // case euler_zyx: {}
  976. // case euler_zxy: {}
  977. // }
  978. // }
  979. // /*
  980. // matrix[0][0] = cosY * cosZ;
  981. // matrix[0][1] = -cosY * sinZ;
  982. // matrix[0][2] = sinY;
  983. // matrix[1][0] = cosX * sinZ + cosZ * sinX * sinY;
  984. // matrix[1][1] = cosX * cosZ - sinX * sinY * sinZ;
  985. // matrix[1][2] = -cosY * sinX;
  986. // matrix[2][0] = sinX * sinZ - cosX * cosZ * sinY;
  987. // matrix[2][1] = cosZ * sinX + cosX * sinY * sinZ;
  988. // matrix[2][2] = cosX * cosY;
  989. // rZ = 0 rY = 90 / -90
  990. // matrix[1][0] = sinX * sinY;
  991. // matrix[1][1] = cosX;
  992. // matrix[2][0] = -cosX * sinY;
  993. // matrix[2][1] = sinX;
  994. // */
  995. // case euler_xyz: {
  996. // switch(mode) {
  997. // case euler_xzx: {}
  998. // case euler_xyx: {}
  999. // case euler_yxy: {}
  1000. // case euler_yzy: {}
  1001. // case euler_zyz: {}
  1002. // case euler_zxz: {}
  1003. // case euler_xzy: {}
  1004. // case euler_xyz: {
  1005. // rX = oX;
  1006. // rY = oZ;
  1007. // rZ = oZ;
  1008. // }
  1009. // case euler_yxz: {}
  1010. // case euler_yzx: {}
  1011. // case euler_zyx: {}
  1012. // case euler_zxy: {}
  1013. // }
  1014. // }
  1015. // /*
  1016. // matrix[0][0] = cosY * cosZ + sinY * sinX * sinZ;
  1017. // matrix[0][1] = cosZ * sinY * sinX - cosY * sinZ;
  1018. // matrix[0][2] = cosX * sinY;
  1019. // matrix[1][0] = cosX * sinZ;
  1020. // matrix[1][1] = cosX * cosZ;
  1021. // matrix[1][2] = -sinX;
  1022. // matrix[2][0] = cosY * sinX * sinZ - cosZ * sinY;
  1023. // matrix[2][1] = cosY * cosZ * sinX + sinY * sinZ;
  1024. // matrix[2][2] = cosY * cosX;
  1025. // rZ = 0 rX = 90 / -90
  1026. // matrix[0][0] = cosY;
  1027. // matrix[0][1] = sinY * sinX;
  1028. // matrix[2][0] = -sinY;
  1029. // matrix[2][1] = cosY * sinX;
  1030. // */
  1031. // case euler_yxz: {
  1032. // switch(mode) {
  1033. // case euler_xzx: {}
  1034. // case euler_xyx: {}
  1035. // case euler_yxy: {}
  1036. // case euler_yzy: {}
  1037. // case euler_zyz: {}
  1038. // case euler_zxz: {}
  1039. // case euler_xzy: {}
  1040. // case euler_xyz: {}
  1041. // case euler_yxz: {
  1042. // rX = oX;
  1043. // rY = oZ;
  1044. // rZ = oZ;
  1045. // }
  1046. // case euler_yzx: {}
  1047. // case euler_zyx: {}
  1048. // case euler_zxy: {}
  1049. // }
  1050. // }
  1051. // /*
  1052. // matrix[0][0] = cosY * cosZ;
  1053. // matrix[0][1] = sinY * sinX - cosY * cosX * sinZ;
  1054. // matrix[0][2] = cosX * sinY + cosY * sinZ * sinX;
  1055. // matrix[1][0] = sinZ;
  1056. // matrix[1][1] = cosZ * cosX;
  1057. // matrix[1][2] = -cosZ * sinX;
  1058. // matrix[2][0] = -cosZ * sinY;
  1059. // matrix[2][1] = cosY * sinX + cosX * sinY * sinZ;
  1060. // matrix[2][2] = cosY * cosX - sinY * sinZ * sinX;
  1061. // rX = 0 rZ = 90 / -90
  1062. // matrix[0][1] = -cosY * sinZ;
  1063. // matrix[0][2] = sinY;
  1064. // matrix[2][1] = sinY * sinZ;
  1065. // matrix[2][2] = cosY;
  1066. // */
  1067. // case euler_yzx: {
  1068. // switch(mode) {
  1069. // case euler_xzx: {}
  1070. // case euler_xyx: {}
  1071. // case euler_yxy: {}
  1072. // case euler_yzy: {}
  1073. // case euler_zyz: {}
  1074. // case euler_zxz: {}
  1075. // case euler_xzy: {}
  1076. // case euler_xyz: {}
  1077. // case euler_yxz: {}
  1078. // case euler_yzx: {
  1079. // rX = oX;
  1080. // rY = oZ;
  1081. // rZ = oZ;
  1082. // }
  1083. // case euler_zyx: {}
  1084. // case euler_zxy: {}
  1085. // }
  1086. // }
  1087. // /*
  1088. // matrix[0][0] = cosZ * cosY;
  1089. // matrix[0][1] = cosZ * sinY * sinX - cosX * sinZ;
  1090. // matrix[0][2] = sinZ * sinX + cosZ * cosX * sinY;
  1091. // matrix[1][0] = cosY * sinZ;
  1092. // matrix[1][1] = cosZ * cosX + sinZ * sinY * sinX;
  1093. // matrix[1][2] = cosX * sinZ * sinY - cosZ * sinX;
  1094. // matrix[2][0] = -sinY;
  1095. // matrix[2][1] = cosY * sinX;
  1096. // matrix[2][2] = cosY * cosX;
  1097. // rX = 0 rY = 90 / -90
  1098. // matrix[0][1] = -sinZ;
  1099. // matrix[0][2] = cosZ * sinY;
  1100. // matrix[1][1] = cosZ;
  1101. // matrix[1][2] = sinZ * sinY;
  1102. // */
  1103. // case euler_zyx: { // pitch roll yaw
  1104. // switch(mode) {
  1105. // case euler_xzx: {}
  1106. // case euler_xyx: {}
  1107. // case euler_yxy: {}
  1108. // case euler_yzy: {}
  1109. // case euler_zyz: {}
  1110. // case euler_zxz: {}
  1111. // case euler_xzy: {}
  1112. // case euler_xyz: {}
  1113. // case euler_yxz: {}
  1114. // case euler_yzx: {}
  1115. // case euler_zyx: { // pitch roll yaw
  1116. // rX = oX;
  1117. // rY = oZ;
  1118. // rZ = oZ;
  1119. // }
  1120. // case euler_zxy: { // sa-mp
  1121. // rX = cosY * sinX;
  1122. // if(rX > 0.9999) {
  1123. // rX = 90.0;
  1124. // rY = 0.0;
  1125. // rZ = oZ;
  1126. // } else if(rX < -0.9999) {
  1127. // rX = -90.0;
  1128. // rY = 0.0;
  1129. // rZ = oZ;
  1130. // } else {
  1131. // rX = asin(rX);
  1132. // rY = atan2(sinY, cosY * cosX);
  1133. // rZ = atan2(cosX * sinZ - cosZ * sinY * sinX, cosZ * cosX + sinZ * sinY * sinX);
  1134. // }
  1135. // }
  1136. // }
  1137. // }
  1138. // /*
  1139. // matrix[0][0] = cosZ * cosY - sinZ * sinX * sinY;
  1140. // matrix[0][1] = -sinZ * cosX;
  1141. // matrix[0][2] = cosZ * sinY + sinZ * sinX * cosY;
  1142. // matrix[1][0] = sinZ * cosY + cosZ * sinX * sinY;
  1143. // matrix[1][1] = cosZ * cosX;
  1144. // matrix[1][2] = sinZ * sinY - cosZ * sinX * cosY;
  1145. // matrix[2][0] = -cosX * sinY;
  1146. // matrix[2][1] = sinX;
  1147. // matrix[2][2] = cosX * cosY;
  1148. // rY = 0 rX = 90 / -90
  1149. // matrix[0][0] = cosZ;
  1150. // matrix[0][2] = sinZ * sinX;
  1151. // matrix[1][0] = sinZ ;
  1152. // matrix[1][2] = -cosZ * sinX;
  1153. // */
  1154. // case euler_zxy: { // sa-mp
  1155. // switch(mode) {
  1156. // case euler_xzx: {}
  1157. // case euler_xyx: {}
  1158. // case euler_yxy: {}
  1159. // case euler_yzy: {}
  1160. // case euler_zyz: {}
  1161. // case euler_zxz: {}
  1162. // case euler_xzy: {}
  1163. // case euler_xyz: {}
  1164. // case euler_yxz: {}
  1165. // case euler_yzx: {}
  1166. // case euler_zyx: { // pitch roll yaw
  1167. // rY = cosX * sinY;
  1168. // if(rY < -0.9999) {
  1169. // rX = 0.0;
  1170. // rY = 90.0;
  1171. // rZ = oZ;
  1172. // } else if(rY > 0.9999) {
  1173. // rX = 0.0;
  1174. // rY = -90.0;
  1175. // rZ = oZ;
  1176. // } else {
  1177. // rX = atan2(sinX, cosX * cosY);
  1178. // rY = asin(rY);
  1179. // rZ = atan2(sinZ * cosY + cosZ * sinX * sinY, cosZ * cosY - sinZ * sinX * sinY);
  1180. // }
  1181. // }
  1182. // case euler_zxy: { // sa-mp
  1183. // rX = oX;
  1184. // rY = oZ;
  1185. // rZ = oZ;
  1186. // }
  1187. // }
  1188. // }
  1189. // }
  1190. // }