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

  1. package Box2D.Collision.Shapes
  2. {
  3.    import Box2D.Collision.b2AABB;
  4.    import Box2D.Collision.b2BroadPhase;
  5.    import Box2D.Collision.b2Pair;
  6.    import Box2D.Collision.b2Segment;
  7.    import Box2D.Common.Math.b2Vec2;
  8.    import Box2D.Common.Math.b2XForm;
  9.    import Box2D.Dynamics.b2Body;
  10.    
  11.    public class b2Shape
  12.    {
  13.       
  14.       public static const e_polygonShape:int = 1;
  15.       
  16.       private static var s_resetAABB:b2AABB = new b2AABB();
  17.       
  18.       private static var s_syncAABB:b2AABB = new b2AABB();
  19.       
  20.       private static var s_proxyAABB:b2AABB = new b2AABB();
  21.       
  22.       public static const e_unknownShape:int = -1;
  23.       
  24.       public static const e_circleShape:int = 0;
  25.       
  26.       public static const e_shapeTypeCount:int = 2;
  27.        
  28.       
  29.       public var m_next:b2Shape;
  30.       
  31.       public var m_type:int;
  32.       
  33.       public var m_sweepRadius:Number;
  34.       
  35.       public var m_density:Number;
  36.       
  37.       public var m_filter:b2FilterData;
  38.       
  39.       public var m_friction:Number;
  40.       
  41.       public var m_isSensor:Boolean;
  42.       
  43.       public var m_restitution:Number;
  44.       
  45.       public var m_userData:*;
  46.       
  47.       public var m_proxyId:uint;
  48.       
  49.       public var m_body:b2Body;
  50.       
  51.       public function b2Shape(def:b2ShapeDef)
  52.       {
  53.          super();
  54.          m_userData = def.userData;
  55.          m_friction = def.friction;
  56.          m_restitution = def.restitution;
  57.          m_density = def.density;
  58.          m_body = null;
  59.          m_sweepRadius = 0;
  60.          m_next = null;
  61.          m_proxyId = b2Pair.b2_nullProxy;
  62.          m_filter = def.filter.Copy();
  63.          m_isSensor = def.isSensor;
  64.       }
  65.       
  66.       public static function Destroy(shape:b2Shape, allocator:*) : void
  67.       {
  68.       }
  69.       
  70.       public static function Create(def:b2ShapeDef, allocator:*) : b2Shape
  71.       {
  72.          switch(def.type)
  73.          {
  74.             case e_circleShape:
  75.                return new b2CircleShape(def);
  76.             case e_polygonShape:
  77.                return new b2PolygonShape(def);
  78.             default:
  79.                return null;
  80.          }
  81.       }
  82.       
  83.       public function SetUserData(data:*) : void
  84.       {
  85.          m_userData = data;
  86.       }
  87.       
  88.       public function GetSweepRadius() : Number
  89.       {
  90.          return m_sweepRadius;
  91.       }
  92.       
  93.       public function GetNext() : b2Shape
  94.       {
  95.          return m_next;
  96.       }
  97.       
  98.       public function ComputeSweptAABB(aabb:b2AABB, xf1:b2XForm, xf2:b2XForm) : void
  99.       {
  100.       }
  101.       
  102.       public function GetType() : int
  103.       {
  104.          return m_type;
  105.       }
  106.       
  107.       public function GetRestitution() : Number
  108.       {
  109.          return m_restitution;
  110.       }
  111.       
  112.       public function GetFriction() : Number
  113.       {
  114.          return m_friction;
  115.       }
  116.       
  117.       public function GetFilterData() : b2FilterData
  118.       {
  119.          return m_filter.Copy();
  120.       }
  121.       
  122.       public function TestSegment(xf:b2XForm, lambda:Array, normal:b2Vec2, segment:b2Segment, maxLambda:Number) : Boolean
  123.       {
  124.          return false;
  125.       }
  126.       
  127.       public function RefilterProxy(broadPhase:b2BroadPhase, transform:b2XForm) : void
  128.       {
  129.          if(m_proxyId == b2Pair.b2_nullProxy)
  130.          {
  131.             return;
  132.          }
  133.          broadPhase.DestroyProxy(m_proxyId);
  134.          var aabb:b2AABB = s_resetAABB;
  135.          ComputeAABB(aabb,transform);
  136.          var inRange:Boolean = broadPhase.InRange(aabb);
  137.          if(inRange)
  138.          {
  139.             m_proxyId = broadPhase.CreateProxy(aabb,this);
  140.          }
  141.          else
  142.          {
  143.             m_proxyId = b2Pair.b2_nullProxy;
  144.          }
  145.       }
  146.       
  147.       public function SetFilterData(filter:b2FilterData) : void
  148.       {
  149.          m_filter = filter.Copy();
  150.       }
  151.       
  152.       public function GetUserData() : *
  153.       {
  154.          return m_userData;
  155.       }
  156.       
  157.       public function Synchronize(broadPhase:b2BroadPhase, transform1:b2XForm, transform2:b2XForm) : Boolean
  158.       {
  159.          if(m_proxyId == b2Pair.b2_nullProxy)
  160.          {
  161.             return false;
  162.          }
  163.          var aabb:b2AABB = s_syncAABB;
  164.          ComputeSweptAABB(aabb,transform1,transform2);
  165.          if(broadPhase.InRange(aabb))
  166.          {
  167.             broadPhase.MoveProxy(m_proxyId,aabb);
  168.             return true;
  169.          }
  170.          return false;
  171.       }
  172.       
  173.       public function ComputeMass(massData:b2MassData) : void
  174.       {
  175.       }
  176.       
  177.       public function IsSensor() : Boolean
  178.       {
  179.          return m_isSensor;
  180.       }
  181.       
  182.       public function DestroyProxy(broadPhase:b2BroadPhase) : void
  183.       {
  184.          if(m_proxyId != b2Pair.b2_nullProxy)
  185.          {
  186.             broadPhase.DestroyProxy(m_proxyId);
  187.             m_proxyId = b2Pair.b2_nullProxy;
  188.          }
  189.       }
  190.       
  191.       public function UpdateSweepRadius(center:b2Vec2) : void
  192.       {
  193.       }
  194.       
  195.       public function ComputeAABB(aabb:b2AABB, xf:b2XForm) : void
  196.       {
  197.       }
  198.       
  199.       public function GetBody() : b2Body
  200.       {
  201.          return m_body;
  202.       }
  203.       
  204.       public function CreateProxy(broadPhase:b2BroadPhase, transform:b2XForm) : void
  205.       {
  206.          var aabb:b2AABB = s_proxyAABB;
  207.          ComputeAABB(aabb,transform);
  208.          var inRange:Boolean = broadPhase.InRange(aabb);
  209.          if(inRange)
  210.          {
  211.             m_proxyId = broadPhase.CreateProxy(aabb,this);
  212.          }
  213.          else
  214.          {
  215.             m_proxyId = b2Pair.b2_nullProxy;
  216.          }
  217.       }
  218.       
  219.       public function TestPoint(xf:b2XForm, p:b2Vec2) : Boolean
  220.       {
  221.          return false;
  222.       }
  223.    }
  224. }
  225.