diff options
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/fparkan-assets/src/cockpit_reticle.rs | 75 | ||||
| -rw-r--r-- | crates/fparkan-assets/src/lib.rs | 1 |
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; |
