use crate::{types::Vec2, world::World};
use boxdd_sys::ffi;
#[derive(Copy, Clone, Debug)]
pub struct ExplosionDef(pub(crate) ffi::b2ExplosionDef);
impl Default for ExplosionDef {
fn default() -> Self {
let def = unsafe { ffi::b2DefaultExplosionDef() };
Self(def)
}
}
impl ExplosionDef {
pub fn new() -> Self {
Self::default()
}
pub fn position<V: Into<Vec2>>(mut self, p: V) -> Self {
self.0.position = p.into().into();
self
}
pub fn radius(mut self, r: f32) -> Self {
self.0.radius = r;
self
}
pub fn falloff(mut self, f: f32) -> Self {
self.0.falloff = f;
self
}
pub fn impulse_per_length(mut self, v: f32) -> Self {
self.0.impulsePerLength = v;
self
}
}
pub trait WorldExplosionExt {
fn explode(&mut self, def: &ExplosionDef);
}
impl WorldExplosionExt for World {
fn explode(&mut self, def: &ExplosionDef) {
crate::core::callback_state::assert_not_in_callback();
unsafe { ffi::b2World_Explode(self.raw(), &def.0) }
}
}