Watch rotation + galister fixes (Keyboard mapping fix, OpenXR hand transform fix) (#4)

* Watch rotation + galister fixes (Keyboard mapping fix, OpenXR hand transform fix)

* Use from_scale_rotation_translation
This commit is contained in:
Aleksander
2024-01-30 21:22:18 +01:00
committed by GitHub
parent dded4f6398
commit 6999a4b277
5 changed files with 17 additions and 7 deletions

View File

@@ -353,7 +353,10 @@ fn quat_lerp(a: Quat, mut b: Quat, t: f32) -> Quat {
fn transform_to_posef(transform: &Affine3A) -> xr::Posef {
let translation = transform.translation;
let rotation = Quat::from_affine3(transform).normalize();
let norm_mat3 = transform
.matrix3
.mul_scalar(1.0 / transform.matrix3.x_axis.length());
let rotation = Quat::from_mat3a(&norm_mat3).normalize();
xr::Posef {
orientation: xr::Quaternionf {

View File

@@ -72,7 +72,7 @@ where
fn default() -> Self {
OverlayData {
state: Default::default(),
backend: Box::new(SplitOverlayBackend::default()),
backend: Box::<SplitOverlayBackend>::default(),
primary_pointer: None,
data: Default::default(),
}
@@ -87,17 +87,22 @@ impl OverlayState {
RelativeTo::Hand(idx) => Some(app.input_state.pointers[idx].pose),
}
}
pub fn auto_movement(&mut self, app: &mut AppState) {
if let Some(parent) = self.parent_transform(app) {
self.transform = parent
* Affine3A::from_scale_rotation_translation(
Vec3::ONE * self.spawn_scale,
self.spawn_rotation,
self.spawn_rotation
* Quat::from_rotation_x(f32::to_radians(-180.0))
* Quat::from_rotation_z(f32::to_radians(180.0)),
self.spawn_point.into(),
);
self.dirty = true;
}
}
pub fn reset(&mut self, app: &mut AppState) {
let translation = app.input_state.hmd.transform_point3a(self.spawn_point);
self.transform = Affine3A::from_scale_rotation_translation(
@@ -108,6 +113,7 @@ impl OverlayState {
self.realign(&app.input_state.hmd);
}
pub fn realign(&mut self, hmd: &Affine3A) {
let to_hmd = hmd.translation - self.transform.translation;
let up_dir: Vec3A;

View File

@@ -108,7 +108,7 @@ impl UInputProvider {
}
for key in VirtualKey::iter() {
let key: Key = unsafe { transmute(key as u16) };
let key: Key = unsafe { transmute((key as u16) - 8) };
if handle.set_keybit(key).is_err() {
return None;
}
@@ -249,6 +249,7 @@ pub const SUPER: KeyModifier = 0x40;
pub const META: KeyModifier = 0x80;
#[allow(non_camel_case_types)]
#[repr(u16)]
#[derive(Debug, PartialEq, Clone, Copy, IntegerId, EnumString, EnumIter)]
pub enum VirtualKey {
Escape = 9,

View File

@@ -115,7 +115,7 @@ where
canvas.bg_color = color_parse("#405060");
for screen in screens.into_iter() {
for screen in screens.iter() {
let button = canvas.button(
button_x + 2.,
162.,
@@ -169,7 +169,7 @@ where
name: "Watch".into(),
size: (400, 200),
want_visible: true,
spawn_scale: 0.065 * state.session.config.watch_scale,
spawn_scale: 0.11 * state.session.config.watch_scale,
spawn_point: state.session.watch_pos.into(),
spawn_rotation: state.session.watch_rot,
interaction_transform,

View File

@@ -13,7 +13,7 @@ use crate::{
shaders::{frag_color, frag_glyph, frag_screen, frag_sprite, frag_srgb, vert_common},
};
pub const WATCH_DEFAULT_POS: Vec3 = Vec3::new(0.025, 0., 0.15);
pub const WATCH_DEFAULT_POS: Vec3 = Vec3::new(-0.03, -0.01, 0.1);
pub const WATCH_DEFAULT_ROT: Quat = Quat::from_xyzw(0.7071066, 0., 0.7071066, 0.0007963);
pub struct AppState {