Home Reference Source

cables_dev/cables/src/core/cg/cg_matrixstack.js

  1.  
  2. const MatrixStack = function ()
  3. {
  4. this._arr = [mat4.create()];
  5. this._index = 0;
  6. this.stateCounter = 0;
  7. };
  8.  
  9. MatrixStack.prototype.push = function (m)
  10. {
  11. this._index++;
  12. this.stateCounter++;
  13.  
  14. if (this._index == this._arr.length)
  15. {
  16. const copy = mat4.create();
  17. this._arr.push(copy);
  18. }
  19.  
  20. mat4.copy(this._arr[this._index], m || this._arr[this._index - 1]);
  21.  
  22. return this._arr[this._index];
  23. };
  24.  
  25. MatrixStack.prototype.pop = function ()
  26. {
  27. this.stateCounter++;
  28.  
  29. this._index--;
  30. if (this._index < 0) this._index = 0;
  31.  
  32. return this._arr[this._index];
  33. };
  34.  
  35. MatrixStack.prototype.length = function ()
  36. {
  37. return this._index;
  38. };
  39.  
  40. export { MatrixStack };