Skip to content
Permalink
Browse files

Add XRFrame.getPose()

  • Loading branch information...
Manishearth committed Apr 4, 2019
1 parent 3d79027 commit 7e4b6512a7c0899b642e5eedf0f250630f7d9d34
Showing with 18 additions and 0 deletions.
  1. +1 −0 components/script/dom/webidls/XRFrame.webidl
  2. +17 −0 components/script/dom/xrframe.rs
@@ -9,5 +9,6 @@ interface XRFrame {
readonly attribute XRSession session;

[Throws] XRViewerPose? getViewerPose(XRReferenceSpace referenceSpace);
[Throws] XRPose? getPose(XRSpace space, XRSpace relativeTo);
// XRInputPose? getInputPose(XRInputSource inputSource, optional XRReferenceSpace referenceSpace);
};
@@ -9,8 +9,10 @@ use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::globalscope::GlobalScope;
use crate::dom::xrpose::XRPose;
use crate::dom::xrreferencespace::XRReferenceSpace;
use crate::dom::xrsession::XRSession;
use crate::dom::xrspace::XRSpace;
use crate::dom::xrviewerpose::XRViewerPose;
use dom_struct::dom_struct;
use webvr_traits::WebVRFrameData;
@@ -67,4 +69,19 @@ impl XRFrameMethods for XRFrame {
&self.data,
)))
}

/// https://immersive-web.github.io/webxr/#dom-xrframe-getpose
fn GetPose(
&self,
space: &XRSpace,
relative_to: &XRSpace,
) -> Result<Option<DomRoot<XRPose>>, Error> {
if self.session != space.session() || self.session != relative_to.session() {
return Err(Error::InvalidState);
}
let space = space.get_pose(&self.data);
let relative_to = relative_to.get_pose(&self.data);
let pose = relative_to.inverse().pre_mul(&space);
Ok(Some(XRPose::new(&self.global(), pose)))
}
}

0 comments on commit 7e4b651

Please sign in to comment.
You can’t perform that action at this time.