Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* ContactPointAdd, ContactPointRemove, ContactPointPersist */
- public override function PreSolve(contact:b2Contact, oldManifold:b2Manifold):void
- {
- var u1:ShapeUserData = contact.GetFixtureA().GetUserData();
- var u2:ShapeUserData = contact.GetFixtureB().GetUserData();
- if (u1 == null || u2 == null) return;
- var cr:int = rdPtr.collReg[u1.collType][u2.collType] | rdPtr.collReg[u2.collType][u1.collType];
- cr &= 0xff; //char cr;
- if (cr == 1)
- {
- /* Prepare collision data global to all points */
- var collData:CollData = new CollData();
- collData.body1 = u1.body;
- collData.body2 = u2.body;
- collData.collPoint.SetZero();
- collData.shape1 = u1.ID;
- collData.shape2 = u2.ID;
- collData.type1 = u1.collType;
- collData.type2 = u2.collType;
- /* Get world manifold (so we can convert local to global contact points) */
- var worldManifold:b2WorldManifold = new b2WorldManifold();
- contact.GetWorldManifold(worldManifold);
- /* Find differences between the two manifold point vectors */
- var newPoints:Vector.<b2ManifoldPoint> = contact.GetManifold().m_points;
- var oldPoints:Vector.<b2ManifoldPoint> = oldManifold.m_points;
- /* Find new or old points */
- var point:b2ManifoldPoint;
- var c:CollideCallback;
- var i:int = 0;
- for each(point in newPoints)
- {
- /* ContactPointAdd */
- if(!findPoint(oldPoints, point))
- {
- c = new CollideCallback(21);
- c.data = collData.clone();
- /* Collision point = average of global for both bodies of manifold local point */
- trace(newPoints.length, worldManifold.m_points.length);
- c.data.collPoint = worldManifold.m_points[i];
- c.data.collPoint.Multiply(rdPtr.scale);
- /* TODO copy velocity etc. */
- if(c.data.collPoint.x != 0 && c.data.collPoint.y != 0)
- rdPtr.addCallback(c);
- }
- /* ContactPointPersist */
- else
- {
- c = new CollideCallback(24);
- c.data = collData.clone();
- c.data.collPoint = point.m_localPoint;
- /* TODO copy velocity etc. */
- rdPtr.addCallback(c);
- }
- /* Keep track of wolrd point */
- ++i;
- }
- /* Find removed points */
- for each(point in oldPoints)
- {
- /* ContactPointRemove */
- if(!findPoint(newPoints, point))
- {
- c = new CollideCallback(27);
- c.data = collData.clone();
- c.data.collPoint = point.m_localPoint;
- /* TODO copy velocity etc. */
- rdPtr.addCallback(c);
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment