diff options
author | Manish Goregaokar <manishsmail@gmail.com> | 2019-04-04 16:06:23 -0700 |
---|---|---|
committer | Manish Goregaokar <manishsmail@gmail.com> | 2019-04-04 16:06:23 -0700 |
commit | e33896f3ecc21a4a16d830bbf7076dcbd4d3c55f (patch) | |
tree | 80b666afa952ba66e73a29e4e48d4da700f6e12d /components/script/dom/xrreferencespace.rs | |
parent | d2e2b8da4da132390225ffc85adb8a33a1b36c13 (diff) | |
download | servo-e33896f3ecc21a4a16d830bbf7076dcbd4d3c55f.tar.gz servo-e33896f3ecc21a4a16d830bbf7076dcbd4d3c55f.zip |
Add proper get_pose for XRSpaces
Diffstat (limited to 'components/script/dom/xrreferencespace.rs')
-rw-r--r-- | components/script/dom/xrreferencespace.rs | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/components/script/dom/xrreferencespace.rs b/components/script/dom/xrreferencespace.rs index ce81a714e80..804768eee69 100644 --- a/components/script/dom/xrreferencespace.rs +++ b/components/script/dom/xrreferencespace.rs @@ -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) + } } } |