TranslationRotationScale.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import Cartesian3 from "./Cartesian3.js";
  2. import defaultValue from "./defaultValue.js";
  3. import defined from "./defined.js";
  4. import Quaternion from "./Quaternion.js";
  5. const defaultScale = new Cartesian3(1.0, 1.0, 1.0);
  6. const defaultTranslation = Cartesian3.ZERO;
  7. const defaultRotation = Quaternion.IDENTITY;
  8. /**
  9. * An affine transformation defined by a translation, rotation, and scale.
  10. * @alias TranslationRotationScale
  11. * @constructor
  12. *
  13. * @param {Cartesian3} [translation=Cartesian3.ZERO] A {@link Cartesian3} specifying the (x, y, z) translation to apply to the node.
  14. * @param {Quaternion} [rotation=Quaternion.IDENTITY] A {@link Quaternion} specifying the (x, y, z, w) rotation to apply to the node.
  15. * @param {Cartesian3} [scale=new Cartesian3(1.0, 1.0, 1.0)] A {@link Cartesian3} specifying the (x, y, z) scaling to apply to the node.
  16. */
  17. function TranslationRotationScale(translation, rotation, scale) {
  18. /**
  19. * Gets or sets the (x, y, z) translation to apply to the node.
  20. * @type {Cartesian3}
  21. * @default Cartesian3.ZERO
  22. */
  23. this.translation = Cartesian3.clone(
  24. defaultValue(translation, defaultTranslation)
  25. );
  26. /**
  27. * Gets or sets the (x, y, z, w) rotation to apply to the node.
  28. * @type {Quaternion}
  29. * @default Quaternion.IDENTITY
  30. */
  31. this.rotation = Quaternion.clone(defaultValue(rotation, defaultRotation));
  32. /**
  33. * Gets or sets the (x, y, z) scaling to apply to the node.
  34. * @type {Cartesian3}
  35. * @default new Cartesian3(1.0, 1.0, 1.0)
  36. */
  37. this.scale = Cartesian3.clone(defaultValue(scale, defaultScale));
  38. }
  39. /**
  40. * Compares this instance against the provided instance and returns
  41. * <code>true</code> if they are equal, <code>false</code> otherwise.
  42. *
  43. * @param {TranslationRotationScale} [right] The right hand side TranslationRotationScale.
  44. * @returns {boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
  45. */
  46. TranslationRotationScale.prototype.equals = function (right) {
  47. return (
  48. this === right ||
  49. (defined(right) &&
  50. Cartesian3.equals(this.translation, right.translation) &&
  51. Quaternion.equals(this.rotation, right.rotation) &&
  52. Cartesian3.equals(this.scale, right.scale))
  53. );
  54. };
  55. export default TranslationRotationScale;