diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-02 17:33:49 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-02 17:33:49 +0300 |
| commit | bd7811533a348e56d2be9c7281d0533fc8c46024 (patch) | |
| tree | fee2ca08f873d7eef94d26c2cabd51b3cd2e4ce6 /crates/fparkan-runtime/src/strategic_view | |
| parent | da16b075618b792458bbb9ca19e856e9c4189c66 (diff) | |
| download | fparkan-bd7811533a348e56d2be9c7281d0533fc8c46024.tar.xz fparkan-bd7811533a348e56d2be9c7281d0533fc8c46024.zip | |
feat(ui): follow mobile command posts with the strategic camera
Connect captured command vehicles and follow their native orbit. Verify the sweep and acceleration against the original DLL. In a Teleport debug copy, verify Enter, edge rotation and Esc with Vulkan validation enabled. The stock start opens cleanly. The stock route and the original window comparison remain pending.
Diffstat (limited to 'crates/fparkan-runtime/src/strategic_view')
| -rw-r--r-- | crates/fparkan-runtime/src/strategic_view/vehicle_camera.rs | 153 |
1 files changed, 153 insertions, 0 deletions
diff --git a/crates/fparkan-runtime/src/strategic_view/vehicle_camera.rs b/crates/fparkan-runtime/src/strategic_view/vehicle_camera.rs new file mode 100644 index 00000000..424d065b --- /dev/null +++ b/crates/fparkan-runtime/src/strategic_view/vehicle_camera.rs @@ -0,0 +1,153 @@ +use super::{CameraAxis, CommandCamera, COMMAND_FOV}; + +impl CommandCamera { + pub(super) fn advance_vehicle( + &mut self, + dt: f32, + rotation: [i8; 2], + map_max: [f32; 3], + target: [f32; 3], + radius: f32, + ) { + if dt <= 0.0 { + return; + } + // iron3d+0x37f70 follows an orbit point in world axes. + let (sin_yaw, cos_yaw) = self.yaw.sin_cos(); + let (sin_tilt, cos_tilt) = self.tilt.sin_cos(); + let horizontal = sin_tilt * self.follow_distance; + let goal = [ + target[0] - cos_yaw * horizontal, + target[1] - sin_yaw * horizontal, + target[2] + cos_tilt * self.follow_distance, + ]; + let margin = (0.5 * COMMAND_FOV).tan() * self.position[2]; + for (axis, (position, goal)) in self.position.iter_mut().zip(goal).enumerate() { + let (snap, speed) = if axis < 2 { (3.0, 125.0) } else { (2.0, 62.5) }; + let offset = goal - *position; + if offset.abs() <= snap { + *position = goal; + self.axes[axis] = CameraAxis::default(); + continue; + } + let direction = if offset > 0.0 { 1 } else { -1 }; + let next = *position + self.axes[axis].step(direction, speed, dt); + if axis == 2 + || (offset < 0.0 && next > margin) + || (offset > 0.0 && next < map_max[axis] - margin) + { + *position = next; + } + } + self.rotate(dt, rotation); + + // iron3d+0x38250 adjusts the orbit distance once per active frame. + if self.follow_distance > radius * 8.0 { + self.follow_distance -= 1.0; + } + if self.follow_distance < 200.0 { + self.follow_distance += 1.0; + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::strategic_view::{mobile_command_post, CommandCameraInput, CommandPost}; + use crate::{ + create, enter_vehicle, frame, load_gameplay_mission, mission_object_handle, player_vehicle, + starting_cockpit, EngineServices, MissionMode, MissionRequest, MissionStartupInput, + }; + use fparkan_vfs::DirectoryVfs; + use fparkan_world::{set_transform, transform_state, ObjectHandle, OriginalObjectId}; + use std::f32::consts::FRAC_PI_2; + use std::sync::Arc; + + #[test] + fn vehicle_camera_tracks_the_native_orbit_in_world_axes() { + let mut camera = CommandCamera { + post: CommandPost::Warbot(ObjectHandle { + slot: 0, + generation: 0, + }), + position: [402.9, 430.0, 92.0], + yaw: FRAC_PI_2, + tilt: 1.0, + follow_distance: 25.0, + axes: [CameraAxis::default(); 5], + }; + let max = [1024.0; 3]; + let target = [400.0, 450.0, 80.0]; + camera.advance_vehicle(0.01, [0, 0], max, target, 3.0); + for (actual, expected) in camera + .position + .into_iter() + .zip([400.0, 428.96323, 93.50756]) + { + assert!((actual - expected).abs() < 0.00005); + } + assert_eq!(camera.follow_distance, 25.0); + camera.position = [420.0, 400.0, 80.0]; + camera.advance_vehicle(0.01, [1, 0], max, target, 3.0); + assert_eq!(camera.position, [420.0, 400.0, 80.0]); + camera.advance_vehicle(0.25, [1, 0], max, target, 3.0); + assert_eq!(camera.position, [404.375, 415.625, 87.8125]); + assert!((camera.yaw - FRAC_PI_2 - 0.1875).abs() < 1e-6); + } + + #[test] + #[ignore = "requires licensed corpus"] + fn captured_teleport_hq_supplies_mobile_camera_without_boarding() { + let root = std::env::var_os("FPARKAN_CORPUS_PART1_ROOT").unwrap(); + let mut engine = create(EngineServices::new(Arc::new(DirectoryVfs::new(root)))).unwrap(); + load_gameplay_mission( + &mut engine, + MissionRequest { + key: "MISSIONS/CAMPAIGN/CAMPAIGN.00/Mission.04/data.tma".into(), + mode: MissionMode::SingleMission, + }, + MissionStartupInput { + queue_time_ms: 0, + research_creation_gate: false, + }, + None, + ) + .unwrap(); + frame(&mut engine, 1).unwrap(); + let hero = starting_cockpit(&engine).unwrap(); + let hq = mission_object_handle(&engine, OriginalObjectId(0)).unwrap(); + let original_pose = transform_state(&engine.world, hero.handle).unwrap(); + let mut near_hq = original_pose; + near_hq.position = transform_state(&engine.world, hq).unwrap().position; + set_transform(&mut engine.world, hero.handle, near_hq).unwrap(); + assert_eq!(mobile_command_post(&engine, hero, hq), None); + assert_eq!( + enter_vehicle(&mut engine, hero, None).unwrap().captured, + Some(OriginalObjectId(0)) + ); + let post = mobile_command_post(&engine, hero, hq); + assert_eq!(post, Some(CommandPost::Warbot(hq))); + set_transform(&mut engine.world, hero.handle, original_pose).unwrap(); + assert_eq!(mobile_command_post(&engine, hero, hq), None); + + let mut camera = CommandCamera::new(&engine, post.unwrap()).unwrap(); + let terrain_only = |_| panic!("mobile camera should skip the roof query"); + let start = camera + .sample(&engine, 0.0, CommandCameraInput::default(), terrain_only) + .unwrap(); + let input = CommandCameraInput { + rotation: [1, 0], + ..Default::default() + }; + let mut moved = start; + for _ in 0..30 { + moved = camera + .sample(&engine, 1.0 / 60.0, input, terrain_only) + .unwrap(); + } + assert_ne!(moved.translation(), start.translation()); + assert_ne!(moved.words[0], start.words[0]); + assert_eq!(player_vehicle(&engine), None); + } +} |
