From 792c3860089612aa398a8dc2cadec5dcf28c85d7 Mon Sep 17 00:00:00 2001 From: Quaternions <krakow20@gmail.com> Date: Thu, 20 Feb 2025 09:30:23 -0800 Subject: [PATCH] last ray hit --- engine/physics/src/physics.rs | 3 ++- engine/session/src/session.rs | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/engine/physics/src/physics.rs b/engine/physics/src/physics.rs index 0748db6..9383508 100644 --- a/engine/physics/src/physics.rs +++ b/engine/physics/src/physics.rs @@ -281,7 +281,8 @@ impl PhysicsCamera{ .clamp(Self::ANGLE_PITCH_LOWER_LIMIT,Self::ANGLE_PITCH_UPPER_LIMIT); mat3::from_rotation_yx(ax,ay) } - fn rotation(&self)->Planar64Mat3{ + #[inline] + pub fn rotation(&self)->Planar64Mat3{ self.get_rotation(self.clamped_mouse_pos) } fn simulate_move_rotation(&self,mouse_delta:glam::IVec2)->Planar64Mat3{ diff --git a/engine/session/src/session.rs b/engine/session/src/session.rs index e7959b3..55bf47b 100644 --- a/engine/session/src/session.rs +++ b/engine/session/src/session.rs @@ -161,6 +161,7 @@ pub struct Session{ recording:Recording, //players:HashMap<PlayerId,Simulation>, replays:HashMap<BotId,Replay>, + last_ray_hit:Option<strafesnet_common::model::ModelId>, } impl Session{ pub fn new( @@ -177,6 +178,7 @@ impl Session{ view_state:ViewState::Play, recording:Default::default(), replays:HashMap::new(), + last_ray_hit:None, } } fn clear_recording(&mut self){ @@ -194,6 +196,19 @@ impl Session{ ), } } + pub fn debug_raycast_print_model_id_if_changed(&mut self,time:SessionTime){ + if let Some(frame_state)=self.get_frame_state(time){ + let ray=strafesnet_common::ray::Ray{ + origin:frame_state.body.extrapolated_position(self.simulation.timer.time(time)), + direction:-frame_state.camera.rotation().z_axis, + }; + let model_id=self.geometry_shared.trace_ray(ray); + if model_id!=self.last_ray_hit{ + println!("hit={model_id:?}"); + self.last_ray_hit=model_id; + } + } + } pub fn user_settings(&self)->&UserSettings{ &self.user_settings }