Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement hit testing API #26171

Merged
merged 18 commits into from Apr 20, 2020
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

Add XRRay constructors

  • Loading branch information
Manishearth committed Apr 20, 2020
commit 977b36d855e323052ed8d7d42be7f80cfec83f7f
@@ -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;
@@ -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 {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.