Skip to content

Commit

Permalink
openxr: laser pointer smoothing
Browse files Browse the repository at this point in the history
  • Loading branch information
galister committed Sep 8, 2024
1 parent 4f38d1a commit b0a33a1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
12 changes: 10 additions & 2 deletions src/backend/openxr/input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,13 +316,21 @@ impl OpenXrHand {
.location_flags
.contains(xr::SpaceLocationFlags::ORIENTATION_VALID)
{
let (quat, pos) = unsafe {
let (cur_quat, cur_pos) = (Quat::from_affine3(&pointer.pose), pointer.pose.translation);

let (new_quat, new_pos) = unsafe {
(
transmute::<Quaternionf, Quat>(location.pose.orientation),
transmute::<Vector3f, Vec3>(location.pose.position),
)
};
pointer.pose = Affine3A::from_rotation_translation(quat, pos);
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(),
);
}

pointer.now.click = self
Expand Down
12 changes: 6 additions & 6 deletions src/backend/openxr/playspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl PlayspaceMover {
state: &AppState,
monado: &mut Monado,
) {
for (_i, pointer) in state.input_state.pointers.iter().enumerate() {
for pointer in state.input_state.pointers.iter() {
if pointer.now.space_reset {
if !pointer.before.space_reset {
log::info!("Space reset");
Expand All @@ -74,7 +74,7 @@ impl PlayspaceMover {
}

let new_hand =
Quat::from_affine3(&(data.pose * state.input_state.pointers[data.hand].pose));
Quat::from_affine3(&(data.pose * state.input_state.pointers[data.hand].raw_pose));

let dq = new_hand * data.hand_pose.conjugate();
let rel_y = f32::atan2(
Expand Down Expand Up @@ -131,7 +131,7 @@ impl PlayspaceMover {

let new_hand = data
.pose
.transform_point3a(state.input_state.pointers[data.hand].pose.translation);
.transform_point3a(state.input_state.pointers[data.hand].raw_pose.translation);
let relative_pos =
(new_hand - data.hand_pose) * state.session.config.space_drag_multiplier;

Expand Down Expand Up @@ -159,7 +159,7 @@ impl PlayspaceMover {
if pointer.now.space_drag {
let hand_pos = self
.last_transform
.transform_point3a(pointer.pose.translation);
.transform_point3a(pointer.raw_pose.translation);
self.drag = Some(MoverData {
pose: self.last_transform,
hand: i,
Expand Down Expand Up @@ -196,8 +196,8 @@ impl PlayspaceMover {
self.rotate = None;
}

let y1 = input.pointers[0].pose.translation.y;
let y2 = input.pointers[1].pose.translation.y;
let y1 = input.pointers[0].raw_pose.translation.y;
let y2 = input.pointers[1].raw_pose.translation.y;
let delta = y1.min(y2) - 0.03;
self.last_transform.translation.y += delta;
self.apply_offset(self.last_transform, monado);
Expand Down
7 changes: 7 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ pub fn def_point7() -> f32 {
0.7
}

pub fn def_point3() -> f32 {
0.3
}

fn def_osc_port() -> u16 {
9000
}
Expand Down Expand Up @@ -263,6 +267,9 @@ pub struct GeneralConfig {

#[serde(default = "def_false")]
pub screen_render_down: bool,

#[serde(default = "def_point3")]
pub pointer_lerp_factor: f32,
}

impl GeneralConfig {
Expand Down

0 comments on commit b0a33a1

Please sign in to comment.