use glam::Vec3A;
use super::Arena;
fn combine_world_contact_normal_sums(sums: impl IntoIterator<Item = Vec3A>) -> Option<Vec3A> {
const MIN_LEN_SQ: f32 = 1e-8;
let mut total = Vec3A::ZERO;
for sum in sums {
let len_sq = sum.length_squared();
if len_sq >= MIN_LEN_SQ {
total += sum / len_sq.sqrt();
}
}
let len_sq = total.length_squared();
(len_sq >= MIN_LEN_SQ).then(|| total / len_sq.sqrt())
}
impl Arena {
pub(super) fn update_world_contact_normal(&mut self) {
let car_count = self.cars.len();
for car_idx in 0..car_count {
let combined = combine_world_contact_normal_sums(
self.contact_tracker
.world_contact_normal_groups()
.iter()
.filter(|group| group.car_idx == car_idx)
.map(|group| group.sum),
);
if let Some(normal) = combined {
self.cars[car_idx].state.cache.world_contact_normal = Some(normal);
}
}
}
}