label TIMESTAMP
This commit is contained in:
parent
6262553c02
commit
4e83bee60f
11
src/body.rs
11
src/body.rs
@ -1,7 +1,7 @@
|
||||
pub struct Body {
|
||||
pub position: glam::Vec3,//I64 where 2^32 = 1 u
|
||||
pub velocity: glam::Vec3,//I64 where 2^32 = 1 u/s
|
||||
pub time: i64,//nanoseconds x xxxxD!
|
||||
pub time: TIMESTAMP,//nanoseconds x xxxxD!
|
||||
}
|
||||
|
||||
pub struct PhysicsState {
|
||||
@ -14,9 +14,12 @@ pub struct PhysicsState {
|
||||
pub grounded: bool,
|
||||
pub walkspeed: f32,
|
||||
}
|
||||
|
||||
pub type TIMESTAMP = i64;
|
||||
|
||||
const CONTROL_JUMP:u32 = 0b01000000;//temp
|
||||
impl PhysicsState {
|
||||
pub fn run(&mut self, time: i64, control_dir: glam::Vec3, controls: u32){
|
||||
pub fn run(&mut self, time: TIMESTAMP, control_dir: glam::Vec3, controls: u32){
|
||||
let target_tick = (time/10_000_000) as u32;//100t
|
||||
//the game code can run for 1 month before running out of ticks
|
||||
for tick in self.tick+1..=target_tick {
|
||||
@ -49,10 +52,10 @@ impl PhysicsState {
|
||||
}
|
||||
self.tick=target_tick;
|
||||
|
||||
self.body.time=target_tick as i64*10_000_000;
|
||||
self.body.time=target_tick as TIMESTAMP*10_000_000;
|
||||
}
|
||||
|
||||
pub fn extrapolate_position(&self, time: i64) -> glam::Vec3 {
|
||||
pub fn extrapolate_position(&self, time: TIMESTAMP) -> glam::Vec3 {
|
||||
let dt=(time-self.body.time) as f64/1_000_000_000f64;
|
||||
self.body.position+self.body.velocity*(dt as f32)+self.gravity*((0.5*dt*dt) as f32)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user