MCPcopy Create free account
hub / github.com/ByteArena/box2d / Collide

Method Collide

DynamicsB2ContactManager.go:86–145  ·  view source on GitHub ↗

This is the top level collision call for the time step. Here all the narrow phase collision is processed for the world contact list.

()

Source from the content-addressed store, hash-verified

84// all the narrow phase collision is processed for the world
85// contact list.
86func (mgr *B2ContactManager) Collide() {
87 // Update awake contacts.
88 c := mgr.M_contactList
89
90 for c != nil {
91 fixtureA := c.GetFixtureA()
92 fixtureB := c.GetFixtureB()
93 indexA := c.GetChildIndexA()
94 indexB := c.GetChildIndexB()
95 bodyA := fixtureA.GetBody()
96 bodyB := fixtureB.GetBody()
97
98 // Is this contact flagged for filtering?
99 if (c.GetFlags() & B2Contact_Flag.E_filterFlag) != 0x0000 {
100 // Should these bodies collide?
101 if bodyB.ShouldCollide(bodyA) == false {
102 cNuke := c
103 c = cNuke.GetNext()
104 mgr.Destroy(cNuke)
105 continue
106 }
107
108 // Check user filtering.
109 if mgr.M_contactFilter != nil && mgr.M_contactFilter.ShouldCollide(fixtureA, fixtureB) == false {
110 cNuke := c
111 c = cNuke.GetNext()
112 mgr.Destroy(cNuke)
113 continue
114 }
115
116 // Clear the filtering flag.
117 c.SetFlags(c.GetFlags() & ^B2Contact_Flag.E_filterFlag)
118 }
119
120 activeA := bodyA.IsAwake() && bodyA.M_type != B2BodyType.B2_staticBody
121 activeB := bodyB.IsAwake() && bodyB.M_type != B2BodyType.B2_staticBody
122
123 // At least one body must be awake and it must be dynamic or kinematic.
124 if activeA == false && activeB == false {
125 c = c.GetNext()
126 continue
127 }
128
129 proxyIdA := fixtureA.M_proxies[indexA].ProxyId
130 proxyIdB := fixtureB.M_proxies[indexB].ProxyId
131 overlap := mgr.M_broadPhase.TestOverlap(proxyIdA, proxyIdB)
132
133 // Here we destroy contacts that cease to overlap in the broad-phase.
134 if overlap == false {
135 cNuke := c
136 c = cNuke.GetNext()
137 mgr.Destroy(cNuke)
138 continue
139 }
140
141 // The contact persists.
142 B2ContactUpdate(c, mgr.M_contactListener)
143 c = c.GetNext()

Callers

nothing calls this directly

Calls 13

DestroyMethod · 0.95
B2ContactUpdateFunction · 0.85
GetBodyMethod · 0.80
IsAwakeMethod · 0.80
TestOverlapMethod · 0.80
GetFixtureAMethod · 0.65
GetFixtureBMethod · 0.65
GetChildIndexAMethod · 0.65
GetChildIndexBMethod · 0.65
GetFlagsMethod · 0.65
ShouldCollideMethod · 0.65
GetNextMethod · 0.65

Tested by

no test coverage detected