use crate::physics::Cartesian; pub struct PhysBody { pub pos: Cartesian, pub vel: Cartesian, pub mass: f64, pub angle: f64, // In degrees } impl PhysBody { pub fn new(pos: Cartesian) -> Self { return PhysBody { pos, vel: Cartesian::new(0.0, 0.0), mass: 0.3, angle: 0.0, }; } /// Calculate the state of this body after t seconds. pub fn tick(&mut self, t: f64) { self.pos += self.vel * t; } /// Apply an instantaneous force to this object pub fn force(&mut self, v: Cartesian) { self.vel += v / self.mass; } /// Apply force in the direction this object is pointing. pub fn thrust(&mut self, f: f64) { let l = Cartesian::new( -self.angle.to_radians().sin(), self.angle.to_radians().cos(), ) * f; self.force(l); } // Rotate this object by `a` radians. pub fn rot(&mut self, a: f64) { self.angle -= a; if self.angle.abs() > 180.0 { self.angle -= self.angle.signum() * 360.0; } } }