Source: core/display/TransformBase.js

core/display/TransformBase.js

  1. import { Matrix } from '../math';
  2. /**
  3. * Generic class to deal with traditional 2D matrix transforms
  4. *
  5. * @class
  6. * @memberof PIXI
  7. */
  8. export default class TransformBase
  9. {
  10. /**
  11. *
  12. */
  13. constructor()
  14. {
  15. /**
  16. * The global matrix transform. It can be swapped temporarily by some functions like getLocalBounds()
  17. *
  18. * @member {PIXI.Matrix}
  19. */
  20. this.worldTransform = new Matrix();
  21. /**
  22. * The local matrix transform
  23. *
  24. * @member {PIXI.Matrix}
  25. */
  26. this.localTransform = new Matrix();
  27. this._worldID = 0;
  28. this._parentID = 0;
  29. }
  30. /**
  31. * TransformBase does not have decomposition, so this function wont do anything
  32. */
  33. updateLocalTransform()
  34. {
  35. // empty
  36. }
  37. /**
  38. * Updates the values of the object and applies the parent's transform.
  39. *
  40. * @param {PIXI.TransformBase} parentTransform - The transform of the parent of this object
  41. */
  42. updateTransform(parentTransform)
  43. {
  44. const pt = parentTransform.worldTransform;
  45. const wt = this.worldTransform;
  46. const lt = this.localTransform;
  47. // concat the parent matrix with the objects transform.
  48. wt.a = (lt.a * pt.a) + (lt.b * pt.c);
  49. wt.b = (lt.a * pt.b) + (lt.b * pt.d);
  50. wt.c = (lt.c * pt.a) + (lt.d * pt.c);
  51. wt.d = (lt.c * pt.b) + (lt.d * pt.d);
  52. wt.tx = (lt.tx * pt.a) + (lt.ty * pt.c) + pt.tx;
  53. wt.ty = (lt.tx * pt.b) + (lt.ty * pt.d) + pt.ty;
  54. this._worldID ++;
  55. }
  56. }
  57. /**
  58. * Updates the values of the object and applies the parent's transform.
  59. * @param parentTransform {PIXI.Transform} The transform of the parent of this object
  60. *
  61. */
  62. TransformBase.prototype.updateWorldTransform = TransformBase.prototype.updateTransform;
  63. TransformBase.IDENTITY = new TransformBase();