use crate::core::{get_length_units_per_meter, SECRET_COOKIE};
use crate::math_functions::{Pos, Rot, Vec2, POS_ZERO, ROT_IDENTITY, VEC2_ZERO};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum BodyType {
#[default]
Static = 0,
Kinematic = 1,
Dynamic = 2,
}
pub const BODY_TYPE_COUNT: usize = 3;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct MotionLocks {
pub linear_x: bool,
pub linear_y: bool,
pub angular_z: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct BodyDef {
pub type_: BodyType,
pub position: Pos,
pub rotation: Rot,
pub linear_velocity: Vec2,
pub angular_velocity: f32,
pub linear_damping: f32,
pub angular_damping: f32,
pub gravity_scale: f32,
pub sleep_threshold: f32,
pub name: String,
pub user_data: u64,
pub motion_locks: MotionLocks,
pub enable_sleep: bool,
pub is_awake: bool,
pub is_bullet: bool,
pub is_enabled: bool,
pub allow_fast_rotation: bool,
pub enable_contact_recycling: bool,
pub internal_value: i32,
}
pub fn default_body_def() -> BodyDef {
BodyDef {
type_: BodyType::Static,
position: POS_ZERO,
rotation: ROT_IDENTITY,
linear_velocity: VEC2_ZERO,
angular_velocity: 0.0,
linear_damping: 0.0,
angular_damping: 0.0,
gravity_scale: 1.0,
sleep_threshold: 0.05 * get_length_units_per_meter(),
name: String::new(),
user_data: 0,
motion_locks: MotionLocks::default(),
enable_sleep: true,
is_awake: true,
is_bullet: false,
is_enabled: true,
allow_fast_rotation: false,
enable_contact_recycling: true,
internal_value: SECRET_COOKIE,
}
}
impl Default for BodyDef {
fn default() -> Self {
default_body_def()
}
}