mod continuous;
mod integrate;
mod solve;
use crate::math_functions::PI;
pub use solve::solve;
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct Softness {
pub bias_rate: f32,
pub mass_scale: f32,
pub impulse_scale: f32,
}
pub fn make_soft(hertz: f32, zeta: f32, h: f32) -> Softness {
if hertz == 0.0 {
return Softness {
bias_rate: 0.0,
mass_scale: 0.0,
impulse_scale: 0.0,
};
}
let omega = 2.0 * PI * hertz;
let a1 = 2.0 * zeta + h * omega;
let a2 = h * omega * a1;
let a3 = 1.0 / (1.0 + a2);
Softness {
bias_rate: omega / a1,
mass_scale: a2 * a3,
impulse_scale: a3,
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(i32)]
pub enum SolverStageType {
PrepareJoints = 0,
PrepareWideContacts = 1,
PrepareContacts = 2,
IntegrateVelocities = 3,
WarmStart = 4,
Solve = 5,
IntegratePositions = 6,
Relax = 7,
Restitution = 8,
StoreWideImpulses = 9,
StoreImpulses = 10,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
#[repr(u8)]
pub enum SolverBlockType {
BodyBlock = 0,
JointBlock = 1,
WideContactBlock = 2,
ContactBlock = 3,
GraphJointBlock = 4,
GraphWideContactBlock = 5,
GraphContactBlock = 6,
OverflowBlock = 7,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub struct SolverBlock {
pub start_index: i32,
pub count: u16,
pub block_type: u8,
pub color_index: u8,
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct StepContext {
pub dt: f32,
pub inv_dt: f32,
pub h: f32,
pub inv_h: f32,
pub sub_step_count: i32,
pub contact_softness: Softness,
pub static_softness: Softness,
pub restitution_threshold: f32,
pub max_linear_velocity: f32,
pub contact_speed: f32,
pub enable_warm_starting: bool,
}