Add XRRay(transform) constructor

This commit is contained in:
Manish Goregaokar 2020-04-08 16:34:22 -07:00
parent 977b36d855
commit e7ba4e5a47
3 changed files with 16 additions and 5 deletions

View file

@ -7,7 +7,7 @@
[SecureContext, Exposed=Window, Pref="dom.webxr.enabled"] [SecureContext, Exposed=Window, Pref="dom.webxr.enabled"]
interface XRRay { interface XRRay {
constructor(optional DOMPointInit origin = {}, optional DOMPointInit direction = {}); constructor(optional DOMPointInit origin = {}, optional DOMPointInit direction = {});
// constructor(XRRigidTransform transform); constructor(XRRigidTransform transform);
[SameObject] readonly attribute DOMPointReadOnly origin; [SameObject] readonly attribute DOMPointReadOnly origin;
[SameObject] readonly attribute DOMPointReadOnly direction; [SameObject] readonly attribute DOMPointReadOnly direction;
// [SameObject] readonly attribute Float32Array matrix; // [SameObject] readonly attribute Float32Array matrix;

View file

@ -9,6 +9,7 @@ use crate::dom::bindings::root::DomRoot;
use crate::dom::dompointreadonly::DOMPointReadOnly; use crate::dom::dompointreadonly::DOMPointReadOnly;
use crate::dom::globalscope::GlobalScope; use crate::dom::globalscope::GlobalScope;
use crate::dom::window::Window; use crate::dom::window::Window;
use crate::dom::xrrigidtransform::XRRigidTransform;
use dom_struct::dom_struct; use dom_struct::dom_struct;
use euclid::Vector3D; use euclid::Vector3D;
use webxr_api::{ApiSpace, Ray}; use webxr_api::{ApiSpace, Ray};
@ -45,6 +46,18 @@ impl XRRay {
Self::new(&window.global(), Ray { origin, direction }) Self::new(&window.global(), Ray { origin, direction })
} }
#[allow(non_snake_case)]
/// https://immersive-web.github.io/hit-test/#dom-xrray-xrray-transform
pub fn Constructor_(window: &Window, transform: &XRRigidTransform) -> DomRoot<Self> {
let transform = transform.transform();
let origin = transform.translation;
let direction = transform
.rotation
.transform_vector3d(Vector3D::new(0., 0., -1.));
Self::new(&window.global(), Ray { origin, direction })
}
} }
impl XRRayMethods for XRRay { impl XRRayMethods for XRRay {

View file

@ -47,8 +47,8 @@ use std::f64::consts::{FRAC_PI_2, PI};
use std::mem; use std::mem;
use std::rc::Rc; use std::rc::Rc;
use webxr_api::{ use webxr_api::{
self, util, Display, EnvironmentBlendMode, Event as XREvent, Frame, SelectEvent, SelectKind, self, util, ApiSpace, Display, EnvironmentBlendMode, Event as XREvent, Frame, SelectEvent,
Session, SessionId, View, Viewer, Visibility, SelectKind, Session, SessionId, View, Viewer, Visibility,
}; };
#[dom_struct] #[dom_struct]
@ -711,8 +711,6 @@ impl XRSessionMethods for XRSession {
} }
} }
#[derive(Clone, Copy, Debug)]
pub struct ApiSpace;
// The pose of an object in native-space. Should never be exposed. // The pose of an object in native-space. Should never be exposed.
pub type ApiPose = RigidTransform3D<f32, ApiSpace, webxr_api::Native>; pub type ApiPose = RigidTransform3D<f32, ApiSpace, webxr_api::Native>;
// The pose of the viewer in some api-space. // The pose of the viewer in some api-space.