Guest User

Untitled

a guest
Jun 19th, 2018
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.         /* ContactPointAdd, ContactPointRemove, ContactPointPersist */
  2.         public override function PreSolve(contact:b2Contact, oldManifold:b2Manifold):void
  3.         {      
  4.             var u1:ShapeUserData = contact.GetFixtureA().GetUserData();
  5.             var u2:ShapeUserData = contact.GetFixtureB().GetUserData();
  6.             if (u1 == null || u2 == null) return;
  7.            
  8.             var cr:int = rdPtr.collReg[u1.collType][u2.collType] | rdPtr.collReg[u2.collType][u1.collType];
  9.             cr &= 0xff; //char cr;
  10.            
  11.             if (cr == 1)
  12.             {
  13.                 /* Prepare collision data global to all points */
  14.                 var collData:CollData = new CollData();
  15.                 collData.body1 = u1.body;
  16.                 collData.body2 = u2.body;
  17.                 collData.collPoint.SetZero();
  18.                 collData.shape1 = u1.ID;
  19.                 collData.shape2 = u2.ID;
  20.                 collData.type1 = u1.collType;
  21.                 collData.type2 = u2.collType;
  22.                
  23.                 /* Get world manifold (so we can convert local to global contact points) */
  24.                 var worldManifold:b2WorldManifold = new b2WorldManifold();
  25.                 contact.GetWorldManifold(worldManifold);
  26.                
  27.                 /* Find differences between the two manifold point vectors */
  28.                 var newPoints:Vector.<b2ManifoldPoint> = contact.GetManifold().m_points;
  29.                 var oldPoints:Vector.<b2ManifoldPoint> = oldManifold.m_points;
  30.                
  31.                 /* Find new or old points */
  32.                 var point:b2ManifoldPoint;
  33.                 var c:CollideCallback;
  34.                 var i:int = 0;
  35.                
  36.                 for each(point in newPoints)
  37.                 {
  38.                     /* ContactPointAdd */
  39.                     if(!findPoint(oldPoints, point))
  40.                     {
  41.                         c = new CollideCallback(21);
  42.                         c.data = collData.clone();
  43.                         /* Collision point = average of global for both bodies of manifold local point */
  44.                        
  45.                         trace(newPoints.length, worldManifold.m_points.length);
  46.                        
  47.                         c.data.collPoint = worldManifold.m_points[i];
  48.                         c.data.collPoint.Multiply(rdPtr.scale);
  49.                         /* TODO copy velocity etc. */
  50.                         if(c.data.collPoint.x != 0 && c.data.collPoint.y != 0)
  51.                             rdPtr.addCallback(c);
  52.                     }
  53.                     /* ContactPointPersist */
  54.                     else
  55.                     {
  56.                         c = new CollideCallback(24);
  57.                         c.data = collData.clone();
  58.                         c.data.collPoint = point.m_localPoint;
  59.                         /* TODO copy velocity etc. */
  60.                         rdPtr.addCallback(c);
  61.                     }
  62.                    
  63.                     /* Keep track of wolrd point */
  64.                     ++i;
  65.                 }
  66.                
  67.                 /* Find removed points */
  68.                 for each(point in oldPoints)
  69.                 {
  70.                     /* ContactPointRemove */
  71.                     if(!findPoint(newPoints, point))
  72.                     {
  73.                         c = new CollideCallback(27);
  74.                         c.data = collData.clone();
  75.                         c.data.collPoint = point.m_localPoint;
  76.                         /* TODO copy velocity etc. */
  77.                         rdPtr.addCallback(c);
  78.                     }
  79.                 }
  80.             }
  81.         }
Add Comment
Please, Sign In to add comment