From 1e0128c6de44aa73e446451a27469e9873bc7e93 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Tue, 1 Dec 2026 16:38:57 +0400 Subject: fix(combat): fire autonomous turrets along their barrel and sights Transform the live CPT axis through the weapon sockets and the chassis. Mounted weapons use the same sight convergence as manual shots for compatible profiles. The autonomous ray checks current chassis and mounted geometry. Checked the Control.dll CPT transform and convergence oracle against the Rust path, observed the initial AutoDemo combat in the Vulkan window, and ran the licensed AutoDemo combat test. --- crates/fparkan-runtime/src/weapon_pose.rs | 62 ++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 2 deletions(-) (limited to 'crates/fparkan-runtime/src/weapon_pose.rs') diff --git a/crates/fparkan-runtime/src/weapon_pose.rs b/crates/fparkan-runtime/src/weapon_pose.rs index b7a9f48f..f01a93e1 100644 --- a/crates/fparkan-runtime/src/weapon_pose.rs +++ b/crates/fparkan-runtime/src/weapon_pose.rs @@ -2,7 +2,7 @@ use crate::{ turret_aim::{apply_autonomous_turret_pose, has_turret_aim, TurretAim}, - MissionAssets, MissionObjectDraft, + turret_sight_points, MissionAssets, MissionObjectDraft, }; use fparkan_animation::{AnimationTime, NodePoseBuffer, Pose}; use fparkan_assets::{ @@ -276,6 +276,60 @@ impl WeaponPoses { } .try_transform_scaled_point(point, state.scale.map(f32::from_bits)) } + + pub(super) fn cpt_axis( + &self, + state: TransformState, + component: usize, + point: &PreparedControlPoint, + ) -> Option<[f32; 3]> { + let node = usize::try_from(point.raw_signed_field_04).ok()?; + let to_hull = + |point| mounted_point(&self.hierarchies, &self.mounts, component, node, point); + let origin = to_hull([0.0; 3])?; + let tip = to_hull(point.direction)?; + LegacyIron3dEulerTransform { + translation: [0.0; 3], + orientation_radians: state.orientation.map(f32::from_bits), + } + .try_transform_scaled_point( + std::array::from_fn(|axis| tip[axis] - origin[axis]), + state.scale.map(f32::from_bits), + ) + .filter(|axis| *axis != [0.0; 3]) + } + + pub(super) fn turret_sight_component(&self, mut component: usize) -> Option { + for _ in 0..self.mounts.len() { + if self.aim(component).is_some() { + return Some(component); + } + let Mount::Socket(parent, _) = *self.mounts.get(component)? else { + return None; + }; + component = parent; + } + None + } + + pub(super) fn sight_ray( + &self, + assets: &MissionAssets, + object: usize, + state: TransformState, + component: usize, + ) -> Option<[[f32; 3]; 2]> { + let control = assets + .object_component_controls + .get(object)? + .get(component)? + .as_ref()?; + let [origin, axis] = turret_sight_points(control)?; + Some([ + self.muzzle(state, component, origin)?, + self.cpt_axis(state, component, axis)?, + ]) + } } fn mounted_point( @@ -411,13 +465,17 @@ mod tests { raw_signed_field_04: 0, raw_signed_field_08: 0, position: [1.0, 2.0, 3.0], - direction: [0.0, 1.0, 0.0], + direction: [1.0, 2.0, 3.0], name: [0; 32], }; let actual = poses.muzzle(state, 0, &barrel).unwrap(); for (actual, expected) in actual.into_iter().zip([14.0, 32.0, 52.0]) { assert!((actual - expected).abs() < 0.00001); } + let axis = poses.cpt_axis(state, 0, &barrel).unwrap(); + for (actual, expected) in axis.into_iter().zip([-6.0, 2.0, 12.0]) { + assert!((actual - expected).abs() < 0.00001); + } } #[test] -- cgit v1.2.3