Skip to content
Permalink
Browse files

Validate spaces passed to getViewerPose()

  • Loading branch information...
Manishearth committed Apr 4, 2019
1 parent e33896f commit 3d790278f1033c1fbefd3d227ff3da7d842fb24d
@@ -8,6 +8,6 @@
interface XRFrame {
readonly attribute XRSession session;

XRViewerPose? getViewerPose(XRReferenceSpace referenceSpace);
[Throws] XRViewerPose? getViewerPose(XRReferenceSpace referenceSpace);
// XRInputPose? getInputPose(XRInputSource inputSource, optional XRReferenceSpace referenceSpace);
};
@@ -4,6 +4,8 @@

use crate::dom::bindings::codegen::Bindings::XRFrameBinding;
use crate::dom::bindings::codegen::Bindings::XRFrameBinding::XRFrameMethods;
use crate::dom::bindings::error::Error;
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;
@@ -50,13 +52,19 @@ impl XRFrameMethods for XRFrame {
}

/// https://immersive-web.github.io/webxr/#dom-xrframe-getviewerpose
fn GetViewerPose(&self, reference: &XRReferenceSpace) -> Option<DomRoot<XRViewerPose>> {
fn GetViewerPose(
&self,
reference: &XRReferenceSpace,
) -> Result<Option<DomRoot<XRViewerPose>>, Error> {
if self.session != reference.upcast::<XRSpace>().session() {
return Err(Error::InvalidState);
}
let pose = reference.get_viewer_pose(&self.data);
Some(XRViewerPose::new(
Ok(Some(XRViewerPose::new(
&self.global(),
&self.session,
pose,
&self.data,
))
)))
}
}
@@ -44,7 +44,6 @@ impl XRSpace {
/// 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
#[allow(unused)]
pub fn get_pose(&self, base_pose: &WebVRFrameData) -> RigidTransform3D<f64> {
if let Some(reference) = self.downcast::<XRReferenceSpace>() {
reference.get_pose(base_pose)
@@ -65,4 +64,8 @@ impl XRSpace {
);
RigidTransform3D::new(rotation, translation)
}

pub fn session(&self) -> &XRSession {
&self.session
}
}

0 comments on commit 3d79027

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