use bevy::{
ecs::prelude::Resource,
math::{Vec2, Vec3, Vec3Swizzles},
};
#[derive(Debug, Copy, Clone, Resource)]
pub struct VerletConfig {
pub gravity: Vec3,
pub friction: f32,
pub sticks_computation_depth: u8,
pub parallel_processing: bool,
}
impl Default for VerletConfig {
fn default() -> Self {
Self {
gravity: Vec3::new(0., -9.81, 0.),
friction: 0.01,
sticks_computation_depth: 5,
parallel_processing: true,
}
}
}
impl VerletConfig {
#[must_use]
#[inline]
pub(crate) fn friction_coefficient(&self) -> f32 {
1.0 - self.friction.clamp(0.0, 1.0)
}
#[must_use]
#[inline]
pub fn gravity_2d(&self) -> Vec2 {
self.gravity.xy()
}
}