Axis.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. import Check from "../Core/Check.js";
  2. import CesiumMath from "../Core/Math.js";
  3. import Matrix3 from "../Core/Matrix3.js";
  4. import Matrix4 from "../Core/Matrix4.js";
  5. /**
  6. * An enum describing the x, y, and z axes and helper conversion functions.
  7. *
  8. * @enum {number}
  9. */
  10. const Axis = {
  11. /**
  12. * Denotes the x-axis.
  13. *
  14. * @type {number}
  15. * @constant
  16. */
  17. X: 0,
  18. /**
  19. * Denotes the y-axis.
  20. *
  21. * @type {number}
  22. * @constant
  23. */
  24. Y: 1,
  25. /**
  26. * Denotes the z-axis.
  27. *
  28. * @type {number}
  29. * @constant
  30. */
  31. Z: 2,
  32. };
  33. /**
  34. * Matrix used to convert from y-up to z-up
  35. *
  36. * @type {Matrix4}
  37. * @constant
  38. */
  39. Axis.Y_UP_TO_Z_UP = Matrix4.fromRotationTranslation(
  40. Matrix3.fromRotationX(CesiumMath.PI_OVER_TWO)
  41. );
  42. /**
  43. * Matrix used to convert from z-up to y-up
  44. *
  45. * @type {Matrix4}
  46. * @constant
  47. */
  48. Axis.Z_UP_TO_Y_UP = Matrix4.fromRotationTranslation(
  49. Matrix3.fromRotationX(-CesiumMath.PI_OVER_TWO)
  50. );
  51. /**
  52. * Matrix used to convert from x-up to z-up
  53. *
  54. * @type {Matrix4}
  55. * @constant
  56. */
  57. Axis.X_UP_TO_Z_UP = Matrix4.fromRotationTranslation(
  58. Matrix3.fromRotationY(-CesiumMath.PI_OVER_TWO)
  59. );
  60. /**
  61. * Matrix used to convert from z-up to x-up
  62. *
  63. * @type {Matrix4}
  64. * @constant
  65. */
  66. Axis.Z_UP_TO_X_UP = Matrix4.fromRotationTranslation(
  67. Matrix3.fromRotationY(CesiumMath.PI_OVER_TWO)
  68. );
  69. /**
  70. * Matrix used to convert from x-up to y-up
  71. *
  72. * @type {Matrix4}
  73. * @constant
  74. */
  75. Axis.X_UP_TO_Y_UP = Matrix4.fromRotationTranslation(
  76. Matrix3.fromRotationZ(CesiumMath.PI_OVER_TWO)
  77. );
  78. /**
  79. * Matrix used to convert from y-up to x-up
  80. *
  81. * @type {Matrix4}
  82. * @constant
  83. */
  84. Axis.Y_UP_TO_X_UP = Matrix4.fromRotationTranslation(
  85. Matrix3.fromRotationZ(-CesiumMath.PI_OVER_TWO)
  86. );
  87. /**
  88. * Gets the axis by name
  89. *
  90. * @param {string} name The name of the axis.
  91. * @returns {number} The axis enum.
  92. */
  93. Axis.fromName = function (name) {
  94. //>>includeStart('debug', pragmas.debug);
  95. Check.typeOf.string("name", name);
  96. //>>includeEnd('debug');
  97. return Axis[name];
  98. };
  99. export default Object.freeze(Axis);