Matrix3.js 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. var Matrix3 = Class.extend
  2. ({
  3. n11: null, n12: null, n13: null,
  4. n21: null, n22: null, n23: null,
  5. n31: null, n32: null, n33: null,
  6. init: function()
  7. {
  8. this.identity();
  9. },
  10. identity: function()
  11. {
  12. this.n11 = 1; this.n12 = 0; this.n13 = 0;
  13. this.n21 = 0; this.n22 = 1; this.n23 = 0;
  14. this.n31 = 0; this.n32 = 0; this.n33 = 1;
  15. },
  16. assign: function(m)
  17. {
  18. this.n11 = m.n11; this.n12 = m.n12; this.n13 = m.n13;
  19. this.n21 = m.n21; this.n22 = m.n22; this.n23 = m.n23;
  20. this.n31 = m.n31; this.n32 = m.n32; this.n33 = m.n33;
  21. },
  22. multiplySelf: function(m)
  23. {
  24. var n11 = this.n11, n12 = this.n12, n13 = this.n13, n14 = this.n14;
  25. var n21 = this.n21, n22 = this.n22, n23 = this.n23, n24 = this.n24;
  26. var n31 = this.n31, n32 = this.n32, n33 = this.n33, n34 = this.n34;
  27. this.n11 = n11 * m.n11 + n12 * m.n21 + n13 * m.n31;
  28. this.n12 = n11 * m.n12 + n12 * m.n22 + n13 * m.n32;
  29. this.n13 = n11 * m.n13 + n12 * m.n23 + n13 * m.n33;
  30. this.n21 = n21 * m.n11 + n22 * m.n21 + n23 * m.n31;
  31. this.n22 = n21 * m.n12 + n22 * m.n22 + n23 * m.n32;
  32. this.n23 = n21 * m.n13 + n22 * m.n23 + n23 * m.n33;
  33. this.n31 = n31 * m.n11 + n32 * m.n21 + n33 * m.n31;
  34. this.n32 = n31 * m.n12 + n32 * m.n22 + n33 * m.n32;
  35. this.n33 = n31 * m.n13 + n32 * m.n23 + n33 * m.n33;
  36. },
  37. inverse: function()
  38. {
  39. var n11 = this.n11, n12 = this.n12, n13 = this.n13, n14 = this.n14;
  40. var n21 = this.n21, n22 = this.n22, n23 = this.n23, n24 = this.n24;
  41. var n31 = this.n31, n32 = this.n32, n33 = this.n33, n34 = this.n34;
  42. this.n11 = n11; this.n12 = n21; this.n13 = n31;
  43. this.n21 = n12; this.n22 = n22; this.n23 = n32;
  44. this.n31 = n13; this.n32 = n23; this.n33 = n33;
  45. },
  46. clone: function()
  47. {
  48. var m = new Matrix3();
  49. m.n11 = this.n11; m.n12 = this.n12; m.n13 = this.n13;
  50. m.n21 = this.n21; m.n22 = this.n22; m.n23 = this.n23;
  51. m.n31 = this.n31; m.n32 = this.n32; m.n33 = this.n33;
  52. return m;
  53. },
  54. toString: function()
  55. {
  56. return "| " + this.n11 + " " + this.n12 + " " + this.n13 + " |\n" +
  57. "| " + this.n21 + " " + this.n22 + " " + this.n23 + " |\n" +
  58. "| " + this.n31 + " " + this.n32 + " " + this.n33 + " |";
  59. }
  60. });