use crate::core::{get_length_units_per_meter, SECRET_COOKIE};
use crate::id::ShapeId;
use crate::math_functions::{Pos, Vec2, POS_ZERO, VEC2_ZERO};
pub type FrictionCallback = fn(f32, u64, f32, u64) -> f32;
pub type RestitutionCallback = fn(f32, u64, f32, u64) -> f32;
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct RayResult {
pub shape_id: ShapeId,
pub point: Pos,
pub normal: Vec2,
pub fraction: f32,
pub node_visits: i32,
pub leaf_visits: i32,
pub hit: bool,
}
impl Default for RayResult {
fn default() -> Self {
RayResult {
shape_id: ShapeId::default(),
point: POS_ZERO,
normal: VEC2_ZERO,
fraction: 0.0,
node_visits: 0,
leaf_visits: 0,
hit: false,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Capacity {
pub static_shape_count: i32,
pub dynamic_shape_count: i32,
pub static_body_count: i32,
pub dynamic_body_count: i32,
pub contact_count: i32,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct Counters {
pub byte_count: i64,
pub body_count: i32,
pub shape_count: i32,
pub contact_count: i32,
pub joint_count: i32,
pub island_count: i32,
pub stack_used: i32,
pub static_tree_height: i32,
pub tree_height: i32,
pub task_count: i32,
pub color_counts: [i32; crate::constants::GRAPH_COLOR_COUNT as usize],
pub awake_contact_count: i32,
pub recycled_contact_count: i32,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct ExplosionDef {
pub mask_bits: u64,
pub position: Pos,
pub radius: f32,
pub falloff: f32,
pub impulse_per_length: f32,
}
pub fn default_explosion_def() -> ExplosionDef {
ExplosionDef {
mask_bits: crate::dynamic_tree::DEFAULT_MASK_BITS,
position: POS_ZERO,
radius: 0.0,
falloff: 0.0,
impulse_per_length: 0.0,
}
}
impl Default for ExplosionDef {
fn default() -> Self {
default_explosion_def()
}
}
#[derive(Debug, Clone, Copy)]
pub struct WorldDef {
pub gravity: Vec2,
pub restitution_threshold: f32,
pub hit_event_threshold: f32,
pub contact_hertz: f32,
pub contact_damping_ratio: f32,
pub contact_speed: f32,
pub maximum_linear_speed: f32,
pub friction_callback: Option<FrictionCallback>,
pub restitution_callback: Option<RestitutionCallback>,
pub enable_sleep: bool,
pub enable_continuous: bool,
pub enable_contact_softening: bool,
pub worker_count: i32,
pub user_data: u64,
pub capacity: Capacity,
pub internal_value: i32,
}
pub fn default_world_def() -> WorldDef {
let length_units = get_length_units_per_meter();
WorldDef {
gravity: Vec2 { x: 0.0, y: -10.0 },
hit_event_threshold: 1.0 * length_units,
restitution_threshold: 1.0 * length_units,
contact_speed: 3.0 * length_units,
contact_hertz: 30.0,
contact_damping_ratio: 10.0,
maximum_linear_speed: 400.0 * length_units,
friction_callback: None,
restitution_callback: None,
enable_sleep: true,
enable_continuous: true,
enable_contact_softening: false,
worker_count: 0,
user_data: 0,
capacity: Capacity::default(),
internal_value: SECRET_COOKIE,
}
}
impl Default for WorldDef {
fn default() -> Self {
default_world_def()
}
}