mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Add proper get_pose for XRSpaces
This commit is contained in:
parent
d2e2b8da4d
commit
e33896f3ec
3 changed files with 53 additions and 25 deletions
|
@ -55,6 +55,9 @@ impl XRReferenceSpaceMethods for XRReferenceSpace {
|
|||
|
||||
impl XRReferenceSpace {
|
||||
/// Gets pose of the viewer with respect to this space
|
||||
///
|
||||
/// This is equivalent to `get_pose(self).inverse() * get_pose(viewerSpace)`, however
|
||||
/// we specialize it to be efficient
|
||||
pub fn get_viewer_pose(&self, base_pose: &WebVRFrameData) -> RigidTransform3D<f64> {
|
||||
let pose = self.get_unoffset_viewer_pose(base_pose);
|
||||
|
||||
|
@ -72,7 +75,8 @@ impl XRReferenceSpace {
|
|||
stationary.get_unoffset_viewer_pose(base_pose)
|
||||
} else {
|
||||
// non-subclassed XRReferenceSpaces exist, obtained via the "identity"
|
||||
// type. The pose does not depend on the base pose.
|
||||
// type. These poses are equivalent to the viewer pose and follow the headset
|
||||
// around, so the viewer is always at an identity transform with respect to them
|
||||
RigidTransform3D::identity()
|
||||
}
|
||||
}
|
||||
|
@ -82,7 +86,25 @@ impl XRReferenceSpace {
|
|||
/// The reference origin used is common between all
|
||||
/// get_pose calls for spaces from the same device, so this can be used to compare
|
||||
/// with other spaces
|
||||
pub fn get_pose(&self, _: &WebVRFrameData) -> RigidTransform3D<f64> {
|
||||
unimplemented!()
|
||||
pub fn get_pose(&self, base_pose: &WebVRFrameData) -> RigidTransform3D<f64> {
|
||||
let pose = self.get_unoffset_pose(base_pose);
|
||||
|
||||
// This may change, see https://github.com/immersive-web/webxr/issues/567
|
||||
let offset = self.transform.get().transform();
|
||||
offset.post_mul(&pose)
|
||||
}
|
||||
|
||||
/// Gets pose represented by this space
|
||||
///
|
||||
/// Does not apply originOffset, use get_viewer_pose instead if you need it
|
||||
pub fn get_unoffset_pose(&self, base_pose: &WebVRFrameData) -> RigidTransform3D<f64> {
|
||||
if let Some(stationary) = self.downcast::<XRStationaryReferenceSpace>() {
|
||||
stationary.get_unoffset_pose(base_pose)
|
||||
} else {
|
||||
// non-subclassed XRReferenceSpaces exist, obtained via the "identity"
|
||||
// type. These are equivalent to the viewer pose and follow the headset
|
||||
// around
|
||||
XRSpace::viewer_pose_from_frame_data(base_pose)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue