From 84620f4b687c0071d5a9bfbbf8a725c866d7357f Mon Sep 17 00:00:00 2001 From: zmerp Date: Sun, 15 Dec 2024 13:00:34 +0100 Subject: [PATCH] feat(common): :sparkles: Add `Pose * DeviceMotion` operator (#2574) --- alvr/common/src/primitives.rs | 12 ++++++++++++ alvr/server_core/src/tracking/mod.rs | 6 +----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/alvr/common/src/primitives.rs b/alvr/common/src/primitives.rs index 747c33bbf0..e59ded920a 100644 --- a/alvr/common/src/primitives.rs +++ b/alvr/common/src/primitives.rs @@ -55,3 +55,15 @@ pub struct DeviceMotion { pub linear_velocity: Vec3, pub angular_velocity: Vec3, } + +impl Mul for Pose { + type Output = DeviceMotion; + + fn mul(self, rhs: DeviceMotion) -> DeviceMotion { + DeviceMotion { + pose: self * rhs.pose, + linear_velocity: self.orientation * rhs.linear_velocity, + angular_velocity: self.orientation * rhs.angular_velocity, + } + } +} diff --git a/alvr/server_core/src/tracking/mod.rs b/alvr/server_core/src/tracking/mod.rs index 73e49f4b70..c476ee0963 100644 --- a/alvr/server_core/src/tracking/mod.rs +++ b/alvr/server_core/src/tracking/mod.rs @@ -115,11 +115,7 @@ impl TrackingManager { } pub fn recenter_motion(&self, motion: DeviceMotion) -> DeviceMotion { - DeviceMotion { - pose: self.recenter_pose(motion.pose), - linear_velocity: self.inverse_recentering_origin.orientation * motion.linear_velocity, - angular_velocity: self.inverse_recentering_origin.orientation * motion.angular_velocity, - } + self.inverse_recentering_origin * motion } // Performs all kinds of tracking transformations, driven by settings.