diff --git a/engine/physics/src/push_solve.rs b/engine/physics/src/push_solve.rs index a40eaa8..5b1c5a7 100644 --- a/engine/physics/src/push_solve.rs +++ b/engine/physics/src/push_solve.rs @@ -1,4 +1,6 @@ -use strafesnet_common::integer::{self,vec3::{self,Vector3},Fixed,Planar64,Planar64Vec3,Ratio}; +use strafesnet_common::integer::vec3::{self,Vector3}; +use strafesnet_common::integer::{Fixed,Planar64Vec3,Ratio}; +use strafesnet_common::ray::Ray; // This algorithm is based on Lua code // written by Trey Reynolds in 2021 @@ -12,24 +14,6 @@ type Conts<'a>=arrayvec::ArrayVec<&'a Contact,4>; // hack to allow comparing ratios to zero const RATIO_ZERO:Ratio<Fixed<1,32>,Fixed<1,32>>=Ratio::new(Fixed::ZERO,Fixed::EPSILON); -struct Ray{ - origin:Planar64Vec3, - direction:Planar64Vec3, -} -impl Ray{ - fn extrapolate<Num,Den,N1,T1>(&self,t:Ratio<Num,Den>)->Planar64Vec3 - where - Num:Copy, - Den:Copy, - Num:core::ops::Mul<Planar64,Output=N1>, - Planar64:core::ops::Mul<Den,Output=N1>, - N1:integer::Divide<Den,Output=T1>, - T1:integer::Fix<Planar64>, - { - self.origin+self.direction.map(|elem|(t*elem).divide().fix()) - } -} - /// Information about a contact restriction pub struct Contact{ pub position:Planar64Vec3, diff --git a/lib/common/src/lib.rs b/lib/common/src/lib.rs index 69a3501..e6364ba 100644 --- a/lib/common/src/lib.rs +++ b/lib/common/src/lib.rs @@ -1,5 +1,6 @@ pub mod bvh; pub mod map; +pub mod ray; pub mod run; pub mod aabb; pub mod model; diff --git a/lib/common/src/ray.rs b/lib/common/src/ray.rs new file mode 100644 index 0000000..fe16127 --- /dev/null +++ b/lib/common/src/ray.rs @@ -0,0 +1,20 @@ +use ratio_ops::ratio::Ratio; +use crate::integer::{self,Planar64,Planar64Vec3}; + +pub struct Ray{ + pub origin:Planar64Vec3, + pub direction:Planar64Vec3, +} +impl Ray{ + pub fn extrapolate<Num,Den,N1,T1>(&self,t:Ratio<Num,Den>)->Planar64Vec3 + where + Num:Copy, + Den:Copy, + Num:core::ops::Mul<Planar64,Output=N1>, + Planar64:core::ops::Mul<Den,Output=N1>, + N1:integer::Divide<Den,Output=T1>, + T1:integer::Fix<Planar64>, + { + self.origin+self.direction.map(|elem|(t*elem).divide().fix()) + } +}