aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-runtime/src/weapon_pose.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/fparkan-runtime/src/weapon_pose.rs')
-rw-r--r--crates/fparkan-runtime/src/weapon_pose.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/crates/fparkan-runtime/src/weapon_pose.rs b/crates/fparkan-runtime/src/weapon_pose.rs
index f5f7758e..9da98bee 100644
--- a/crates/fparkan-runtime/src/weapon_pose.rs
+++ b/crates/fparkan-runtime/src/weapon_pose.rs
@@ -37,6 +37,7 @@ pub(super) struct WeaponPoses {
states: Vec<ControlInstanceState>,
hierarchies: Vec<Option<NodePoseBuffer>>,
aims: Vec<Option<TurretAim>>,
+ pub(super) mounted_radius: f32,
}
impl WeaponPoses {
@@ -69,6 +70,7 @@ impl WeaponPoses {
states: vec![ControlInstanceState::default(); visuals.len()],
hierarchies: vec![None; visuals.len()],
aims: vec![None; visuals.len()],
+ mounted_radius: 0.0,
}
}
@@ -81,6 +83,7 @@ impl WeaponPoses {
hull_local_target: Option<[f32; 3]>,
report: &mut WeaponPoseReport,
) {
+ self.mounted_radius = 0.0;
for (component, &visual) in assets.visuals_for_object(index).iter().enumerate() {
let model = assets
.visual_by_id(visual)
@@ -132,9 +135,32 @@ impl WeaponPoses {
.as_ref()
.and_then(|times| node38_sampled_hierarchy_at_times(&model.validated, times))
.or_else(|| node38_fallback_hierarchy(&model.validated));
+ if let Some(center) =
+ self.model_point_on_hull(component, model.validated.bounding_sphere_center)
+ {
+ let distance = center[0].hypot(center[1]).hypot(center[2]);
+ self.mounted_radius = self
+ .mounted_radius
+ .max(distance + model.validated.bounding_sphere_radius);
+ }
}
}
+ pub(super) fn model_point_on_hull(
+ &self,
+ component: usize,
+ point: [f32; 3],
+ ) -> Option<[f32; 3]> {
+ let Mount::Socket(parent, socket) = *self.mounts.get(component)? else {
+ return None;
+ };
+ mounted_point(&self.hierarchies, &self.mounts, parent, socket, point)
+ }
+
+ pub(super) fn model_hierarchy(&self, component: usize) -> Option<&NodePoseBuffer> {
+ self.hierarchies.get(component)?.as_ref()
+ }
+
fn aim_at(&self, component: usize, target: [f32; 3]) -> Option<TurretAim> {
let local = match *self.mounts.get(component)? {
Mount::Root => target,
@@ -350,6 +376,7 @@ mod tests {
fn cpt_scale_and_world_transform_match_control_dll_query() {
// GOG Control.dll RVA 0x1b4f0, native execution with a supplied node matrix.
let poses = WeaponPoses {
+ mounted_radius: 0.0,
mounts: vec![Mount::Root],
states: vec![],
aims: vec![],