use crate::NodeCollider;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct SceneBodyId(pub(crate) u64);
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum SceneBodyType {
Dynamic,
Fixed,
}
#[derive(Clone, Debug)]
pub struct SceneBodySpec {
pub collider: NodeCollider,
pub position: (f32, f32),
pub velocity: (f32, f32),
pub body_type: SceneBodyType,
pub restitution: f32,
pub gravity_scale: f32,
pub rotation: f32,
pub sprite: Option<String>,
}
impl SceneBodySpec {
pub fn dynamic(collider: NodeCollider, position: (f32, f32)) -> Self {
Self {
collider,
position,
velocity: (0.0, 0.0),
body_type: SceneBodyType::Dynamic,
restitution: 0.3,
gravity_scale: 1.0,
rotation: 0.0,
sprite: None,
}
}
pub fn fixed(collider: NodeCollider, position: (f32, f32)) -> Self {
Self {
body_type: SceneBodyType::Fixed,
..Self::dynamic(collider, position)
}
}
pub fn velocity(mut self, velocity: (f32, f32)) -> Self {
self.velocity = velocity;
self
}
pub fn restitution(mut self, restitution: f32) -> Self {
self.restitution = restitution;
self
}
pub fn gravity_scale(mut self, gravity_scale: f32) -> Self {
self.gravity_scale = gravity_scale;
self
}
pub fn rotation(mut self, rotation: f32) -> Self {
self.rotation = rotation;
self
}
pub fn sprite(mut self, handle: impl Into<String>) -> Self {
self.sprite = Some(handle.into());
self
}
}
#[derive(Clone, Copy, Debug)]
pub enum SceneJoint {
Fixed {
anchor_a: (f32, f32),
anchor_b: (f32, f32),
},
Revolute {
anchor_a: (f32, f32),
anchor_b: (f32, f32),
motor: Option<JointMotorSpec>,
},
Rope {
anchor_a: (f32, f32),
anchor_b: (f32, f32),
length: f32,
},
Spring {
anchor_a: (f32, f32),
anchor_b: (f32, f32),
rest_length: f32,
stiffness: f32,
damping: f32,
},
}
#[derive(Clone, Copy, Debug)]
pub struct JointMotorSpec {
pub target_vel: f32,
pub factor: f32,
}
#[derive(Clone, Copy, Debug)]
pub struct SceneJointSpec {
pub body_a: usize,
pub body_b: usize,
pub joint: SceneJoint,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub enum SceneField {
Vortex {
center: (f32, f32),
strength: f32,
inward: f32,
},
}
#[derive(Clone, Debug)]
pub struct SceneEmitter {
pub collider: NodeCollider,
pub position: (f32, f32),
pub position_jitter: (f32, f32),
pub velocity: (f32, f32),
pub velocity_jitter: (f32, f32),
pub rate_per_sec: f32,
pub lifetime_secs: f32,
pub max_alive: usize,
}
#[derive(Clone, Debug)]
pub struct SceneSpec {
pub bodies: Vec<SceneBodySpec>,
pub gravity: (f32, f32),
pub default_tangible: bool,
pub perpetual: bool,
pub joints: Vec<SceneJointSpec>,
}