Физган: диагностика SOURCE_RS_PHYSGUN_DEBUG (ошибка и скорости раз в 30 кадров)
Some checks are pending
CI / checks (push) Waiting to run
Some checks are pending
CI / checks (push) Waiting to run
This commit is contained in:
parent
26a61b0e7e
commit
49bd9f127f
1 changed files with 20 additions and 0 deletions
|
|
@ -428,6 +428,26 @@ pub fn hold(world: &mut World, grab: &mut Grab, origin: Vec3, direction: Vec3, d
|
|||
// Компенсация вращения: без неё угловая скорость уводила бы точку захвата
|
||||
// с луча, и P-регулятор догонял бы её рывками.
|
||||
let velocity = clamp_speed(point_velocity - omega.cross(arm), PHYSGUN_MAX_SPEED);
|
||||
// Диагностика по требованию: `SOURCE_RS_PHYSGUN_DEBUG=1` печатает раз в
|
||||
// 30 кадров рассогласование и скорости — по числам видно, где теряется
|
||||
// скорость (цель, пружина или тело).
|
||||
if std::sync::OnceLock::<bool>::new()
|
||||
.get_or_init(|| std::env::var_os("SOURCE_RS_PHYSGUN_DEBUG").is_some())
|
||||
== &true
|
||||
{
|
||||
use std::sync::atomic::{AtomicU32, Ordering};
|
||||
static COUNTER: AtomicU32 = AtomicU32::new(0);
|
||||
if COUNTER.fetch_add(1, Ordering::Relaxed) % 30 == 0 {
|
||||
eprintln!(
|
||||
"PHYSGUN: error={:.1} target_v={:.0} point_v={:.0} body_v={:.0} dist={:.0}",
|
||||
(target - point).length(),
|
||||
target_velocity.length(),
|
||||
point_velocity.length(),
|
||||
velocity.length(),
|
||||
grab.distance
|
||||
);
|
||||
}
|
||||
}
|
||||
world.physics.set_velocity(grab.body, velocity);
|
||||
world.physics.set_angular_velocity(grab.body, omega);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue