aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 15:05:28 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 15:05:28 +0300
commit900aa7e51ecf26bc242f7853bdbcad68eb02b31a (patch)
treef5264f54167ac71e604e0a651f4fbec53fde2526 /crates/fparkan-runtime/src
parentf03b144907be8ad8cec2e1c7487b5d9e0a43f13e (diff)
downloadfparkan-900aa7e51ecf26bc242f7853bdbcad68eb02b31a.tar.xz
fparkan-900aa7e51ecf26bc242f7853bdbcad68eb02b31a.zip
fix(combat): aim mounted turrets in their authored axes
Keep the authored root rotation when converting a target from a chassis socket into the animated turret model. AutoDemo no longer turns the medium turret sideways toward a target on level ground. Compared the stock muzzle direction with the recorded GOG Control.dll launch and checked AutoDemo in the Vulkan window, the licensed combat run, and the workspace suite.
Diffstat (limited to 'crates/fparkan-runtime/src')
-rw-r--r--crates/fparkan-runtime/src/turret_aim.rs4
-rw-r--r--crates/fparkan-runtime/src/weapon_pose.rs54
2 files changed, 51 insertions, 7 deletions
diff --git a/crates/fparkan-runtime/src/turret_aim.rs b/crates/fparkan-runtime/src/turret_aim.rs
index 2c9c66e7..d8e145fd 100644
--- a/crates/fparkan-runtime/src/turret_aim.rs
+++ b/crates/fparkan-runtime/src/turret_aim.rs
@@ -9,8 +9,8 @@ use fparkan_render::LegacyIron3dEulerTransform;
/// An autonomous turret's selected direction in its mount's coordinates.
#[derive(Clone, Copy, Debug)]
pub struct TurretAim {
- azimuth: f32,
- elevation: f32,
+ pub(super) azimuth: f32,
+ pub(super) elevation: f32,
}
impl TurretAim {
diff --git a/crates/fparkan-runtime/src/weapon_pose.rs b/crates/fparkan-runtime/src/weapon_pose.rs
index 9da98bee..b7a9f48f 100644
--- a/crates/fparkan-runtime/src/weapon_pose.rs
+++ b/crates/fparkan-runtime/src/weapon_pose.rs
@@ -9,7 +9,9 @@ use fparkan_assets::{
sample_control_node_times, ControlInstanceState, PreparedControlGateProvider,
PreparedControlNodeBinding, PreparedControlPoint,
};
-use fparkan_msh::{node38_fallback_hierarchy, node38_sampled_hierarchy_at_times};
+use fparkan_msh::{
+ node38_fallback_hierarchy, node38_fallback_pose, node38_sampled_hierarchy_at_times, NodeId,
+};
use fparkan_prototype::{unit_component_tree, PROTOTYPE_TYPE_EXTO};
use fparkan_render::LegacyIron3dEulerTransform;
use fparkan_world::TransformState;
@@ -97,7 +99,10 @@ impl WeaponPoses {
.and_then(Option::as_ref);
let aim = control
.filter(|control| has_turret_aim(control))
- .and_then(|_| self.aim_at(component, hull_local_target?));
+ .and_then(|_| {
+ let authored_root = node38_fallback_pose(&model.validated, NodeId(0));
+ self.aim_at(component, hull_local_target?, authored_root)
+ });
self.aims[component] = aim;
let times = control.and_then(|control| {
// Match the renderer's query gates. Recoil still uses the
@@ -161,7 +166,12 @@ impl WeaponPoses {
self.hierarchies.get(component)?.as_ref()
}
- fn aim_at(&self, component: usize, target: [f32; 3]) -> Option<TurretAim> {
+ fn aim_at(
+ &self,
+ component: usize,
+ target: [f32; 3],
+ authored_root: Option<Pose>,
+ ) -> Option<TurretAim> {
let local = match *self.mounts.get(component)? {
Mount::Root => target,
Mount::Unavailable => return None,
@@ -177,11 +187,18 @@ impl WeaponPoses {
.sum(),
)
};
- [
+ let attachment_local = [
project([1.0, 0.0, 0.0])?,
project([0.0, 1.0, 0.0])?,
project([0.0, 0.0, 1.0])?,
- ]
+ ];
+ // The animated hierarchy is drawn after removing its authored
+ // root pose. Undo that removal when aiming in the model's axes.
+ Pose {
+ translation: [0.0; 3],
+ ..authored_root?
+ }
+ .transform_point(attachment_local)
}
};
TurretAim::toward(local)
@@ -404,6 +421,33 @@ mod tests {
}
#[test]
+ fn turret_aim_replaces_the_authored_root_before_measuring_angles() {
+ let half_sqrt = std::f32::consts::FRAC_1_SQRT_2;
+ let authored_root = Pose {
+ rotation: [-half_sqrt, 0.0, 0.0, half_sqrt],
+ ..Pose::default()
+ };
+ let socket = Pose {
+ translation: [0.0, 0.0, 3.0],
+ ..authored_root
+ };
+ let poses = WeaponPoses {
+ mounted_radius: 0.0,
+ mounts: vec![Mount::Root, Mount::Socket(0, 1)],
+ states: vec![],
+ hierarchies: vec![Some(NodePoseBuffer {
+ poses: vec![Pose::default(), socket],
+ })],
+ aims: vec![],
+ };
+ let aim = poses
+ .aim_at(1, [-30.0, 40.0, 3.0], Some(authored_root))
+ .unwrap();
+ assert!((aim.azimuth - 0.75_f32.atan()).abs() < 1e-5);
+ assert!(aim.elevation.abs() < 1e-5);
+ }
+
+ #[test]
fn mounted_muzzle_replaces_child_roots_and_follows_rotated_parent_socket() {
let quarter_turn = [
0.0,