aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 18:23:04 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 18:23:04 +0300
commit077bead07a76908ac4e0e2b84de3940256cf6fd1 (patch)
tree6d01dd0b8885204a0dd054e8a64a9360985bf173 /crates
parent9f442fa339371869dda44a32a9e0ec2f763d830c (diff)
downloadfparkan-077bead07a76908ac4e0e2b84de3940256cf6fd1.tar.xz
fparkan-077bead07a76908ac4e0e2b84de3940256cf6fd1.zip
feat(ui): draw the cockpit reticle from the original atlas
Use the native page9 crops, mirrored scales and hull-relative heading marker. Match the geometry against the original and run the stock Constructor cockpit with and without the satellite map under Vulkan validation.
Diffstat (limited to 'crates')
-rw-r--r--crates/fparkan-assets/src/cockpit_reticle.rs75
-rw-r--r--crates/fparkan-assets/src/lib.rs1
2 files changed, 76 insertions, 0 deletions
diff --git a/crates/fparkan-assets/src/cockpit_reticle.rs b/crates/fparkan-assets/src/cockpit_reticle.rs
new file mode 100644
index 00000000..a4d9343c
--- /dev/null
+++ b/crates/fparkan-assets/src/cockpit_reticle.rs
@@ -0,0 +1,75 @@
+//! Original page9 crops and 640×480 placement for the cockpit reticle.
+
+use crate::{
+ mission_pager::copy_sprite,
+ ui_sprite::{atlas_region, load_ui_page},
+ RgbaImage,
+};
+use fparkan_vfs::Vfs;
+
+/// The rectangle enclosing the reticle sprites in the native viewport.
+pub const BOUNDS: [u32; 4] = [232, 199, 408, 281];
+
+/// Assembles the ring, its corners and the mirrored scales from the installed atlas.
+pub fn load(vfs: &dyn Vfs) -> Result<RgbaImage, String> {
+ let page = load_ui_page(vfs, "page9")?;
+ let crop = |rect| atlas_region(&page, rect).ok_or("reticle crop outside page9");
+ // iron3d+0x4318d selects these three source rectangles.
+ let scale = crop([168, 0, 82, 15])?;
+ let ring = crop([77, 0, 64, 64])?;
+ let corner = crop([54, 28, 23, 23])?;
+ let [x, y, right, bottom] = BOUNDS;
+ let mut reticle = RgbaImage {
+ width: right - x,
+ height: bottom - y,
+ rgba8: vec![0; ((right - x) * (bottom - y) * 4) as usize],
+ };
+ // iron3d+0x43293 draws the lower right corner with a wider span.
+ for (sprite, [left, top, right, bottom], flip) in [
+ (&ring, [288, 208, 352, 272], [false; 2]),
+ (&corner, [279, 199, 300, 220], [false, true]),
+ (&corner, [279, 260, 300, 281], [false; 2]),
+ (&corner, [340, 199, 361, 220], [true, true]),
+ (&corner, [340, 260, 367, 281], [true, false]),
+ (&scale, [232, 233, 314, 248], [false; 2]),
+ (&scale, [326, 233, 408, 248], [true, false]),
+ ] {
+ copy_sprite(
+ &mut reticle,
+ sprite,
+ [left - x, top - y, right - x, bottom - y],
+ flip,
+ [55, 255, 55],
+ );
+ }
+ Ok(reticle)
+}
+
+/// Native solid marker bounds from the camera's forward vector in hull space.
+pub fn heading_marker([x, y]: [f32; 2]) -> [f32; 4] {
+ // iron3d+0x433d5 rounds each edge separately before subtracting it from the center.
+ let edge = |center: f32, direction: f32, padding: f32| {
+ center - (24.0 * direction + padding).round_ties_even()
+ };
+ [
+ edge(320.0, x, 1.0),
+ edge(240.0, y, 1.0),
+ edge(320.0, x, -1.0),
+ edge(240.0, y, -1.0),
+ ]
+}
+
+#[cfg(test)]
+mod tests {
+ use super::heading_marker;
+
+ #[test]
+ fn heading_marker_uses_camera_rotation_within_the_hull() {
+ assert_eq!(heading_marker([0.0, 1.0]), [319.0, 215.0, 321.0, 217.0]);
+ // Local matrix sampled from the medium bunker after aiming in Two Fortresses.
+ assert_eq!(
+ heading_marker([0.274_880, 0.103_380]),
+ [312.0, 237.0, 314.0, 239.0]
+ );
+ }
+}
diff --git a/crates/fparkan-assets/src/lib.rs b/crates/fparkan-assets/src/lib.rs
index 295ed772..55c2d611 100644
--- a/crates/fparkan-assets/src/lib.rs
+++ b/crates/fparkan-assets/src/lib.rs
@@ -31,6 +31,7 @@ pub use fparkan_texm::{PageRect, RgbaImage};
use fparkan_vfs::DirectoryVfs;
mod behavior_profile_values;
mod chassis_profile;
+pub mod cockpit_reticle;
mod control_drive;
mod control_weapon_sound;
mod designer_categories;