@@ -114,8 +114,8 @@ void ResolveCollisionForces(const float penetration_depth,
114
114
no.Forces -= forcevec * gamma ;
115
115
}
116
116
117
-
118
- void RoR::ResolveInterActorCollisions (const float dt, PointColDetector &interPointCD,
117
+ // STUPID OLD CODE: all the following params always belong to the same actor, see `ActorManager::UpdatePhysicsSimulation()`
118
+ void RoR::ResolveInterActorCollisions (const float dt, InterPointColDetector &interPointCD,
119
119
const int free_collcab, int collcabs[], int cabs[],
120
120
collcab_rate_t inter_collcabrate[], node_t nodes[],
121
121
const float collrange,
@@ -137,69 +137,73 @@ void RoR::ResolveInterActorCollisions(const float dt, PointColDetector &interPoi
137
137
const auto na = &nodes[cabs[tmpv+1 ]];
138
138
const auto nb = &nodes[cabs[tmpv+2 ]];
139
139
140
- interPointCD.query (no->AbsPosition
141
- , na->AbsPosition
142
- , nb->AbsPosition , collrange);
140
+ Ogre::AxisAlignedBox collcab_box;
141
+ collcab_box.merge (no->AbsPosition );
142
+ collcab_box.merge (na->AbsPosition );
143
+ collcab_box.merge (nb->AbsPosition );
144
+ collcab_box.setMinimum (collcab_box.getMinimum () - collrange);
145
+ collcab_box.setMaximum (collcab_box.getMaximum () + collrange);
143
146
144
- if (! interPointCD.hit_list . empty () )
147
+ for ( const PointColDetector::ColActor& partner: interPointCD.collision_partners )
145
148
{
146
- // setup transformation of points to triangle local coordinates
147
- const Triangle triangle (na->AbsPosition , nb->AbsPosition , no->AbsPosition );
148
- const CartesianToTriangleTransform transform (triangle);
149
-
150
- for (ColPointID_t i_hit : interPointCD.hit_list )
149
+ if (interPointCD.QueryCollisionsWithSinglePartner (collcab_box, partner))
151
150
{
152
- const PointColDetector::ColPoint& h = interPointCD. contactable_point_pool [i_hit];
153
- const ActorPtr& hit_actor = App::GetGameContext ()-> GetActorManager ()-> GetActorById (h. actorid );
154
- node_t & hitnode = hit_actor-> ar_nodes [h. nodenum ] ;
151
+ // setup transformation of points to triangle local coordinates
152
+ const Triangle triangle (na-> AbsPosition , nb-> AbsPosition , no-> AbsPosition );
153
+ const CartesianToTriangleTransform transform (triangle) ;
155
154
156
- // transform point to triangle local coordinates
157
- const auto local_point = transform (hitnode.AbsPosition );
158
-
159
- // collision test
160
- const bool is_colliding = InsideTriangleTest (local_point, collrange);
161
- if (is_colliding)
155
+ for (NodeNum_t hitnode_num: interPointCD.hit_list )
162
156
{
163
- inter_collcabrate[i]. rate = 0 ;
157
+ node_t & hitnode = partner. actor -> ar_nodes [hitnode_num] ;
164
158
165
- const auto coord = local_point.barycentric ;
166
- auto distance = local_point.distance ;
167
- auto normal = triangle.normal ();
159
+ // transform point to triangle local coordinates
160
+ const auto local_point = transform (hitnode.AbsPosition );
168
161
169
- // adapt in case the collision is occuring on the backface of the triangle
170
- const auto neighbour_node_ids = hit_actor->ar_node_to_node_connections [h.nodenum ];
171
- const bool is_backface = BackfaceCollisionTest (distance, normal , *no, neighbour_node_ids, hit_actor->ar_nodes );
172
- if (is_backface)
162
+ // collision test
163
+ const bool is_colliding = InsideTriangleTest (local_point, collrange);
164
+ if (is_colliding)
173
165
{
174
- // flip surface normal and distance to triangle plane
175
- normal = -normal ;
176
- distance = -distance;
166
+ inter_collcabrate[i].rate = 0 ;
167
+
168
+ const auto coord = local_point.barycentric ;
169
+ auto distance = local_point.distance ;
170
+ auto normal = triangle.normal ();
171
+
172
+ // adapt in case the collision is occuring on the backface of the triangle
173
+ const auto neighbour_node_ids = partner.actor ->ar_node_to_node_connections [hitnode_num];
174
+ const bool is_backface = BackfaceCollisionTest (distance, normal , *no, neighbour_node_ids, partner.actor ->ar_nodes );
175
+ if (is_backface)
176
+ {
177
+ // flip surface normal and distance to triangle plane
178
+ normal = -normal ;
179
+ distance = -distance;
180
+ }
181
+
182
+ const auto penetration_depth = collrange - distance;
183
+
184
+ const bool remote = (partner.actor ->ar_state == ActorState::NETWORKED_OK);
185
+
186
+ ResolveCollisionForces (penetration_depth, hitnode, *na, *nb, *no, coord.alpha ,
187
+ coord.beta , coord.gamma , normal , dt, remote, submesh_ground_model);
188
+
189
+ hitnode.nd_last_collision_gm = &submesh_ground_model;
190
+ hitnode.nd_has_mesh_contact = true ;
191
+ na->nd_has_mesh_contact = true ;
192
+ nb->nd_has_mesh_contact = true ;
193
+ no->nd_has_mesh_contact = true ;
177
194
}
178
-
179
- const auto penetration_depth = collrange - distance;
180
-
181
- const bool remote = (hit_actor->ar_state == ActorState::NETWORKED_OK);
182
-
183
- ResolveCollisionForces (penetration_depth, hitnode, *na, *nb, *no, coord.alpha ,
184
- coord.beta , coord.gamma , normal , dt, remote, submesh_ground_model);
185
-
186
- hitnode.nd_last_collision_gm = &submesh_ground_model;
187
- hitnode.nd_has_mesh_contact = true ;
188
- na->nd_has_mesh_contact = true ;
189
- nb->nd_has_mesh_contact = true ;
190
- no->nd_has_mesh_contact = true ;
191
195
}
192
196
}
193
- }
194
- else
195
- {
196
- inter_collcabrate[i]. rate ++;
197
+ else
198
+ {
199
+ inter_collcabrate[i]. rate ++;
200
+ }
197
201
}
198
202
}
199
203
}
200
204
201
-
202
- void RoR::ResolveIntraActorCollisions (const float dt, PointColDetector &intraPointCD,
205
+ // STUPID OLD CODE: all the following params always belong to the same actor, see `Actor::CalcCabCollisions()`
206
+ void RoR::ResolveIntraActorCollisions (const float dt, IntraPointColDetector &intraPointCD,
203
207
const int free_collcab, int collcabs[], int cabs[],
204
208
collcab_rate_t intra_collcabrate[], node_t nodes[],
205
209
const float collrange,
@@ -224,64 +228,67 @@ void RoR::ResolveIntraActorCollisions(const float dt, PointColDetector &intraPoi
224
228
const auto na = &nodes[cabs[tmpv+1 ]];
225
229
const auto nb = &nodes[cabs[tmpv+2 ]];
226
230
227
- intraPointCD.query (no->AbsPosition
228
- , na->AbsPosition
229
- , nb->AbsPosition , collrange);
231
+ Ogre::AxisAlignedBox collcab_box;
232
+ collcab_box.merge (no->AbsPosition );
233
+ collcab_box.merge (na->AbsPosition );
234
+ collcab_box.merge (nb->AbsPosition );
235
+ collcab_box.setMinimum (collcab_box.getMinimum () - collrange);
236
+ collcab_box.setMaximum (collcab_box.getMaximum () + collrange);
230
237
231
238
bool collision = false ;
232
-
233
- if (!intraPointCD.hit_list .empty ())
239
+ for (const PointColDetector::ColActor& partner: intraPointCD.collision_partners )
234
240
{
235
- // setup transformation of points to triangle local coordinates
236
- const Triangle triangle (na->AbsPosition , nb->AbsPosition , no->AbsPosition );
237
- const CartesianToTriangleTransform transform (triangle);
238
-
239
- for (ColPointID_t i_hit : intraPointCD.hit_list )
241
+ if (intraPointCD.QueryCollisionsWithSinglePartner (collcab_box, partner))
240
242
{
241
- const PointColDetector::ColPoint& h = intraPointCD.contactable_point_pool [i_hit];
242
- const ActorPtr& hit_actor = App::GetGameContext ()->GetActorManager ()->GetActorById (h.actorid );
243
- node_t & hitnode = hit_actor->ar_nodes [h.nodenum ];
244
-
245
- // ignore wheel/chassis self contact
246
- if (hitnode.nd_tyre_node ) continue ;
247
- if (no == &hitnode || na == &hitnode || nb == &hitnode) continue ;
243
+ // setup transformation of points to triangle local coordinates
244
+ const Triangle triangle (na->AbsPosition , nb->AbsPosition , no->AbsPosition );
245
+ const CartesianToTriangleTransform transform (triangle);
248
246
249
- // transform point to triangle local coordinates
250
- const auto local_point = transform (hitnode.AbsPosition );
251
-
252
- // collision test
253
- const bool is_colliding = InsideTriangleTest (local_point, collrange);
254
- if (is_colliding)
247
+ for (NodeNum_t hitnode_num: intraPointCD.hit_list )
255
248
{
256
- collision = true ;
249
+ node_t & hitnode = partner.actor ->ar_nodes [hitnode_num];
250
+
251
+ // ignore wheel/chassis self contact
252
+ if (hitnode.nd_tyre_node ) continue ;
253
+ if (no == &hitnode || na == &hitnode || nb == &hitnode) continue ;
257
254
258
- const auto coord = local_point.barycentric ;
259
- auto distance = local_point.distance ;
260
- auto normal = triangle.normal ();
255
+ // transform point to triangle local coordinates
256
+ const auto local_point = transform (hitnode.AbsPosition );
261
257
262
- // adapt in case the collision is occuring on the backface of the triangle
263
- if (distance < 0 )
258
+ // collision test
259
+ const bool is_colliding = InsideTriangleTest (local_point, collrange);
260
+ if (is_colliding)
264
261
{
265
- // flip surface normal and distance to triangle plane
266
- normal = -normal ;
267
- distance = -distance;
268
- }
262
+ collision = true ;
263
+
264
+ const auto coord = local_point.barycentric ;
265
+ auto distance = local_point.distance ;
266
+ auto normal = triangle.normal ();
269
267
270
- const auto penetration_depth = collrange - distance;
268
+ // adapt in case the collision is occuring on the backface of the triangle
269
+ if (distance < 0 )
270
+ {
271
+ // flip surface normal and distance to triangle plane
272
+ normal = -normal ;
273
+ distance = -distance;
274
+ }
271
275
272
- ResolveCollisionForces (penetration_depth, hitnode, *na, *nb, *no, coord.alpha ,
273
- coord.beta , coord.gamma , normal , dt, false , submesh_ground_model);
276
+ const auto penetration_depth = collrange - distance;
277
+
278
+ ResolveCollisionForces (penetration_depth, hitnode, *na, *nb, *no, coord.alpha ,
279
+ coord.beta , coord.gamma , normal , dt, false , submesh_ground_model);
280
+ }
274
281
}
275
282
}
276
- }
277
283
278
- if (collision)
279
- {
280
- intra_collcabrate[i].rate = -20000 ;
281
- }
282
- else
283
- {
284
- intra_collcabrate[i].rate ++;
284
+ if (collision)
285
+ {
286
+ intra_collcabrate[i].rate = -20000 ;
287
+ }
288
+ else
289
+ {
290
+ intra_collcabrate[i].rate ++;
291
+ }
285
292
}
286
293
}
287
294
}
0 commit comments