use crate::rapier::{
geometry::{ContactEvent, IntersectionEvent},
pipeline::{EventHandler, PhysicsHooks},
};
use concurrent_queue::ConcurrentQueue;
use rapier::math::Vector;
pub struct RapierConfiguration {
pub gravity: Vector<f32>,
pub scale: f32,
pub physics_pipeline_active: bool,
pub query_pipeline_active: bool,
pub time_dependent_number_of_timesteps: bool,
}
impl Default for RapierConfiguration {
fn default() -> Self {
Self {
gravity: Vector::y() * -9.81,
scale: 1.0,
physics_pipeline_active: true,
query_pipeline_active: true,
time_dependent_number_of_timesteps: false,
}
}
}
pub struct EventQueue {
pub contact_events: ConcurrentQueue<ContactEvent>,
pub intersection_events: ConcurrentQueue<IntersectionEvent>,
pub auto_clear: bool,
}
impl EventQueue {
pub fn new(auto_clear: bool) -> Self {
Self {
contact_events: ConcurrentQueue::unbounded(),
intersection_events: ConcurrentQueue::unbounded(),
auto_clear,
}
}
pub fn clear(&self) {
while let Ok(_) = self.contact_events.pop() {}
while let Ok(_) = self.intersection_events.pop() {}
}
}
impl EventHandler for EventQueue {
fn handle_intersection_event(&self, event: IntersectionEvent) {
let _ = self.intersection_events.push(event);
}
fn handle_contact_event(&self, event: ContactEvent) {
let _ = self.contact_events.push(event);
}
}
#[derive(Default)]
pub struct SimulationToRenderTime {
pub diff: f32,
}
pub struct UserPhysicsHooks {
pub hooks: Box<dyn PhysicsHooks>,
}
impl UserPhysicsHooks {
pub fn new() -> Self {
Self {
hooks: Box::new(()),
}
}
pub fn hooks(&mut self, hooks: impl PhysicsHooks + 'static) {
self.hooks = Box::new(hooks) as Box<dyn PhysicsHooks>;
}
}