From f35ccda5dd88cb0ddebed33efa2660c1b9742cbe Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 21:29:10 +0400 Subject: fix(ui): project cockpit miniatures in their layout viewport --- apps/fparkan-game/src/cockpit_instrument.rs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) (limited to 'apps/fparkan-game/src/cockpit_instrument.rs') diff --git a/apps/fparkan-game/src/cockpit_instrument.rs b/apps/fparkan-game/src/cockpit_instrument.rs index 37023fea..400f3a7d 100644 --- a/apps/fparkan-game/src/cockpit_instrument.rs +++ b/apps/fparkan-game/src/cockpit_instrument.rs @@ -156,7 +156,6 @@ impl CockpitInstrument { renderer: &mut VulkanSmokeRenderer, live: Option<(&Engine, StartingCockpit, &WorldSnapshot)>, selected: Option, - drawable: [f32; 2], mut live_models: LiveModels<'_>, ) -> Result<[Option; 2], String> { if !self.initialized { @@ -217,7 +216,7 @@ impl CockpitInstrument { }; self.models .get(unit.object_index)? - .view(panel.side, center, radius, forward, drawable) + .view(panel.side, center, radius, forward) })(); if views[index].is_some() { active[index] = Some(unit.object_index); @@ -370,7 +369,6 @@ impl Model { center: [f32; 3], radius: f32, forward: [f32; 3], - drawable: [f32; 2], ) -> Option { let near = 0.5; let far = 300.0; @@ -392,8 +390,10 @@ impl Model { right_edge / 640.0, bottom / 480.0, ]; - let aspect = super::preview_aspect((drawable[0] / 640.0) / (drawable[1] / 480.0)); - let fov = ((0.6_f32).tan() / aspect).atan() * 2.0; + // The camera applied at iron3d+0x42117 uses a 75-degree field + // of view in the instrument's square layout viewport. + let fov = 75.0_f32.to_radians(); + let aspect = (right_edge - left) / (bottom - top); let camera = VulkanStaticCamera { clip_from_world: clip_from_world_for_view( eye, forward, right, up, fov, near, far, aspect, @@ -416,3 +416,21 @@ impl Model { }) } } + +#[cfg(test)] +#[test] +fn targeter_projection_uses_the_original_focal_scale_on_both_axes() { + let model = Model { + bounds: None, + ranges: 0..1, + counts: Vec::new(), + components: Vec::new(), + }; + for side in [Side::Left, Side::Right] { + let view = model.view(side, [0.0; 3], 2.0, [0.0, 1.0, 0.0]).unwrap(); + let matrix = view.camera.clip_from_world; + let focal = 1.303_225_4; + assert!((matrix[0] - focal).abs() < 1e-6); + assert!((matrix[9] + focal).abs() < 1e-6); + } +} -- cgit v1.2.3