@@ -87,58 +87,58 @@ fn check_collisions(
87
87
mut event_writer : EventWriter < CollisionEvent > ,
88
88
query : Query < Entity > ,
89
89
) {
90
- // let mut before = collisions.clone();
91
- // let mut events = Vec::<CollisionEvent>::new();
92
-
93
- // // first pass detects intersections
94
- // for (e1, e2, _) in rapier_context.intersection_pairs() {
95
- // if !query.contains(e1) || !query.contains(e2) {
96
- // // entity are removed from ECS
97
- // // so we are not spawning events for them
98
- // // they will be removed in last loop
99
- // continue;
100
- // }
101
-
102
- // let pair = EntityPair::new(e1, e2);
103
- // before.remove(&pair);
104
- // if collisions.contains(&pair) {
105
- // // we already have a started event for this intersection
106
- // continue;
107
- // }
108
-
109
- // collisions.add(pair);
110
- // events.push(CollisionEvent::Started(pair.entity1, pair.entity2));
111
- // }
112
-
113
- // // second pass detects contacts
114
- // for c in rapier_context.contact_pairs() {
115
- // let e1 = c.collider1();
116
- // let e2 = c.collider2();
117
-
118
- // if !query.contains(e1) || !query.contains(e2) {
119
- // // entity are removed from ECS
120
- // // so we are not spawning events for them
121
- // // they will be removed in last loop
122
- // continue;
123
- // }
124
-
125
- // let pair = EntityPair::new(e1, e2);
126
- // before.remove(&pair);
127
- // if collisions.contains(&pair) {
128
- // // we already have a started event for this intersection
129
- // continue;
130
- // }
131
-
132
- // collisions.add(pair);
133
- // events.push(CollisionEvent::Started(e1, e2));
134
- // }
135
-
136
- // // emit ended collisions
137
- // // TODO: implement iter() that return an iterator on the collisions struct
138
- // for (pair, _) in before.pairs {
139
- // collisions.remove(&pair);
140
- // events.push(CollisionEvent::Stopped(pair.entity1, pair.entity2));
141
- // }
142
-
143
- // event_writer.send_batch(events);
90
+ let mut before = collisions. clone ( ) ;
91
+ let mut events = Vec :: < CollisionEvent > :: new ( ) ;
92
+
93
+ // first pass detects intersections
94
+ for ( e1, e2, _) in rapier_context. intersection_pairs ( ) {
95
+ if !query. contains ( e1) || !query. contains ( e2) {
96
+ // entity are removed from ECS
97
+ // so we are not spawning events for them
98
+ // they will be removed in last loop
99
+ continue ;
100
+ }
101
+
102
+ let pair = EntityPair :: new ( e1, e2) ;
103
+ before. remove ( & pair) ;
104
+ if collisions. contains ( & pair) {
105
+ // we already have a started event for this intersection
106
+ continue ;
107
+ }
108
+
109
+ collisions. add ( pair) ;
110
+ events. push ( CollisionEvent :: Started ( pair. entity1 , pair. entity2 ) ) ;
111
+ }
112
+
113
+ // second pass detects contacts
114
+ for c in rapier_context. contact_pairs ( ) {
115
+ let e1 = c. collider1 ( ) ;
116
+ let e2 = c. collider2 ( ) ;
117
+
118
+ if !query. contains ( e1) || !query. contains ( e2) {
119
+ // entity are removed from ECS
120
+ // so we are not spawning events for them
121
+ // they will be removed in last loop
122
+ continue ;
123
+ }
124
+
125
+ let pair = EntityPair :: new ( e1, e2) ;
126
+ before. remove ( & pair) ;
127
+ if collisions. contains ( & pair) {
128
+ // we already have a started event for this intersection
129
+ continue ;
130
+ }
131
+
132
+ collisions. add ( pair) ;
133
+ events. push ( CollisionEvent :: Started ( e1, e2) ) ;
134
+ }
135
+
136
+ // emit ended collisions
137
+ // TODO: implement iter() that return an iterator on the collisions struct
138
+ for ( pair, _) in before. pairs {
139
+ collisions. remove ( & pair) ;
140
+ events. push ( CollisionEvent :: Stopped ( pair. entity1 , pair. entity2 ) ) ;
141
+ }
142
+
143
+ event_writer. send_batch ( events) ;
144
144
}
0 commit comments