Matrix2.js 579 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. export class Matrix2 {
  2. constructor( n11, n12, n21, n22 ) {
  3. Matrix2.prototype.isMatrix2 = true;
  4. this.elements = [
  5. 1, 0,
  6. 0, 1,
  7. ];
  8. if ( n11 !== undefined ) {
  9. this.set( n11, n12, n21, n22 );
  10. }
  11. }
  12. identity() {
  13. this.set(
  14. 1, 0,
  15. 0, 1,
  16. );
  17. return this;
  18. }
  19. fromArray( array, offset = 0 ) {
  20. for ( let i = 0; i < 4; i ++ ) {
  21. this.elements[ i ] = array[ i + offset ];
  22. }
  23. return this;
  24. }
  25. set( n11, n12, n21, n22 ) {
  26. const te = this.elements;
  27. te[ 0 ] = n11; te[ 2 ] = n12;
  28. te[ 1 ] = n21; te[ 3 ] = n22;
  29. return this;
  30. }
  31. }