From fd159dbfa3e0ae399658a2cbea305d0a35debf77 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 22:23:02 +0400 Subject: fix(ui): match cockpit miniature camera fitting --- apps/fparkan-game/src/cockpit_instrument.rs | 22 ++++++++++------------ apps/fparkan-game/src/mission_overlay.rs | 1 + 2 files changed, 11 insertions(+), 12 deletions(-) (limited to 'apps') diff --git a/apps/fparkan-game/src/cockpit_instrument.rs b/apps/fparkan-game/src/cockpit_instrument.rs index 9665afda..2130e6c3 100644 --- a/apps/fparkan-game/src/cockpit_instrument.rs +++ b/apps/fparkan-game/src/cockpit_instrument.rs @@ -12,6 +12,7 @@ use super::{ use fparkan_assets::cockpit_instrument::{Images, Readout, Side}; use fparkan_platform_winit::text::StringResources; use fparkan_render::cockpit_lighting::{lamps, LIGHTING_FLOOR}; +use fparkan_render::cockpit_projection::fit_sphere; use fparkan_render_vulkan::{ project_instrument_msh, VulkanDirectionalLight, VulkanModelPreview, VULKAN_DIRECTIONAL_LIGHT_COUNT, @@ -220,6 +221,7 @@ impl CockpitInstrument { renderer: &mut VulkanSmokeRenderer, live: Option<(&Engine, StartingCockpit, &WorldSnapshot)>, selected: Option, + scene_planes: [f32; 2], mut live_models: LiveModels<'_>, ) -> Result<[Option; 2], String> { if !self.initialized { @@ -285,6 +287,7 @@ impl CockpitInstrument { radius, forward, orientation_radians, + scene_planes, ) })(); if views[index].is_some() { @@ -441,17 +444,12 @@ impl Model { radius: f32, forward: [f32; 3], orientation_radians: [f32; 3], + scene_planes: [f32; 2], ) -> Option { - let near = 0.5; - let far = 300.0; - if self.ranges.is_empty() - || radius <= 0.0 - || !radius.is_finite() - || radius * 2.0 >= far - near - { + if self.ranges.is_empty() { return None; } - let distance = (2.0 * radius).clamp(near + radius, far - radius); + let (distance, fov) = fit_sphere(radius, scene_planes)?; let eye = sub3(center, scale3(forward, distance)); let right = normalize3(cross3(forward, [0.0, 0.0, 1.0])).unwrap_or([1.0, 0.0, 0.0]); let up = cross3(right, forward); @@ -462,9 +460,9 @@ impl Model { right_edge / 640.0, bottom / 480.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(); + // The Terrain camera applied at iron3d+0x42117 has its own clip planes. + let near = 0.5; + let far = 300.0; let aspect = (right_edge - left) / (bottom - top); let camera = VulkanStaticCamera { clip_from_world: clip_from_world_for_view( @@ -505,7 +503,7 @@ fn targeter_projection_and_lighting_are_shared_by_both_panels() { }; for side in [Side::Left, Side::Right] { let view = model - .view(side, [0.0; 3], 2.0, [0.0, 1.0, 0.0], [0.0; 3]) + .view(side, [0.0; 3], 2.0, [0.0, 1.0, 0.0], [0.0; 3], [0.5, 700.0]) .unwrap(); let matrix = view.camera.clip_from_world; let focal = 1.303_225_4; diff --git a/apps/fparkan-game/src/mission_overlay.rs b/apps/fparkan-game/src/mission_overlay.rs index b93ece81..de334d3b 100644 --- a/apps/fparkan-game/src/mission_overlay.rs +++ b/apps/fparkan-game/src/mission_overlay.rs @@ -490,6 +490,7 @@ impl StaticVulkanApp { renderer, live, self.selected_contact, + [frame.camera.near_plane, frame.camera.far_plane], LiveModels { mesh: &mut self.mesh, poses: &self.component_pose_buffers, -- cgit v1.2.3