Add proper get_pose for XRSpaces

This commit is contained in:
Manish Goregaokar 2019-04-04 16:06:23 -07:00
parent d2e2b8da4d
commit e33896f3ec
3 changed files with 53 additions and 25 deletions

View file

@ -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)
}
}
}