diff --git a/src/physics.rs b/src/physics.rs index 798edb1..b833bc2 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -836,6 +836,45 @@ impl Body{ let dt=time-self.time; self.velocity+(self.acceleration*dt).map(|elem|elem.divide().fix_1()) } + pub fn extrapolated_position_ratio_dt(&self,dt:integer::Ratio)->Planar64Vec3 + where + // Why? + // All of this can be removed with const generics because the type can be specified as + // Ratio,Fixed> + // which is known to implement all the necessary traits + Num:Copy, + Den:Copy+core::ops::Mul, + D1:Copy, + Num:core::ops::Mul, + Planar64:core::ops::Mul, + N1:core::ops::Add, + Num:core::ops::Mul, + Den:core::ops::Mul, + D2:Copy, + Planar64:core::ops::Mul, + N4:core::ops::Add, + N6:integer::Divide, + T1:integer::Fix, + { + // a*dt^2/2 + v*dt + p + // (a*dt/2+v)*dt+p + ((self.acceleration.map(|elem|dt*elem/2)+self.velocity).map(|elem|dt.mul_ratio(elem))+self.position) + .map(|elem|elem.divide().fix()) + } + pub fn extrapolated_velocity_ratio_dt(&self,dt:integer::Ratio)->Planar64Vec3 + where + Num:Copy, + Den:Copy, + Num:core::ops::Mul, + Planar64:core::ops::Mul, + N1:core::ops::Add, + N3:integer::Divide, + T1:integer::Fix, + { + // a*dt + v + (self.acceleration.map(|elem|dt*elem)+self.velocity) + .map(|elem|elem.divide().fix()) + } pub fn advance_time(&mut self,time:Time){ self.position=self.extrapolated_position(time); self.velocity=self.extrapolated_velocity(time); @@ -858,21 +897,21 @@ impl Body{ //v+a*t==0 //goober code if !self.acceleration.x.is_zero(){ - let t=Time::from(-(self.velocity.x/self.acceleration.x).divide().fix_1()); - if t0