Add contact force events generated above a user-defined threshold

This commit is contained in:
Sébastien Crozet
2022-06-24 19:00:34 +02:00
parent d6b6189861
commit c9d8277377
8 changed files with 255 additions and 51 deletions

View File

@@ -86,10 +86,13 @@ type Callbacks =
#[allow(dead_code)]
impl Harness {
pub fn new_empty() -> Self {
let event_channel = crossbeam::channel::unbounded();
let event_handler = ChannelEventCollector::new(event_channel.0);
let collision_event_channel = crossbeam::channel::unbounded();
let contact_force_event_channel = crossbeam::channel::unbounded();
let event_handler =
ChannelEventCollector::new(collision_event_channel.0, contact_force_event_channel.0);
let events = PhysicsEvents {
events: event_channel.1,
collision_events: collision_event_channel.1,
contact_force_events: contact_force_event_channel.1,
};
let physics = PhysicsState::new();
let state = RunState::new();

View File

@@ -3,7 +3,7 @@ use rapier::dynamics::{
CCDSolver, ImpulseJointSet, IntegrationParameters, IslandManager, MultibodyJointSet,
RigidBodySet,
};
use rapier::geometry::{BroadPhase, ColliderSet, CollisionEvent, NarrowPhase};
use rapier::geometry::{BroadPhase, ColliderSet, CollisionEvent, CollisionForceEvent, NarrowPhase};
use rapier::math::{Real, Vector};
use rapier::pipeline::{PhysicsHooks, PhysicsPipeline, QueryPipeline};
@@ -107,11 +107,13 @@ impl PhysicsState {
}
pub struct PhysicsEvents {
pub events: Receiver<CollisionEvent>,
pub collision_events: Receiver<CollisionEvent>,
pub contact_force_events: Receiver<CollisionForceEvent>,
}
impl PhysicsEvents {
pub fn poll_all(&self) {
while let Ok(_) = self.events.try_recv() {}
while let Ok(_) = self.collision_events.try_recv() {}
while let Ok(_) = self.contact_force_events.try_recv() {}
}
}