diff options
Diffstat (limited to 'crates/fparkan-runtime/src')
| -rw-r--r-- | crates/fparkan-runtime/src/strategic_view.rs | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/crates/fparkan-runtime/src/strategic_view.rs b/crates/fparkan-runtime/src/strategic_view.rs index b22555f6..81d822eb 100644 --- a/crates/fparkan-runtime/src/strategic_view.rs +++ b/crates/fparkan-runtime/src/strategic_view.rs @@ -76,8 +76,13 @@ fn has_command_link(devices: &[crate::EffectiveControlDevice]) -> bool { } /// Initial external viewpoint of a command post, sampled from the current world. +/// `building_height` returns the highest building hit on the downward segment. #[must_use] -pub fn command_view(engine: &Engine, post: CommandPost) -> Option<RawCameraTransform> { +pub fn command_view( + engine: &Engine, + post: CommandPost, + building_height: impl FnOnce([[f32; 3]; 2]) -> Option<f32>, +) -> Option<RawCameraTransform> { let (handle, clearance) = match post { CommandPost::Bunker(handle) => (handle, 36.0), CommandPost::Warbot(handle) => (handle, 2.5), @@ -87,11 +92,15 @@ pub fn command_view(engine: &Engine, post: CommandPost) -> Option<RawCameraTrans .ok()? .position .map(f32::from_bits); - let terrain = engine.loaded.as_ref()?.terrain.height_at([x, y]).ok()??; + let terrain = &engine.loaded.as_ref()?.terrain; + let ground = terrain.height_at([x, y]).ok()??; + let [_, [_, _, top]] = terrain.surface_bounds()?; + // iron3d+0xa1470 casts down from the map's upper plane and includes roofs. + let surface = building_height([[x, y, top], [x, y, ground]]).unwrap_or(ground); // iron3d+0x63ec0/+0x64140 start at the post, looking north. - // The first external update sets pitch and raises the eye out of terrain. + // The first external update sets pitch and raises the eye over the surface. let matrix = LegacyIron3dEulerTransform { - translation: [x, y, z.max(terrain + clearance)], + translation: [x, y, z.max(surface + clearance)], orientation_radians: [0.0, FRAC_PI_2 - 1.0, FRAC_PI_2], } .try_row_major()?; @@ -149,6 +158,15 @@ mod tests { let bunker = crate::mission_object_handle(&engine, OriginalObjectId(0)).unwrap(); let post = command_post(&engine, hero); assert_eq!(post, Some(CommandPost::Bunker(bunker))); - assert!(command_view(&engine, post.unwrap()).is_some()); + let post = post.unwrap(); + let previous = command_view(&engine, post, |_| None).unwrap().translation(); + let native_roof = 108.54639; + let raised = command_view(&engine, post, |[[x, y, top], [_, _, ground]]| { + assert_eq!([x, y], [previous[0], previous[1]]); + assert!(ground < native_roof && native_roof < top); + Some(native_roof) + }) + .unwrap(); + assert_eq!(raised.translation(), [previous[0], previous[1], 144.54639]); } } |
