aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/weapon_pose.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 15:38:57 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 15:38:57 +0300
commit1e0128c6de44aa73e446451a27469e9873bc7e93 (patch)
treedd056fd39a9223f11d27b21fca5d600b658bb5c7 /crates/fparkan-runtime/src/weapon_pose.rs
parent2de3fd6567d6eee36910af260f1e5767213ba89c (diff)
downloadfparkan-1e0128c6de44aa73e446451a27469e9873bc7e93.tar.xz
fparkan-1e0128c6de44aa73e446451a27469e9873bc7e93.zip
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.
Diffstat (limited to 'crates/fparkan-runtime/src/weapon_pose.rs')
-rw-r--r--crates/fparkan-runtime/src/weapon_pose.rs62
1 files changed, 60 insertions, 2 deletions
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<usize> {
+ 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]