TranslationRotationScale.js 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. var defaultScale = new Cartesian3(1.0, 1.0, 1.0);
  6. var defaultTranslation = Cartesian3.ZERO;
  7. var 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. var TranslationRotationScale = function(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(defaultValue(translation, defaultTranslation));
  24. /**
  25. * Gets or sets the (x, y, z, w) rotation to apply to the node.
  26. * @type {Quaternion}
  27. * @default Quaternion.IDENTITY
  28. */
  29. this.rotation = Quaternion.clone(defaultValue(rotation, defaultRotation));
  30. /**
  31. * Gets or sets the (x, y, z) scaling to apply to the node.
  32. * @type {Cartesian3}
  33. * @default new Cartesian3(1.0, 1.0, 1.0)
  34. */
  35. this.scale = Cartesian3.clone(defaultValue(scale, defaultScale));
  36. };
  37. /**
  38. * Compares this instance against the provided instance and returns
  39. * <code>true</code> if they are equal, <code>false</code> otherwise.
  40. *
  41. * @param {TranslationRotationScale} [right] The right hand side TranslationRotationScale.
  42. * @returns {Boolean} <code>true</code> if they are equal, <code>false</code> otherwise.
  43. */
  44. TranslationRotationScale.prototype.equals = function(right) {
  45. return (this === right) ||
  46. (defined(right) &&
  47. Cartesian3.equals(this.translation, right.translation) &&
  48. Quaternion.equals(this.rotation, right.rotation) &&
  49. Cartesian3.equals(this.scale, right.scale));
  50. };
  51. export default TranslationRotationScale;