diff options
| author | Valentin Popov <valentin@popov.link> | 2026-11-26 21:29:37 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-11-26 21:29:37 +0300 |
| commit | 2259ef230be7940a2bd64846e5d3001fa14a772c (patch) | |
| tree | cb4e6b7f0e0c81613f33b73dd824aeb63ad5b808 /apps/fparkan-game/src | |
| parent | d8166352578d9305f15c9fb1ea9d686f4640d970 (diff) | |
| download | fparkan-2259ef230be7940a2bd64846e5d3001fa14a772c.tar.xz fparkan-2259ef230be7940a2bd64846e5d3001fa14a772c.zip | |
fix(combat): keep shots aligned with the sights during free look
Preserve the turret aim before applying cockpit look offsets. On a stock Firing Range start the view turns under Shift while the cannon keeps the same projectile heading. The Constructor camera regression checks the same separation with a pitched turret.
Control and Ngi32 confirm the CPT direction transform. The original choice of world matrix for the barrel remains open.
Diffstat (limited to 'apps/fparkan-game/src')
| -rw-r--r-- | apps/fparkan-game/src/main.rs | 16 | ||||
| -rw-r--r-- | apps/fparkan-game/src/player_fire.rs | 7 |
2 files changed, 16 insertions, 7 deletions
diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs index 6a136a52..0d7601c0 100644 --- a/apps/fparkan-game/src/main.rs +++ b/apps/fparkan-game/src/main.rs @@ -9930,6 +9930,7 @@ struct StaticVulkanApp { world_range_index_counts: HashMap<usize, u32>, camera: VulkanStaticCamera, view_camera: PreviewCameraFrame, + player_aim_direction: Option<[f32; 3]>, captured_viewport: Option<CapturedViewport>, free_camera: Option<FreeFlightCamera>, environment: Option<DynamicEnvironment>, @@ -10096,6 +10097,7 @@ impl StaticVulkanApp { world_range_index_counts, camera: preview.camera, view_camera: preview.view_camera, + player_aim_direction: None, captured_viewport: preview.captured_viewport, free_camera: preview.free_camera, environment, @@ -10408,6 +10410,7 @@ impl StaticVulkanApp { viewport: [f32; 2], ) -> Result<(), String> { self.cockpit_geometry.clear(); + self.player_aim_direction = None; if let (Some(demo), Some(frame)) = (&mut self.demo_camera, &self.mission_frame) { let mode_and_camera = match demo.sample(self.simulation_time_ms, &frame.snapshot, &self.terrain)? { @@ -10499,7 +10502,7 @@ impl StaticVulkanApp { translation[2] += fparkan_runtime::player_walk_camera_lift(engine, cockpit); } let [view_yaw, view_pitch] = frame.player_view_offset_bits.map(f32::from_bits); - let camera = fparkan_render::forward_cockpit_camera( + let sights = fparkan_render::forward_cockpit_camera( LegacyIron3dEulerTransform { translation, orientation_radians: state.orientation.map(f32::from_bits), @@ -10507,9 +10510,11 @@ impl StaticVulkanApp { state.scale.map(f32::from_bits), point, )? - .with_cockpit_pitch(f32::from_bits(frame.player_pitch_bits))? - .with_cockpit_yaw(view_yaw)? - .with_cockpit_pitch(view_pitch)?; + .with_cockpit_pitch(f32::from_bits(frame.player_pitch_bits))?; + let sights_view = sights.try_direct3d7_view_row_major()?; + let camera = sights + .with_cockpit_yaw(view_yaw)? + .with_cockpit_pitch(view_pitch)?; let viewport = [0, 0, viewport[0] as i32, viewport[1] as i32]; let frame = PreviewCameraFrame::from_legacy_d3d7( camera, @@ -10521,6 +10526,7 @@ impl StaticVulkanApp { }, )?; self.cockpit_geometry.select(cockpit, camera); + self.player_aim_direction = Some([sights_view[2], sights_view[6], sights_view[10]]); Some(frame) } @@ -15992,6 +15998,7 @@ mod tests { app.update_mission_camera(0.016, [800.0, 600.0]).unwrap(); assert_eq!(app.view_camera.position, moved); let sights_forward = app.view_camera.forward; + assert_eq!(app.player_aim_direction, Some(sights_forward)); let turned = plan_player_motion( &engine, cockpit, @@ -16009,6 +16016,7 @@ mod tests { app.update_mission_camera(0.016, [800.0, 600.0]).unwrap(); assert_eq!(app.view_camera.position, moved); assert_ne!(app.view_camera.forward, sights_forward); + assert_eq!(app.player_aim_direction, Some(sights_forward)); let released = plan_player_motion(&engine, cockpit, PlayerMotion::default()) .unwrap() diff --git a/apps/fparkan-game/src/player_fire.rs b/apps/fparkan-game/src/player_fire.rs index b1be6551..719c6d3b 100644 --- a/apps/fparkan-game/src/player_fire.rs +++ b/apps/fparkan-game/src/player_fire.rs @@ -73,9 +73,10 @@ impl StaticVulkanApp { orientation_radians: state.orientation.map(f32::from_bits), }; let scale = state.scale.map(f32::from_bits); - // shortcut: the camera supplies a shared aim direction until native - // per-weapon CPT direction and turret alignment agree in world space. - let direction = self.view_camera.forward; + // shortcut: use the turret sights until the native barrel matrix is resolved. + let Some(direction) = self.player_aim_direction else { + return; + }; for (slot, barrel) in shots { let weapon = &weapons.weapons()[slot]; let hierarchy = self |
