Find TOI contacts and solve them.
(step B2TimeStep)
| 606 | |
| 607 | // Find TOI contacts and solve them. |
| 608 | func (world *B2World) SolveTOI(step B2TimeStep) { |
| 609 | |
| 610 | island := MakeB2Island(2*B2_maxTOIContacts, B2_maxTOIContacts, 0, world.M_contactManager.M_contactListener) |
| 611 | |
| 612 | if world.M_stepComplete { |
| 613 | for b := world.M_bodyList; b != nil; b = b.M_next { |
| 614 | b.M_flags &= ^B2Body_Flags.E_islandFlag |
| 615 | b.M_sweep.Alpha0 = 0.0 |
| 616 | } |
| 617 | |
| 618 | for c := world.M_contactManager.M_contactList; c != nil; c = c.GetNext() { |
| 619 | // Invalidate TOI |
| 620 | c.SetFlags(c.GetFlags() & ^(B2Contact_Flag.E_toiFlag | B2Contact_Flag.E_islandFlag)) |
| 621 | c.SetTOICount(0) |
| 622 | c.SetTOI(1.0) |
| 623 | } |
| 624 | } |
| 625 | |
| 626 | // Find TOI events and solve them. |
| 627 | for { |
| 628 | // Find the first TOI. |
| 629 | var minContact B2ContactInterface = nil // has to be a pointer |
| 630 | minAlpha := 1.0 |
| 631 | |
| 632 | for c := world.M_contactManager.M_contactList; c != nil; c = c.GetNext() { |
| 633 | |
| 634 | // Is this contact disabled? |
| 635 | if c.IsEnabled() == false { |
| 636 | continue |
| 637 | } |
| 638 | |
| 639 | // Prevent excessive sub-stepping. |
| 640 | if c.GetTOICount() > B2_maxSubSteps { |
| 641 | continue |
| 642 | } |
| 643 | |
| 644 | alpha := 1.0 |
| 645 | if (c.GetFlags() & B2Contact_Flag.E_toiFlag) != 0x0000 { |
| 646 | // This contact has a valid cached TOI. |
| 647 | alpha = c.GetTOI() |
| 648 | } else { |
| 649 | fA := c.GetFixtureA() |
| 650 | fB := c.GetFixtureB() |
| 651 | |
| 652 | // Is there a sensor? |
| 653 | if fA.IsSensor() || fB.IsSensor() { |
| 654 | continue |
| 655 | } |
| 656 | |
| 657 | bA := fA.GetBody() |
| 658 | bB := fB.GetBody() |
| 659 | |
| 660 | typeA := bA.M_type |
| 661 | typeB := bB.M_type |
| 662 | B2Assert(typeA == B2BodyType.B2_dynamicBody || typeB == B2BodyType.B2_dynamicBody) |
| 663 | |
| 664 | activeA := bA.IsAwake() && typeA != B2BodyType.B2_staticBody |
| 665 | activeB := bB.IsAwake() && typeB != B2BodyType.B2_staticBody |
no test coverage detected