fps-aware openxr pointer smoothing

This commit is contained in:
galister
2024-09-16 05:09:10 +09:00
parent 72a82530ae
commit 21331b5c42
2 changed files with 8 additions and 4 deletions

View File

@@ -324,12 +324,13 @@ impl OpenXrHand {
transmute::<Vector3f, Vec3>(location.pose.position),
)
};
let lerp_factor = (1.0 / (xr.predicted_display_period.as_nanos() / 10_000_000) as f32
* session.config.pointer_lerp_factor)
.clamp(0.1, 1.0);
pointer.raw_pose = Affine3A::from_rotation_translation(new_quat, new_pos);
pointer.pose = Affine3A::from_rotation_translation(
cur_quat.lerp(new_quat, session.config.pointer_lerp_factor),
cur_pos
.lerp(new_pos.into(), session.config.pointer_lerp_factor)
.into(),
cur_quat.lerp(new_quat, lerp_factor),
cur_pos.lerp(new_pos.into(), lerp_factor).into(),
);
}

View File

@@ -48,6 +48,7 @@ struct XrState {
system: xr::SystemId,
session: xr::Session<xr::Vulkan>,
predicted_display_time: xr::Time,
predicted_display_period: xr::Duration,
stage: Arc<xr::Space>,
view: Arc<xr::Space>,
stage_offset: Affine3A,
@@ -131,6 +132,7 @@ pub fn openxr_run(running: Arc<AtomicBool>, show_by_default: bool) -> Result<(),
system,
session,
predicted_display_time: xr::Time::from_nanos(0),
predicted_display_period: xr::Duration::from_nanos(10_000_000),
stage: Arc::new(stage),
view: Arc::new(view),
stage_offset: Affine3A::IDENTITY,
@@ -231,6 +233,7 @@ pub fn openxr_run(running: Arc<AtomicBool>, show_by_default: bool) -> Result<(),
frame_stream.begin()?;
xr_state.predicted_display_time = xr_frame_state.predicted_display_time;
xr_state.predicted_display_period = xr_frame_state.predicted_display_period;
if !xr_frame_state.should_render {
frame_stream.end(