aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-01 23:45:44 +0300
committerValentin Popov <valentin@popov.link>2026-12-01 23:45:44 +0300
commit029297446ec0b235602b4f4d9197786a3466a6fe (patch)
treecf0371e18391f19879999452d11182e98f01a473
parentb3d2b95b8dd5e4578e2889845809fe7c21c5886b (diff)
downloadfparkan-029297446ec0b235602b4f4d9197786a3466a6fe.tar.xz
fparkan-029297446ec0b235602b4f4d9197786a3466a6fe.zip
feat(ui): display cockpit view bearings and aperture
Read the visible cockpit camera to draw the original front and rear markers and field-of-view sector from the installed UI atlases. Check the indicator on a stock Fireline start and a separate Shift look with the weapon aim held.
-rw-r--r--apps/fparkan-game/src/course_hud.rs117
-rw-r--r--apps/fparkan-game/src/main.rs1
-rw-r--r--apps/fparkan-game/src/mission_overlay.rs25
-rw-r--r--crates/fparkan-render/src/cockpit_course.rs108
-rw-r--r--crates/fparkan-render/src/lib.rs1
-rw-r--r--docs/appendices/ui-shell.md19
6 files changed, 270 insertions, 1 deletions
diff --git a/apps/fparkan-game/src/course_hud.rs b/apps/fparkan-game/src/course_hud.rs
new file mode 100644
index 00000000..7e436271
--- /dev/null
+++ b/apps/fparkan-game/src/course_hud.rs
@@ -0,0 +1,117 @@
+use super::{
+ append_environment_gradient_material, append_environment_range, environment_vertex,
+ world_pipeline_state, DirectoryVfs, EnvironmentGpuRange, LegacyBlendMode, LegacyDepthMode,
+ StaticPreviewScene, VulkanSmokeRenderer, VulkanStaticMesh, VulkanStaticTexture,
+ VulkanStaticVertex,
+};
+use fparkan_assets::{ui_sprite::load_ui_page, RgbaImage};
+use fparkan_render::cockpit_course::{bearing_markers, view_sector};
+use std::path::Path;
+
+const MARKER_UVS: [[f32; 2]; 4] = [
+ [192.5 / 256.0, 154.5 / 256.0],
+ [192.5 / 256.0, 165.0 / 256.0],
+ [201.0 / 256.0, 154.5 / 256.0],
+ [201.0 / 256.0, 165.0 / 256.0],
+];
+const FRONT: [f32; 3] = [10.0 / 255.0, 10.0 / 255.0, 225.0 / 255.0];
+const REAR: [f32; 3] = [225.0 / 255.0, 10.0 / 255.0, 10.0 / 255.0];
+
+pub(super) struct CourseHud {
+ sector: EnvironmentGpuRange,
+ markers: EnvironmentGpuRange,
+}
+
+impl CourseHud {
+ pub(super) fn load(root: &Path, preview: &mut StaticPreviewScene) -> Result<Self, String> {
+ let vfs = DirectoryVfs::new(root);
+ let sector_page = load_ui_page(&vfs, "page7")?;
+ let marker_page = load_ui_page(&vfs, "page6")?;
+ if [
+ sector_page.width,
+ sector_page.height,
+ marker_page.width,
+ marker_page.height,
+ ] != [256; 4]
+ {
+ return Err("unexpected native course atlas dimensions".into());
+ }
+ let sector = append_range(preview, sector_page, 3, vec![0, 1, 2])?;
+ let markers = append_range(
+ preview,
+ marker_page,
+ 8,
+ vec![0, 1, 2, 2, 1, 3, 4, 5, 6, 6, 5, 7],
+ )?;
+ Ok(Self { sector, markers })
+ }
+
+ pub(super) fn ranges(&self) -> [usize; 2] {
+ [self.sector.range_index, self.markers.range_index]
+ }
+
+ pub(super) fn draw(
+ &self,
+ renderer: &mut VulkanSmokeRenderer,
+ mesh: &mut VulkanStaticMesh,
+ view: Option<([f32; 2], f32)>,
+ ) -> Result<(), String> {
+ for (range, count) in self.ranges().into_iter().zip([3, 12]) {
+ renderer
+ .set_draw_range_index_count(range, if view.is_some() { count } else { 0 })
+ .map_err(|error| error.to_string())?;
+ }
+ let Some((forward, fov)) = view else {
+ return Ok(());
+ };
+
+ let start = self.sector.vertex_start;
+ mesh.vertices[start..start + 3]
+ .copy_from_slice(&view_sector(fov).map(|(point, uv)| vertex(point, uv, [1.0; 3])));
+ let start = self.markers.vertex_start;
+ for ((corners, color), vertices) in bearing_markers(forward)
+ .into_iter()
+ .zip([FRONT, REAR])
+ .zip(mesh.vertices[start..start + 8].chunks_exact_mut(4))
+ {
+ for ((point, uv), output) in corners.into_iter().zip(MARKER_UVS).zip(vertices) {
+ *output = vertex(point, uv, color);
+ }
+ }
+ Ok(())
+ }
+}
+
+fn vertex([x, y]: [f32; 2], uv: [f32; 2], color: [f32; 3]) -> VulkanStaticVertex {
+ // Scaling the design coordinates and the viewport by the same factors
+ // cancels out when converting the original TL positions to NDC.
+ environment_vertex(
+ [x * (2.0 / 640.0) - 1.0, y * (2.0 / 480.0) - 1.0, 0.999],
+ color,
+ uv,
+ )
+}
+
+fn append_range(
+ preview: &mut StaticPreviewScene,
+ page: RgbaImage,
+ vertex_count: usize,
+ indices: Vec<u32>,
+) -> Result<EnvironmentGpuRange, String> {
+ let material = append_environment_gradient_material(&mut preview.materials)?;
+ preview.materials[material].screen_tl = true;
+ preview.materials[material].sky_far_depth = false;
+ preview.materials[material].texture = VulkanStaticTexture {
+ width: page.width,
+ height: page.height,
+ rgba8: page.rgba8,
+ mip_levels: Vec::new(),
+ };
+ append_environment_range(
+ &mut preview.mesh,
+ material,
+ vec![environment_vertex([0.0; 3], [1.0; 3], [0.0; 2]); vertex_count],
+ indices,
+ world_pipeline_state(LegacyBlendMode::SourceAlpha, LegacyDepthMode::Disabled),
+ )
+}
diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs
index 4e044abe..c226d0da 100644
--- a/apps/fparkan-game/src/main.rs
+++ b/apps/fparkan-game/src/main.rs
@@ -10,6 +10,7 @@ mod chassis_animation;
mod cockpit_geometry;
#[cfg(windows)]
mod control_effects;
+mod course_hud;
#[cfg(test)]
use control_effects::advance_control_effect_instances;
mod damage_visibility;
diff --git a/apps/fparkan-game/src/mission_overlay.rs b/apps/fparkan-game/src/mission_overlay.rs
index a3b37d50..fb669e8d 100644
--- a/apps/fparkan-game/src/mission_overlay.rs
+++ b/apps/fparkan-game/src/mission_overlay.rs
@@ -1,5 +1,6 @@
use super::{
- altimeter_hud::AltimeterHud, satellite_map::SatelliteMap, StaticPreviewScene, StaticVulkanApp,
+ altimeter_hud::AltimeterHud, course_hud::CourseHud, horizontal_fov,
+ satellite_map::SatelliteMap, StaticPreviewScene, StaticVulkanApp,
};
#[cfg(windows)]
use super::{mission_hints::MissionHints, weapon_hud::WeaponHud};
@@ -25,6 +26,7 @@ pub(super) fn source_over(pixel: &mut [u8], source: &[u8]) {
#[derive(Default)]
pub(super) struct MissionOverlay {
pub(super) satellite_map: Option<SatelliteMap>,
+ course: Option<CourseHud>,
altimeter: Option<AltimeterHud>,
#[cfg(windows)]
pub(super) hints: Option<MissionHints>,
@@ -44,6 +46,14 @@ impl MissionOverlay {
return Self::default();
};
// The original draws the cockpit instruments before the satellite map.
+ let course = cockpit.and_then(|_| {
+ CourseHud::load(root, preview)
+ .map(Some)
+ .unwrap_or_else(|error| {
+ eprintln!("course_hud_unavailable reason={error}");
+ None
+ })
+ });
let altimeter = cockpit.and_then(|_| {
AltimeterHud::load(root, preview)
.map(Some)
@@ -75,6 +85,7 @@ impl MissionOverlay {
});
Self {
satellite_map,
+ course,
altimeter,
#[cfg(windows)]
hints,
@@ -102,6 +113,11 @@ impl MissionOverlay {
if let Some(altimeter) = &self.altimeter {
remove(altimeter.range_index(), ranges, counts);
}
+ if let Some(course) = &self.course {
+ for range in course.ranges() {
+ remove(range, ranges, counts);
+ }
+ }
#[cfg(windows)]
if let Some(hints) = &self.hints {
remove(hints.range_index(), ranges, counts);
@@ -134,6 +150,13 @@ impl StaticVulkanApp {
.and_then(|(engine, cockpit)| cockpit_altimeter(engine, cockpit));
altimeter.draw(renderer, &mut self.mesh, frame.viewport, state)?;
}
+ if let Some(course) = &self.overlay.course {
+ let view = self.cockpit.map(|_| {
+ let [x, y, _] = frame.camera.forward();
+ ([x, y], horizontal_fov(&frame.camera, frame.aspect))
+ });
+ course.draw(renderer, &mut self.mesh, view)?;
+ }
#[cfg(windows)]
if let Some(hints) = &mut self.overlay.hints {
let outcome = self
diff --git a/crates/fparkan-render/src/cockpit_course.rs b/crates/fparkan-render/src/cockpit_course.rs
new file mode 100644
index 00000000..974249b0
--- /dev/null
+++ b/crates/fparkan-render/src/cockpit_course.rs
@@ -0,0 +1,108 @@
+//! Camera bearings drawn by the original cockpit instrument at 640×480.
+
+use std::f32::consts::{FRAC_PI_2, PI};
+
+const CENTER: [f32; 2] = [320.0, 396.0];
+const HALF_MARKER_ANGLE: f32 = 0.08726647;
+
+/// Front and rear marker corners in the original triangle-strip order.
+#[must_use]
+pub fn bearing_markers([x, y]: [f32; 2]) -> [[[f32; 2]; 4]; 2] {
+ let front = y.atan2(x) - FRAC_PI_2;
+ [front, front + PI].map(|bearing| {
+ // Unlike the sector, the marker projects sine onto X and cosine onto Y.
+ let left = FRAC_PI_2 - (bearing - HALF_MARKER_ANGLE);
+ let right = FRAC_PI_2 - (bearing + HALF_MARKER_ANGLE);
+ [
+ radial_point(CENTER, left, 68.0),
+ radial_point(CENTER, left, 56.0),
+ radial_point(CENTER, right, 68.0),
+ radial_point(CENTER, right, 56.0),
+ ]
+ })
+}
+
+/// Positions and page7 UVs of the sector that represents the view aperture.
+#[must_use]
+pub fn view_sector(horizontal_fov: f32) -> [([f32; 2], [f32; 2]); 3] {
+ let half = horizontal_fov * 0.5;
+ let edge = |side: f32| {
+ let point = radial_point(CENTER, FRAC_PI_2 + side, 75.0);
+ // The original uses -4.71228 here for the atlas angle.
+ let uv = radial_point([192.0, 64.0], side - 4.71228, 64.0).map(|texel| texel / 256.0);
+ (point, uv)
+ };
+ [edge(-half), (CENTER, [0.75, 0.25]), edge(half)]
+}
+
+fn radial_point([x, y]: [f32; 2], angle: f32, radius: f32) -> [f32; 2] {
+ let (sin, cos) = angle.sin_cos();
+ [x + cos * radius, y - sin * radius]
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn matches_native_rear_marker_and_sector_in_the_stock_cockpit() {
+ // The camera and last presented TL vertices are sampled outside the draw call.
+ let [front, rear] = bearing_markers([0.5369722, -0.4331754]);
+ let expected_rear = [
+ [461.82346, 436.666],
+ [450.91342, 446.96024],
+ [471.0138, 448.28775],
+ [458.482, 456.5311],
+ ];
+ for ((front, rear), native) in front.into_iter().zip(rear).zip(expected_rear) {
+ near(rear.map(|axis| axis * 1.25), native, 1.0);
+ near(
+ [front[0] + rear[0], front[1] + rear[1]],
+ [2.0 * CENTER[0], 2.0 * CENTER[1]],
+ 0.001,
+ );
+ }
+ let native_sector = [
+ ([456.7362, 420.36716], [0.9012749, 0.050962552]),
+ ([400.0, 495.00006], [0.75, 0.25]),
+ ([343.2638, 420.36716], [0.5986816, 0.05099559]),
+ ];
+ for ((point, uv), (native_point, native_uv)) in
+ view_sector(1.3).into_iter().zip(native_sector)
+ {
+ near(point.map(|axis| axis * 1.25), native_point, 0.001);
+ near(uv, native_uv, 0.000001);
+ }
+ }
+
+ #[test]
+ fn front_marker_follows_quadrant_and_ignores_view_pitch() {
+ for (forward, expected) in [
+ ([1.0, 0.0], [252.25876, 396.0]),
+ ([0.0, 1.0], [320.0, 328.25876]),
+ ([-1.0, 0.0], [387.74124, 396.0]),
+ ([0.0, -1.0], [320.0, 463.74124]),
+ ] {
+ let [front, _] = bearing_markers(forward);
+ let midpoint = [
+ (front[0][0] + front[2][0]) * 0.5,
+ (front[0][1] + front[2][1]) * 0.5,
+ ];
+ near(midpoint, expected, 0.001);
+ assert_eq!(
+ bearing_markers(forward.map(|axis| axis * 0.5)),
+ bearing_markers(forward)
+ );
+ }
+ }
+
+ fn near(actual: [f32; 2], expected: [f32; 2], tolerance: f32) {
+ assert!(
+ actual
+ .into_iter()
+ .zip(expected)
+ .all(|(a, b)| (a - b).abs() < tolerance),
+ "{actual:?} vs {expected:?}"
+ );
+ }
+}
diff --git a/crates/fparkan-render/src/lib.rs b/crates/fparkan-render/src/lib.rs
index 49954f3e..b684b787 100644
--- a/crates/fparkan-render/src/lib.rs
+++ b/crates/fparkan-render/src/lib.rs
@@ -1,6 +1,7 @@
#![forbid(unsafe_code)]
//! Camera mathematics and graphics pipeline state.
+pub mod cockpit_course;
pub mod water;
/// A 64-byte transform block returned by the original Terrain camera ABI.
diff --git a/docs/appendices/ui-shell.md b/docs/appendices/ui-shell.md
index 8860cbc9..91cfa123 100644
--- a/docs/appendices/ui-shell.md
+++ b/docs/appendices/ui-shell.md
@@ -272,6 +272,25 @@ Control. Оружейный цикл в `Control.dll` по RVA `0x29ca0` разÐ
край. Число использует `GAME_FONT`, пиктограмма берётся из `ui_menu3`.
[Хеш сборки Terrain.dll](../reference/original-binaries.md).
+## Указатели направления в кабине
+
+Синяя и красная метки у центра прибора показывают переднее и заднее
+направления обзора. `iron3d.dll` по RVA `0x40213` читает горизонтальные
+компоненты первого столбца мировой матрицы камеры. Поэтому поворот вида
+сдвигает обе метки, а обычное изменение наклона камеры сохраняет азимут.
+
+В координатах 640×480 центр прибора находится в точке `(320, 396)`.
+Синяя метка расположена под углом `atan2(y, x) − π/2` от центра, красная
+на противоположной стороне. По углам `α` на ±5° от её направления и
+радиусам `r` в 56 и 68 вычисляются смещения `(r sin α, −r cos α)`.
+Обе метки используют одну спрайтовую область `page6`, окрашенную при рисовании.
+
+Зелёный сектор показывает горизонтальный угол обзора. Код по RVA `0x400b0`
+держит его на верхней оси прибора и откладывает половину угла в каждую
+сторону на радиусе 75. Маска берётся из `page7`. При смене разрешения все
+координаты масштабируются независимо по ширине и высоте.
+[Хеш сборки iron3d.dll](../reference/original-binaries.md).
+
## Контракт новой реализации
UI scene хранит корневые widgets, focus, viewport/clip rectangles и modal