home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / Beez.swf / scripts / Box2D / Collision / Shapes / b2PolygonDef.as < prev    next >
Encoding:
Text File  |  2008-09-03  |  1.7 KB  |  63 lines

  1. package Box2D.Collision.Shapes
  2. {
  3.    import Box2D.Common.*;
  4.    import Box2D.Common.Math.*;
  5.    
  6.    public class b2PolygonDef extends b2ShapeDef
  7.    {
  8.       
  9.       private static var s_mat:b2Mat22 = new b2Mat22();
  10.        
  11.       
  12.       public var vertices:Array;
  13.       
  14.       public var vertexCount:int;
  15.       
  16.       public function b2PolygonDef()
  17.       {
  18.          vertices = new Array(b2Settings.b2_maxPolygonVertices);
  19.          super();
  20.          type = b2Shape.e_polygonShape;
  21.          vertexCount = 0;
  22.          for(var i:int = 0; i < b2Settings.b2_maxPolygonVertices; i++)
  23.          {
  24.             vertices[i] = new b2Vec2();
  25.          }
  26.       }
  27.       
  28.       public function SetAsOrientedBox(hx:Number, hy:Number, center:b2Vec2 = null, angle:Number = 0) : void
  29.       {
  30.          var xfPosition:b2Vec2 = null;
  31.          var xfR:b2Mat22 = null;
  32.          var i:int = 0;
  33.          vertexCount = 4;
  34.          vertices[0].Set(-hx,-hy);
  35.          vertices[1].Set(hx,-hy);
  36.          vertices[2].Set(hx,hy);
  37.          vertices[3].Set(-hx,hy);
  38.          if(center)
  39.          {
  40.             xfPosition = center;
  41.             xfR = s_mat;
  42.             xfR.Set(angle);
  43.             for(i = 0; i < vertexCount; i++)
  44.             {
  45.                center = vertices[i];
  46.                hx = xfPosition.x + (xfR.col1.x * center.x + xfR.col2.x * center.y);
  47.                center.y = xfPosition.y + (xfR.col1.y * center.x + xfR.col2.y * center.y);
  48.                center.x = hx;
  49.             }
  50.          }
  51.       }
  52.       
  53.       public function SetAsBox(hx:Number, hy:Number) : void
  54.       {
  55.          vertexCount = 4;
  56.          vertices[0].Set(-hx,-hy);
  57.          vertices[1].Set(hx,-hy);
  58.          vertices[2].Set(hx,hy);
  59.          vertices[3].Set(-hx,hy);
  60.       }
  61.    }
  62. }
  63.