Split rigid-bodies and colliders into multiple components

This commit is contained in:
Crozet Sébastien
2021-04-26 17:59:25 +02:00
parent aaf80bfa87
commit c32da78f2a
91 changed files with 5969 additions and 3653 deletions

View File

@@ -1,7 +1,11 @@
//! Physics pipeline structures.
use crate::dynamics::{JointSet, RigidBodySet};
use crate::geometry::{BroadPhase, BroadPhasePairEvent, ColliderPair, ColliderSet, NarrowPhase};
use crate::data::{ComponentSet, ComponentSetMut};
use crate::dynamics::{
IslandManager, JointSet, RigidBodyActivation, RigidBodyColliders, RigidBodyDominance,
RigidBodyIds, RigidBodyType, RigidBodyVelocity,
};
use crate::geometry::{BroadPhase, BroadPhasePairEvent, ColliderPair, ColliderShape, NarrowPhase};
use crate::math::Real;
use crate::pipeline::{EventHandler, PhysicsHooks};
@@ -34,46 +38,25 @@ impl CollisionPipeline {
}
/// Executes one step of the collision detection.
pub fn step(
pub fn step<Bodies, Colliders>(
&mut self,
prediction_distance: Real,
broad_phase: &mut BroadPhase,
narrow_phase: &mut NarrowPhase,
bodies: &mut RigidBodySet,
colliders: &mut ColliderSet,
hooks: &dyn PhysicsHooks,
events: &dyn EventHandler,
) {
colliders.handle_user_changes(bodies);
bodies.handle_user_changes(colliders);
self.broadphase_collider_pairs.clear();
self.broad_phase_events.clear();
broad_phase.update(prediction_distance, colliders, &mut self.broad_phase_events);
narrow_phase.handle_user_changes(colliders, bodies, events);
narrow_phase.register_pairs(colliders, bodies, &self.broad_phase_events, events);
narrow_phase.compute_contacts(prediction_distance, bodies, colliders, hooks, events);
narrow_phase.compute_intersections(bodies, colliders, hooks, events);
bodies.update_active_set_with_contacts(
colliders,
narrow_phase,
self.empty_joints.joint_graph(),
128,
);
// Update colliders positions and kinematic bodies positions.
bodies.foreach_active_body_mut_internal(|_, rb| {
rb.position = rb.next_position;
rb.update_colliders_positions(colliders);
for handle in &rb.colliders {
let collider = colliders.get_mut_internal(*handle).unwrap();
collider.position = rb.position * collider.delta;
}
});
bodies.modified_inactive_set.clear();
_prediction_distance: Real,
_broad_phase: &mut BroadPhase,
_narrow_phase: &mut NarrowPhase,
_islands: &mut IslandManager,
_bodies: &mut Bodies,
_colliders: &mut Colliders,
_hooks: &dyn PhysicsHooks<Bodies, Colliders>,
_events: &dyn EventHandler,
) where
Bodies: ComponentSetMut<RigidBodyIds>
+ ComponentSetMut<RigidBodyActivation>
+ ComponentSet<RigidBodyColliders>
+ ComponentSetMut<RigidBodyVelocity>
+ ComponentSet<RigidBodyDominance>
+ ComponentSet<RigidBodyType>,
Colliders: ComponentSetMut<ColliderShape>,
{
unimplemented!()
}
}