generateContacts
(contactEq *equation.Contact)
| 536 | |
| 537 | // generateContacts |
| 538 | func (s *Simulation) updateSleepAndCollisionMatrix(contactEq *equation.Contact) { |
| 539 | |
| 540 | // Get current collision indices |
| 541 | bodyA := s.bodies[contactEq.BodyA().Index()] |
| 542 | bodyB := s.bodies[contactEq.BodyB().Index()] |
| 543 | |
| 544 | // TODO future: update equations with physical material properties |
| 545 | |
| 546 | if bodyA.AllowSleep() && bodyA.BodyType() == object.Dynamic && bodyA.SleepState() == object.Sleeping && bodyB.SleepState() == object.Awake && bodyB.BodyType() != object.Static { |
| 547 | velocityB := bodyB.Velocity() |
| 548 | angularVelocityB := bodyB.AngularVelocity() |
| 549 | speedSquaredB := velocityB.LengthSq() + angularVelocityB.LengthSq() |
| 550 | speedLimitSquaredB := math32.Pow(bodyB.SleepSpeedLimit(), 2) |
| 551 | if speedSquaredB >= speedLimitSquaredB*2 { |
| 552 | bodyA.SetWakeUpAfterNarrowphase(true) |
| 553 | } |
| 554 | } |
| 555 | |
| 556 | if bodyB.AllowSleep() && bodyB.BodyType() == object.Dynamic && bodyB.SleepState() == object.Sleeping && bodyA.SleepState() == object.Awake && bodyA.BodyType() != object.Static { |
| 557 | velocityA := bodyA.Velocity() |
| 558 | angularVelocityA := bodyA.AngularVelocity() |
| 559 | speedSquaredA := velocityA.LengthSq() + angularVelocityA.LengthSq() |
| 560 | speedLimitSquaredA := math32.Pow(bodyA.SleepSpeedLimit(), 2) |
| 561 | if speedSquaredA >= speedLimitSquaredA*2 { |
| 562 | bodyB.SetWakeUpAfterNarrowphase(true) |
| 563 | } |
| 564 | } |
| 565 | |
| 566 | // Now we know that i and j are in contact. Set collision matrix state |
| 567 | s.collisionMatrix.Set(bodyA.Index(), bodyB.Index(), true) |
| 568 | |
| 569 | if s.prevCollisionMatrix.Get(bodyA.Index(), bodyB.Index()) == false { |
| 570 | // First contact! |
| 571 | bodyA.Dispatch(CollisionEv, &CollideEvent{bodyB, contactEq}) |
| 572 | bodyB.Dispatch(CollisionEv, &CollideEvent{bodyA, contactEq}) |
| 573 | } |
| 574 | |
| 575 | // TODO this is only for events |
| 576 | //s.bodyOverlapKeeper.set(bodyA.id, bodyB.id) |
| 577 | //s.shapeOverlapKeeper.set(si.id, sj.id) |
| 578 | |
| 579 | } |
| 580 | |
| 581 | func (s *Simulation) emitContactEvents() { |
| 582 | //TODO |
no test coverage detected