From 514136ca97191672ecd24173d1836cdc4d26493b Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Thu, 26 Nov 2026 14:00:09 +0400 Subject: feat(player): bob the cockpit view when walking Use the 0.45 second vertical cycle observed in the GOG hero camera. The stock Firing Range window shows lift on an accepted walk and settles on release. The body and muzzle still use their own poses. --- apps/fparkan-game/src/main.rs | 6 ++- crates/fparkan-runtime/src/lib.rs | 5 ++ crates/fparkan-runtime/src/player_gait.rs | 78 +++++++++++++++++++++++++++++++ docs/appendices/knowledge-boundaries.md | 2 + docs/tomes/06-behavior.md | 11 +++++ 5 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 crates/fparkan-runtime/src/player_gait.rs diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs index cbd81e22..f06b5d05 100644 --- a/apps/fparkan-game/src/main.rs +++ b/apps/fparkan-game/src/main.rs @@ -10523,9 +10523,13 @@ impl StaticVulkanApp { let pose = mount.map_or(pose, |mount| compose_unit_pose(mount, pose)); let offset = rotate_unit_vector(cockpit.node_point, pose.rotation); let point = std::array::from_fn(|axis| pose.translation[axis] + offset[axis]); + let mut translation = state.position.map(f32::from_bits); + if let Some(engine) = &self.mission_engine { + translation[2] += fparkan_runtime::player_walk_camera_lift(engine, cockpit); + } let camera = fparkan_render::forward_cockpit_camera( LegacyIron3dEulerTransform { - translation: state.position.map(f32::from_bits), + translation, orientation_radians: state.orientation.map(f32::from_bits), }, state.scale.map(f32::from_bits), diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs index 0dc5e4a5..11bac68d 100644 --- a/crates/fparkan-runtime/src/lib.rs +++ b/crates/fparkan-runtime/src/lib.rs @@ -94,6 +94,7 @@ pub use laboratory::LaboratoryReport; mod mission_events; mod ore_transport; mod patrol_points; +mod player_gait; mod player_motion; mod unit_speed; pub use patrol_points::PatrolPointReport; @@ -154,6 +155,7 @@ pub use mission_events::{ capture_building, capture_building_with_notice, capture_neutral_building, capture_neutral_warbot, MissionEventStop, MissionEventTick, MissionNotice, }; +pub use player_gait::player_walk_camera_lift; pub use player_motion::{ plan_player_motion, plan_player_motion_with_collision, PlayerMotion, PlayerMotionStep, }; @@ -1455,6 +1457,7 @@ struct LoadedMissionState { construction: construction::Construction, unit_patrol: Option, player_pitch_bits: u32, + player_gait: player_gait::PlayerGait, boarding: Option, local_hero: Option, script_host_mode: MissionMode, @@ -2811,6 +2814,7 @@ node_provider_distribution_suspended: false, construction, unit_patrol, player_pitch_bits: 0, + player_gait: Default::default(), boarding: None, local_hero, script_host_mode: request.mode, @@ -2909,6 +2913,7 @@ pub fn step_headless( } if let Some(mission) = &mut engine.loaded { capture_barrier::advance(mission, &engine.world, queue_time_ms); + player_gait::advance(mission, &engine.world, queue_time_ms); control_resources::tick(mission, &engine.world, queue_time_ms); } let (autodemo_combat_events, autodemo_combat_unavailable) = diff --git a/crates/fparkan-runtime/src/player_gait.rs b/crates/fparkan-runtime/src/player_gait.rs new file mode 100644 index 00000000..3b293d9a --- /dev/null +++ b/crates/fparkan-runtime/src/player_gait.rs @@ -0,0 +1,78 @@ +//! First-person motion of the walking hero's camera. + +use crate::{Engine, LoadedMissionState, StartingCockpit}; +use fparkan_world::{transform_state, World}; + +const WALK_CYCLE_MS: f32 = 448.0; +const CAMERA_LIFT: f32 = 0.15; + +#[derive(Default)] +pub(super) struct PlayerGait { + previous: Option<(u32, [u32; 2])>, + phase: f32, + lift: f32, +} + +impl PlayerGait { + fn advance(&mut self, clock_ms: u32, xy: [u32; 2]) { + let Some((previous_ms, previous_xy)) = self.previous.replace((clock_ms, xy)) else { + return; + }; + let elapsed_ms = clock_ms.wrapping_sub(previous_ms).min(500) as f32; + if previous_xy == xy { + let decay = (1.0 - elapsed_ms / (WALK_CYCLE_MS / 4.0)).clamp(0.0, 1.0); + self.lift *= decay; + if self.lift == 0.0 { + self.phase = 0.0; + } + return; + } + // shortcut: a sine matches the observed main component of the walk; + // the native camera track and its response to movement speed are open. + self.phase = (self.phase + elapsed_ms / WALK_CYCLE_MS).fract(); + self.lift = CAMERA_LIFT * (self.phase * std::f32::consts::TAU).sin(); + } +} + +pub(super) fn advance(mission: &mut LoadedMissionState, world: &World, now: u32) { + let pose = mission + .local_hero + .filter(|_| mission.boarding.is_none()) + .and_then(|hero| transform_state(world, hero).ok()); + if let Some(pose) = pose { + let [x, y, _] = pose.position; + mission.player_gait.advance(now, [x, y]); + } else { + mission.player_gait = PlayerGait::default(); + } +} + +/// Vertical movement of the local hero's camera at the latest simulation tick. +pub fn player_walk_camera_lift(engine: &Engine, cockpit: StartingCockpit) -> f32 { + engine + .loaded + .as_ref() + .filter(|mission| mission.local_hero == Some(cockpit.handle) && mission.boarding.is_none()) + .map_or(0.0, |mission| mission.player_gait.lift) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn camera_oscillates_only_after_walk_displaces_the_hero() { + let mut gait = PlayerGait::default(); + gait.advance(0, [0, 0]); + gait.advance(112, [0, 0]); + assert_eq!(gait.lift, 0.0); + gait.advance(224, [1, 0]); + assert_eq!(gait.lift, CAMERA_LIFT); + gait.advance(448, [3, 0]); + assert_eq!(gait.lift, -CAMERA_LIFT); + gait.advance(504, [3, 0]); + assert_eq!(gait.lift, -CAMERA_LIFT * 0.5); + gait.advance(616, [3, 0]); + assert_eq!(gait.lift, 0.0); + } +} diff --git a/docs/appendices/knowledge-boundaries.md b/docs/appendices/knowledge-boundaries.md index 2e77f9d8..a2be95e9 100644 --- a/docs/appendices/knowledge-boundaries.md +++ b/docs/appendices/knowledge-boundaries.md @@ -135,6 +135,8 @@ authoring API без динамического подтверждения. заводам. В штатном корпусе завершённый `Init` оставляет этот счётчик нулевым. `cockpit_pose_approx` отмечает расчёт кабины по ресурсной позе. +Вертикальное качание героя воспроизводит измеренный период. Форма +смещения, боковое качание и зависимость от скорости открыты. `player_motion_approx` отмечает постоянную скорость, приближённую чувствительность и проверку корпуса короткими отрезками. После задержки дольше полусекунды ходьба учитывает только первые 500 мс. `cockpit_aim_approx` diff --git a/docs/tomes/06-behavior.md b/docs/tomes/06-behavior.md index b165add6..f90ee0a3 100644 --- a/docs/tomes/06-behavior.md +++ b/docs/tomes/06-behavior.md @@ -2598,6 +2598,17 @@ zone/threshold и временной характеристикой. Строк «Конструкторе» дорожка меняет положение и направление узлов орудий около их собственных осей, а точка `CameraCenter` остаётся в кабине. +На участке устойчивой ходьбы героя в запущенной GOG-сборке высота +камеры менялась на 0,35 единицы от нижней точки до верхней. Полный +цикл занимал примерно 0,45 секунды. Положение снималось с активной +камеры GOG `iron3d.dll` через экземпляр игры по RVA `0x10a5f8`. +[Сборка оригинала](../reference/original-binaries.md). + +FParkan приближает это движение +вертикальной синусоидой. Она идёт, пока герой смещается после проверки +столкновений, и затухает на остановке. Высота корпуса и точки выстрела +по-прежнему определяются позой объекта и оружия. + В GOG `Control.dll` (SHA-256 `bcb86318089028548a178b03a21accdce15df0cc85ddd91674cf3c2f55012c6e`) фабрика по RVA `0x2d4b0` создаёт контроллер башни из записи типа 1. -- cgit v1.2.3