Update the contact manifold and touching status. Note: do not assume the fixture AABBs are overlapping or are valid.
(contact B2ContactInterface, listener B2ContactListenerInterface)
| 447 | // Update the contact manifold and touching status. |
| 448 | // Note: do not assume the fixture AABBs are overlapping or are valid. |
| 449 | func B2ContactUpdate(contact B2ContactInterface, listener B2ContactListenerInterface) { |
| 450 | oldManifold := *contact.GetManifold() |
| 451 | |
| 452 | // Re-enable this contact. |
| 453 | contact.SetFlags(contact.GetFlags() | B2Contact_Flag.E_enabledFlag) |
| 454 | |
| 455 | touching := false |
| 456 | wasTouching := (contact.GetFlags() & B2Contact_Flag.E_touchingFlag) == B2Contact_Flag.E_touchingFlag |
| 457 | |
| 458 | sensorA := contact.GetFixtureA().IsSensor() |
| 459 | sensorB := contact.GetFixtureB().IsSensor() |
| 460 | sensor := sensorA || sensorB |
| 461 | |
| 462 | bodyA := contact.GetFixtureA().GetBody() |
| 463 | bodyB := contact.GetFixtureB().GetBody() |
| 464 | xfA := bodyA.GetTransform() |
| 465 | xfB := bodyB.GetTransform() |
| 466 | |
| 467 | // Is this contact a sensor? |
| 468 | if sensor { |
| 469 | shapeA := contact.GetFixtureA().GetShape() |
| 470 | shapeB := contact.GetFixtureB().GetShape() |
| 471 | touching = B2TestOverlapShapes(shapeA, contact.GetChildIndexA(), shapeB, contact.GetChildIndexB(), xfA, xfB) |
| 472 | |
| 473 | // Sensors don't generate manifolds. |
| 474 | contact.GetManifold().PointCount = 0 |
| 475 | } else { |
| 476 | // *B2Contact is extended by specialized contact structs and mentionned by B2ContactInterface but not implemented on specialized structs |
| 477 | // Thus when |
| 478 | //spew.Dump("AVANT", contact.GetManifold()) |
| 479 | contact.Evaluate(contact.GetManifold(), xfA, xfB) // should be evaluated on specialisations of contact (like CircleContact) |
| 480 | //spew.Dump("APRES", contact.GetManifold()) |
| 481 | touching = contact.GetManifold().PointCount > 0 |
| 482 | |
| 483 | // Match old contact ids to new contact ids and copy the |
| 484 | // stored impulses to warm start the solver. |
| 485 | for i := 0; i < contact.GetManifold().PointCount; i++ { |
| 486 | mp2 := &contact.GetManifold().Points[i] |
| 487 | mp2.NormalImpulse = 0.0 |
| 488 | mp2.TangentImpulse = 0.0 |
| 489 | id2 := mp2.Id |
| 490 | |
| 491 | for j := 0; j < oldManifold.PointCount; j++ { |
| 492 | mp1 := &oldManifold.Points[j] |
| 493 | |
| 494 | if mp1.Id.Key() == id2.Key() { |
| 495 | mp2.NormalImpulse = mp1.NormalImpulse |
| 496 | mp2.TangentImpulse = mp1.TangentImpulse |
| 497 | break |
| 498 | } |
| 499 | } |
| 500 | } |
| 501 | |
| 502 | if touching != wasTouching { |
| 503 | bodyA.SetAwake(true) |
| 504 | bodyB.SetAwake(true) |
| 505 | } |
| 506 | } |
no test coverage detected