remove XrSpatialTransform in favor of making XrSpace a Component and adding XrSpatialOffset

Signed-off-by: Schmarni <marnistromer@gmail.com>
This commit is contained in:
Schmarni
2024-06-23 00:07:28 +02:00
parent 6003cc7ac6
commit b7c4a05482
5 changed files with 47 additions and 34 deletions

View File

@@ -3,21 +3,19 @@ use bevy::{
render::{extract_component::ExtractComponent, extract_resource::ExtractResource},
};
use crate::types::XrPose;
/// Any Spaces will be invalid after the owning session exits
#[repr(transparent)]
#[derive(Clone, Copy, Hash, PartialEq, Eq, Reflect, Debug)]
#[derive(Clone, Copy, Hash, PartialEq, Eq, Reflect, Debug, Component, ExtractComponent)]
pub struct XrSpace(u64);
#[derive(Clone, Copy, PartialEq, Reflect, Debug, Component, ExtractComponent)]
pub struct XrSpatialTransform {
pub space: XrSpace,
pub offset: Transform,
}
impl XrSpatialTransform {
pub const fn from_space(space: XrSpace) -> Self {
Self { space, offset: Transform::IDENTITY }
}
}
// Does repr(transparent) even make sense here?
#[repr(transparent)]
#[derive(
Clone, Copy, PartialEq, Reflect, Debug, Component, ExtractComponent, Default, Deref, DerefMut,
)]
pub struct XrSpatialOffset(pub XrPose);
#[derive(Event, Clone, Copy, Deref, DerefMut)]
pub struct XrDestroySpace(pub XrSpace);

View File

@@ -1,13 +1,26 @@
use bevy::math::{Quat, Vec3};
use bevy::{
math::{Quat, Vec3},
reflect::Reflect,
transform::components::Transform,
};
#[derive(Clone, Copy, PartialEq, Reflect, Debug)]
pub struct XrPose {
pub position: Vec3,
pub translation: Vec3,
pub rotation: Quat,
}
impl Default for XrPose {
fn default() -> Self {
Self::IDENTITY
}
}
impl XrPose {
pub const IDENTITY: XrPose = XrPose {
position: Vec3::ZERO,
translation: Vec3::ZERO,
rotation: Quat::IDENTITY,
};
pub const fn to_transform(self) -> Transform {
Transform::from_translation(self.translation).with_rotation(self.rotation)
}
}