From dcfbee8de1c6c38e80bb660eb0b4f721e209d6b3 Mon Sep 17 00:00:00 2001 From: Quaternions Date: Sun, 10 Sep 2023 13:24:47 -0700 Subject: [PATCH] MouseInterpolationState --- src/body.rs | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/body.rs b/src/body.rs index c0fe94ed..f80726e3 100644 --- a/src/body.rs +++ b/src/body.rs @@ -29,12 +29,56 @@ pub enum MoveRestriction { Ladder,//multiple ladders how } +enum MouseInterpolation { + First,//just checks the last value + Lerp,//lerps between +} + +enum InputInstruction { + MoveMouse(glam::IVec2), + Jump(bool), +} + +pub struct MouseInterpolationState { + interpolation: MouseInterpolation, + time0: TIME, + time1: TIME, + mouse0: glam::IVec2, + mouse1: glam::IVec2, +} + +impl MouseInterpolationState { + pub fn move_mouse(&mut self,time:TIME,pos:glam::IVec2){ + self.time0=self.time1; + self.mouse0=self.mouse1; + self.time1=time; + self.mouse1=pos; + } + pub fn interpolated_position(&self,time:TIME) -> glam::IVec2 { + match self.interpolation { + MouseInterpolation::First => self.mouse0, + MouseInterpolation::Lerp => { + let m0=self.mouse0.as_i64vec2(); + let m1=self.mouse1.as_i64vec2(); + //these are deltas + let t1t=(self.time1-time) as i64; + let tt0=(time-self.time0) as i64; + let dt=(self.time1-self.time0) as i64; + ((m0*t1t+m1*tt0)/dt).as_ivec2() + } + } + } +} + pub struct PhysicsState { pub body: Body, pub contacts: Vec, //temp pub models_cringe_clone: Vec, pub temp_control_dir: glam::Vec3, + //camera must exist in state because wormholes modify the camera, also camera punch + //pub camera: Camera, + //pub mouse_interpolation: MouseInterpolationState, pub time: TIME, pub strafe_tick_num: TIME, pub strafe_tick_den: TIME,