aboutsummaryrefslogtreecommitdiff
path: root/crates
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 /crates
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.
Diffstat (limited to 'crates')
-rw-r--r--crates/fparkan-render/src/cockpit_course.rs108
-rw-r--r--crates/fparkan-render/src/lib.rs1
2 files changed, 109 insertions, 0 deletions
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.