Skip to content

Commit

Permalink
fps-aware openxr pointer smoothing
Browse files Browse the repository at this point in the history
  • Loading branch information
galister committed Sep 15, 2024
1 parent 72a8253 commit 21331b5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/backend/openxr/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
);
}

Expand Down
3 changes: 3 additions & 0 deletions src/backend/openxr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 21331b5

Please sign in to comment.