use crate::core::collisions::CollisionType;
use crate::core::ComputeShaderType;
#[derive(Clone, Debug, Copy)]
pub struct Physics {
pub compute_shader: ComputeShaderType,
pub collision_type: CollisionType,
pub mass: f32, pub bounciness: f32, pub friction: f32, pub gravity_scale: f32, pub linear_velocity: [f32; 3],
pub angular_velocity: [f32; 3],
}
impl Default for Physics {
fn default() -> Self {
Self {
compute_shader: ComputeShaderType::FullPhysics,
collision_type: CollisionType::Box,
mass: 1.0,
bounciness: 0.3,
friction: 0.5,
gravity_scale: 1.0,
linear_velocity: [0.0; 3],
angular_velocity: [0.0; 3],
}
}
}
impl Physics {
#[must_use]
pub fn bounciness(mut self, val: f32) -> Self {
self.bounciness = val.clamp(0.0, 1.0);
self
}
#[must_use]
pub fn friction(mut self, val: f32) -> Self {
self.friction = val;
self
}
#[must_use]
pub fn gravity_scale(mut self, val: f32) -> Self {
self.gravity_scale = val;
self
}
#[must_use]
pub fn angular_velocity(mut self, val: [f32; 3]) -> Self {
self.angular_velocity = val;
self
}
#[must_use]
pub fn linear_velocity(mut self, v: [f32; 3]) -> Self {
self.linear_velocity = v;
self
}
#[must_use]
pub fn mass(mut self, m: f32) -> Self {
self.mass = m;
self
}
#[must_use]
pub fn collision_type(mut self, c: CollisionType) -> Self {
self.collision_type = c;
self
}
#[must_use]
pub fn compute_shader(mut self, c: ComputeShaderType) -> Self {
self.compute_shader = c;
self
}
}