add new XrSpace and impl that
Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use bevy::prelude::*;
|
||||
use bevy_xr::types::XrPose;
|
||||
|
||||
pub trait ToPosef {
|
||||
fn to_posef(&self) -> openxr::Posef;
|
||||
@@ -6,6 +7,9 @@ pub trait ToPosef {
|
||||
pub trait ToTransform {
|
||||
fn to_transform(&self) -> Transform;
|
||||
}
|
||||
pub trait ToXrPose {
|
||||
fn to_xr_pose(&self) -> XrPose;
|
||||
}
|
||||
pub trait ToQuaternionf {
|
||||
fn to_quaternionf(&self) -> openxr::Quaternionf;
|
||||
}
|
||||
@@ -38,6 +42,22 @@ impl ToTransform for openxr::Posef {
|
||||
.with_rotation(self.orientation.to_quat())
|
||||
}
|
||||
}
|
||||
impl ToXrPose for openxr::Posef {
|
||||
fn to_xr_pose(&self) -> XrPose {
|
||||
XrPose {
|
||||
position: self.position.to_vec3(),
|
||||
rotation: self.orientation.to_quat(),
|
||||
}
|
||||
}
|
||||
}
|
||||
impl ToPosef for XrPose {
|
||||
fn to_posef(&self) -> openxr::Posef {
|
||||
openxr::Posef {
|
||||
orientation: self.rotation.to_quaternionf(),
|
||||
position: self.position.to_vector3f(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ToQuaternionf for Quat {
|
||||
fn to_quaternionf(&self) -> openxr::Quaternionf {
|
||||
@@ -51,7 +71,14 @@ impl ToQuaternionf for Quat {
|
||||
}
|
||||
impl ToQuat for openxr::Quaternionf {
|
||||
fn to_quat(&self) -> Quat {
|
||||
Quat::from_xyzw(self.x, self.y, self.z, self.w)
|
||||
let mut quat = Quat::from_xyzw(self.x, self.y, self.z, self.w);
|
||||
if quat.length() == 0.0 {
|
||||
quat = Quat::IDENTITY;
|
||||
}
|
||||
if !quat.is_normalized() {
|
||||
quat = quat.normalize();
|
||||
}
|
||||
quat
|
||||
}
|
||||
}
|
||||
impl ToVector3f for Vec3 {
|
||||
|
||||
Reference in New Issue
Block a user