MCPcopy
hub / github.com/g3n/engine / updateSleepAndCollisionMatrix

Method updateSleepAndCollisionMatrix

experimental/physics/simulation.go:538–579  ·  view source on GitHub ↗

generateContacts

(contactEq *equation.Contact)

Source from the content-addressed store, hash-verified

536
537// generateContacts
538func (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
581func (s *Simulation) emitContactEvents() {
582 //TODO

Callers 1

internalStepMethod · 0.95

Calls 15

PowFunction · 0.92
AllowSleepMethod · 0.80
BodyTypeMethod · 0.80
SleepStateMethod · 0.80
SleepSpeedLimitMethod · 0.80
GetMethod · 0.80
IndexMethod · 0.65
BodyAMethod · 0.65
BodyBMethod · 0.65
VelocityMethod · 0.65
AngularVelocityMethod · 0.65

Tested by

no test coverage detected