home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / Beez.swf / scripts / Box2D / Common / Math / b2Mat22.as next >
Encoding:
Text File  |  2008-09-03  |  2.9 KB  |  129 lines

  1. package Box2D.Common.Math
  2. {
  3.    public class b2Mat22
  4.    {
  5.        
  6.       
  7.       public var col1:b2Vec2;
  8.       
  9.       public var col2:b2Vec2;
  10.       
  11.       public function b2Mat22(angle:Number = 0, c1:b2Vec2 = null, c2:b2Vec2 = null)
  12.       {
  13.          var c:Number = NaN;
  14.          var s:Number = NaN;
  15.          col1 = new b2Vec2();
  16.          col2 = new b2Vec2();
  17.          super();
  18.          if(c1 != null && c2 != null)
  19.          {
  20.             col1.SetV(c1);
  21.             col2.SetV(c2);
  22.          }
  23.          else
  24.          {
  25.             c = Math.cos(angle);
  26.             s = Math.sin(angle);
  27.             col1.x = c;
  28.             col2.x = -s;
  29.             col1.y = s;
  30.             col2.y = c;
  31.          }
  32.       }
  33.       
  34.       public function SetIdentity() : void
  35.       {
  36.          col1.x = 1;
  37.          col2.x = 0;
  38.          col1.y = 0;
  39.          col2.y = 1;
  40.       }
  41.       
  42.       public function SetVV(c1:b2Vec2, c2:b2Vec2) : void
  43.       {
  44.          col1.SetV(c1);
  45.          col2.SetV(c2);
  46.       }
  47.       
  48.       public function Set(angle:Number) : void
  49.       {
  50.          var c:Number = NaN;
  51.          c = Math.cos(angle);
  52.          var s:Number = Math.sin(angle);
  53.          col1.x = c;
  54.          col2.x = -s;
  55.          col1.y = s;
  56.          col2.y = c;
  57.       }
  58.       
  59.       public function SetZero() : void
  60.       {
  61.          col1.x = 0;
  62.          col2.x = 0;
  63.          col1.y = 0;
  64.          col2.y = 0;
  65.       }
  66.       
  67.       public function SetM(m:b2Mat22) : void
  68.       {
  69.          col1.SetV(m.col1);
  70.          col2.SetV(m.col2);
  71.       }
  72.       
  73.       public function AddM(m:b2Mat22) : void
  74.       {
  75.          col1.x += m.col1.x;
  76.          col1.y += m.col1.y;
  77.          col2.x += m.col2.x;
  78.          col2.y += m.col2.y;
  79.       }
  80.       
  81.       public function Abs() : void
  82.       {
  83.          col1.Abs();
  84.          col2.Abs();
  85.       }
  86.       
  87.       public function Copy() : b2Mat22
  88.       {
  89.          return new b2Mat22(0,col1,col2);
  90.       }
  91.       
  92.       public function Invert(out:b2Mat22) : b2Mat22
  93.       {
  94.          var a:Number = NaN;
  95.          var c:Number = NaN;
  96.          var det:Number = NaN;
  97.          a = col1.x;
  98.          var b:Number = col2.x;
  99.          c = col1.y;
  100.          var d:Number = col2.y;
  101.          det = a * d - b * c;
  102.          det = 1 / det;
  103.          out.col1.x = det * d;
  104.          out.col2.x = -det * b;
  105.          out.col1.y = -det * c;
  106.          out.col2.y = det * a;
  107.          return out;
  108.       }
  109.       
  110.       public function GetAngle() : Number
  111.       {
  112.          return Math.atan2(col1.y,col1.x);
  113.       }
  114.       
  115.       public function Solve(out:b2Vec2, bX:Number, bY:Number) : b2Vec2
  116.       {
  117.          var a11:Number = col1.x;
  118.          var a12:Number = col2.x;
  119.          var a21:Number = col1.y;
  120.          var a22:Number = col2.y;
  121.          var det:Number = a11 * a22 - a12 * a21;
  122.          det = 1 / det;
  123.          out.x = det * (a22 * bX - a12 * bY);
  124.          out.y = det * (a11 * bY - a21 * bX);
  125.          return out;
  126.       }
  127.    }
  128. }
  129.