home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / pup_idol.swf / scripts / Box2D / Dynamics / Contacts / b2Contact.as < prev    next >
Encoding:
Text File  |  2008-08-07  |  5.2 KB  |  179 lines

  1. package Box2D.Dynamics.Contacts
  2. {
  3.    import Box2D.Collision.*;
  4.    import Box2D.Collision.Shapes.*;
  5.    import Box2D.Common.*;
  6.    import Box2D.Common.Math.*;
  7.    import Box2D.Dynamics.*;
  8.    
  9.    public class b2Contact
  10.    {
  11.       
  12.       public static var s_registers:Array;
  13.       
  14.       public static var s_initialized:Boolean = false;
  15.       
  16.       public static var e_islandFlag:uint = 1;
  17.       
  18.       public static var e_destroyFlag:uint = 2;
  19.        
  20.       
  21.       public var m_shape1:b2Shape;
  22.       
  23.       public var m_shape2:b2Shape;
  24.       
  25.       public var m_next:b2Contact;
  26.       
  27.       public var m_prev:b2Contact;
  28.       
  29.       public var m_friction:Number;
  30.       
  31.       public var m_manifoldCount:int;
  32.       
  33.       public var m_node1:b2ContactNode;
  34.       
  35.       public var m_node2:b2ContactNode;
  36.       
  37.       public var m_restitution:Number;
  38.       
  39.       public var m_flags:uint;
  40.       
  41.       public function b2Contact(param1:b2Shape = null, param2:b2Shape = null)
  42.       {
  43.          m_node1 = new b2ContactNode();
  44.          m_node2 = new b2ContactNode();
  45.          super();
  46.          m_flags = 0;
  47.          if(!param1 || !param2)
  48.          {
  49.             m_shape1 = null;
  50.             m_shape2 = null;
  51.             return;
  52.          }
  53.          m_shape1 = param1;
  54.          m_shape2 = param2;
  55.          m_manifoldCount = 0;
  56.          m_friction = Math.sqrt(m_shape1.m_friction * m_shape2.m_friction);
  57.          m_restitution = b2Math.b2Max(m_shape1.m_restitution,m_shape2.m_restitution);
  58.          m_prev = null;
  59.          m_next = null;
  60.          m_node1.contact = null;
  61.          m_node1.prev = null;
  62.          m_node1.next = null;
  63.          m_node1.other = null;
  64.          m_node2.contact = null;
  65.          m_node2.prev = null;
  66.          m_node2.next = null;
  67.          m_node2.other = null;
  68.       }
  69.       
  70.       public static function InitializeRegisters() : void
  71.       {
  72.          var _loc2_:int = 0;
  73.          s_registers = new Array(b2Shape.e_shapeTypeCount);
  74.          var _loc1_:int = 0;
  75.          while(_loc1_ < b2Shape.e_shapeTypeCount)
  76.          {
  77.             s_registers[_loc1_] = new Array(b2Shape.e_shapeTypeCount);
  78.             _loc2_ = 0;
  79.             while(_loc2_ < b2Shape.e_shapeTypeCount)
  80.             {
  81.                s_registers[_loc1_][_loc2_] = new b2ContactRegister();
  82.                _loc2_++;
  83.             }
  84.             _loc1_++;
  85.          }
  86.          AddType(b2CircleContact.Create,b2CircleContact.Destroy,b2Shape.e_circleShape,b2Shape.e_circleShape);
  87.          AddType(b2PolyAndCircleContact.Create,b2PolyAndCircleContact.Destroy,b2Shape.e_polyShape,b2Shape.e_circleShape);
  88.          AddType(b2PolyContact.Create,b2PolyContact.Destroy,b2Shape.e_polyShape,b2Shape.e_polyShape);
  89.       }
  90.       
  91.       public static function Destroy(param1:b2Contact, param2:*) : void
  92.       {
  93.          if(param1.GetManifoldCount() > 0)
  94.          {
  95.             param1.m_shape1.m_body.WakeUp();
  96.             param1.m_shape2.m_body.WakeUp();
  97.          }
  98.          var _loc3_:int = param1.m_shape1.m_type;
  99.          var _loc4_:int = param1.m_shape2.m_type;
  100.          var _loc5_:*;
  101.          (_loc5_ = s_registers[_loc3_][_loc4_].destroyFcn)(param1,param2);
  102.       }
  103.       
  104.       public static function AddType(param1:*, param2:*, param3:int, param4:int) : void
  105.       {
  106.          s_registers[param3][param4].createFcn = param1;
  107.          s_registers[param3][param4].destroyFcn = param2;
  108.          s_registers[param3][param4].primary = true;
  109.          if(param3 != param4)
  110.          {
  111.             s_registers[param4][param3].createFcn = param1;
  112.             s_registers[param4][param3].destroyFcn = param2;
  113.             s_registers[param4][param3].primary = false;
  114.          }
  115.       }
  116.       
  117.       public static function Create(param1:b2Shape, param2:b2Shape, param3:*) : b2Contact
  118.       {
  119.          var _loc7_:b2Contact = null;
  120.          var _loc8_:int = 0;
  121.          var _loc9_:b2Manifold = null;
  122.          if(s_initialized == false)
  123.          {
  124.             InitializeRegisters();
  125.             s_initialized = true;
  126.          }
  127.          var _loc4_:int = param1.m_type;
  128.          var _loc5_:int = param2.m_type;
  129.          var _loc6_:*;
  130.          if(_loc6_ = s_registers[_loc4_][_loc5_].createFcn)
  131.          {
  132.             if(s_registers[_loc4_][_loc5_].primary)
  133.             {
  134.                return _loc6_(param1,param2,param3);
  135.             }
  136.             _loc7_ = _loc6_(param2,param1,param3);
  137.             _loc8_ = 0;
  138.             while(_loc8_ < _loc7_.GetManifoldCount())
  139.             {
  140.                _loc9_ = _loc7_.GetManifolds()[_loc8_];
  141.                _loc9_.normal = _loc9_.normal.Negative();
  142.                _loc8_++;
  143.             }
  144.             return _loc7_;
  145.          }
  146.          return null;
  147.       }
  148.       
  149.       public function GetShape1() : b2Shape
  150.       {
  151.          return m_shape1;
  152.       }
  153.       
  154.       public function GetShape2() : b2Shape
  155.       {
  156.          return m_shape2;
  157.       }
  158.       
  159.       public function GetManifoldCount() : int
  160.       {
  161.          return m_manifoldCount;
  162.       }
  163.       
  164.       public function GetNext() : b2Contact
  165.       {
  166.          return m_next;
  167.       }
  168.       
  169.       public function GetManifolds() : Array
  170.       {
  171.          return null;
  172.       }
  173.       
  174.       public function Evaluate() : void
  175.       {
  176.       }
  177.    }
  178. }
  179.