diff --git a/src/graphics.rs b/src/graphics.rs index 6f5f71e3..2af48163 100644 --- a/src/graphics.rs +++ b/src/graphics.rs @@ -75,7 +75,7 @@ impl GraphicsCamera{ glam::Mat4::from_translation(pos)*glam::Mat4::from_euler(glam::EulerRot::YXZ,angles.x,angles.y,0f32) } - pub fn to_uniform_data(&self,(pos,angles):(glam::Vec3,glam::Vec2))->[f32; 16 * 4]{ + pub fn to_uniform_data(&self,pos:glam::Vec3,angles:glam::Vec2)->[f32;16*4]{ let proj=self.proj(); let proj_inv=proj.inverse(); let view_inv=self.world(pos,angles); @@ -99,9 +99,9 @@ impl std::default::Default for GraphicsCamera{ } pub struct FrameState{ - pub physics_output:crate::physics::PhysicsOutputState, - pub predicted_time:integer::Time, - pub mouse_pos:glam::IVec2, + pub body:crate::physics::Body, + pub camera:crate::physics::PhysicsCamera, + pub time:integer::Time, } pub struct GraphicsState{ @@ -814,7 +814,7 @@ impl GraphicsState{ }); let camera=GraphicsCamera::default(); - let camera_uniforms=camera.to_uniform_data(crate::physics::PhysicsOutputState::default().extrapolate(strafesnet_common::mouse::MouseState::default())); + let camera_uniforms=camera.to_uniform_data(glam::Vec3::ZERO,glam::Vec2::ZERO); let camera_buf=device.create_buffer_init(&wgpu::util::BufferInitDescriptor{ label:Some("Camera"), contents:bytemuck::cast_slice(&camera_uniforms), @@ -889,7 +889,10 @@ impl GraphicsState{ let mut encoder=device.create_command_encoder(&wgpu::CommandEncoderDescriptor{label:None}); // update rotation - let camera_uniforms=self.camera.to_uniform_data(frame_state.physics_output.extrapolate(strafesnet_common::mouse::MouseState{pos:frame_state.mouse_pos,time:frame_state.predicted_time})); + let camera_uniforms=self.camera.to_uniform_data( + frame_state.body.extrapolated_position(frame_state.time).into(), + frame_state.camera.simulate_move_angles(glam::IVec2::ZERO) + ); self.staging_belt .write_buffer( &mut encoder, diff --git a/src/physics.rs b/src/physics.rs index a3822082..4a78d37d 100644 --- a/src/physics.rs +++ b/src/physics.rs @@ -613,19 +613,6 @@ impl MoveState{ } } -#[derive(Clone,Default)] -pub struct PhysicsOutputState{ - body:Body, - camera:PhysicsCamera, - camera_offset:Planar64Vec3, - mouse_pos:glam::IVec2, -} -impl PhysicsOutputState{ - pub fn extrapolate(&self,mouse:MouseState)->(glam::Vec3,glam::Vec2){ - ((self.body.extrapolated_position(mouse.time)+self.camera_offset).into(),self.camera.simulate_move_angles(mouse.pos-self.mouse_pos)) - } -} - #[derive(Clone,Hash,Eq,PartialEq)] enum PhysicsCollisionAttributes{ Contact(gameplay_attributes::ContactAttributes), @@ -1047,14 +1034,15 @@ impl instruction::InstructionEmitter for PhysicsCont } } impl PhysicsContext{ - pub const fn output(&self)->PhysicsOutputState{ - PhysicsOutputState{ - body:self.state.body, - camera:self.state.camera, - camera_offset:self.state.style.camera_offset, - mouse_pos:self.state.input_state.mouse.pos, + pub fn camera_body(&self)->Body{ + Body{ + position:self.state.body.position+self.state.style.camera_offset, + ..self.state.body } } + pub const fn camera(&self)->PhysicsCamera{ + self.state.camera + } pub const fn get_next_mouse(&self)->&MouseState{ self.state.input_state.get_next_mouse() } diff --git a/src/physics_worker.rs b/src/physics_worker.rs index 9116daf9..7744ffa5 100644 --- a/src/physics_worker.rs +++ b/src/physics_worker.rs @@ -182,9 +182,9 @@ impl MouseInterpolator{ } pub fn get_frame_state(&self,time:Time)->crate::graphics::FrameState{ crate::graphics::FrameState{ - physics_output:self.physics.output(), - mouse_pos:self.physics.get_next_mouse().pos, - predicted_time:self.timer.time(time), + body:self.physics.camera_body(), + camera:self.physics.camera(), + time:self.timer.time(time), } } pub fn change_map(&mut self,time:Time,map:&strafesnet_common::map::CompleteMap){