diff options
author | Manish Goregaokar <manishsmail@gmail.com> | 2020-04-08 16:00:23 -0700 |
---|---|---|
committer | Manish Goregaokar <manishsmail@gmail.com> | 2020-04-19 20:29:14 -0700 |
commit | 977b36d855e323052ed8d7d42be7f80cfec83f7f (patch) | |
tree | 14fa3bada9f302cecad613d780d6ca557db74de3 | |
parent | 98ff97783e7bc083b3f0dd461c6743bd34aa1680 (diff) | |
download | servo-977b36d855e323052ed8d7d42be7f80cfec83f7f.tar.gz servo-977b36d855e323052ed8d7d42be7f80cfec83f7f.zip |
Add XRRay constructors
-rw-r--r-- | components/script/dom/webidls/XRRay.webidl | 2 | ||||
-rw-r--r-- | components/script/dom/xrray.rs | 17 |
2 files changed, 18 insertions, 1 deletions
diff --git a/components/script/dom/webidls/XRRay.webidl b/components/script/dom/webidls/XRRay.webidl index 43963b7020d..317f6609c08 100644 --- a/components/script/dom/webidls/XRRay.webidl +++ b/components/script/dom/webidls/XRRay.webidl @@ -6,7 +6,7 @@ [SecureContext, Exposed=Window, Pref="dom.webxr.enabled"] interface XRRay { - // constructor(optional DOMPointInit origin, optional DOMPointInit direction); + constructor(optional DOMPointInit origin = {}, optional DOMPointInit direction = {}); // constructor(XRRigidTransform transform); [SameObject] readonly attribute DOMPointReadOnly origin; [SameObject] readonly attribute DOMPointReadOnly direction; diff --git a/components/script/dom/xrray.rs b/components/script/dom/xrray.rs index 30327ea0a15..2cf7b2b3a30 100644 --- a/components/script/dom/xrray.rs +++ b/components/script/dom/xrray.rs @@ -2,12 +2,15 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ +use crate::dom::bindings::codegen::Bindings::DOMPointBinding::DOMPointInit; use crate::dom::bindings::codegen::Bindings::XRRayBinding::XRRayMethods; use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector}; use crate::dom::bindings::root::DomRoot; use crate::dom::dompointreadonly::DOMPointReadOnly; use crate::dom::globalscope::GlobalScope; +use crate::dom::window::Window; use dom_struct::dom_struct; +use euclid::Vector3D; use webxr_api::{ApiSpace, Ray}; #[dom_struct] @@ -28,6 +31,20 @@ impl XRRay { pub fn new(global: &GlobalScope, ray: Ray<ApiSpace>) -> DomRoot<XRRay> { reflect_dom_object(Box::new(XRRay::new_inherited(ray)), global) } + + #[allow(non_snake_case)] + /// https://immersive-web.github.io/hit-test/#dom-xrray-xrray + pub fn Constructor( + window: &Window, + origin: &DOMPointInit, + direction: &DOMPointInit, + ) -> DomRoot<Self> { + let origin = Vector3D::new(origin.x as f32, origin.y as f32, origin.z as f32); + let direction = + Vector3D::new(direction.x as f32, direction.y as f32, direction.z as f32).normalize(); + + Self::new(&window.global(), Ray { origin, direction }) + } } impl XRRayMethods for XRRay { |