mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Make XRRigidTransform.position/orientation lazy, default to using euclid things
This commit is contained in:
parent
feb3517ad5
commit
e296185c53
3 changed files with 28 additions and 80 deletions
|
@ -2,7 +2,6 @@
|
||||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
* 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/. */
|
* 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::DOMPointReadOnlyBinding::{
|
use crate::dom::bindings::codegen::Bindings::DOMPointReadOnlyBinding::{
|
||||||
DOMPointReadOnlyMethods, Wrap,
|
DOMPointReadOnlyMethods, Wrap,
|
||||||
};
|
};
|
||||||
|
@ -51,10 +50,6 @@ impl DOMPointReadOnly {
|
||||||
) -> Fallible<DomRoot<DOMPointReadOnly>> {
|
) -> Fallible<DomRoot<DOMPointReadOnly>> {
|
||||||
Ok(DOMPointReadOnly::new(global, x, y, z, w))
|
Ok(DOMPointReadOnly::new(global, x, y, z, w))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn new_from_init(global: &GlobalScope, p: &DOMPointInit) -> DomRoot<DOMPointReadOnly> {
|
|
||||||
DOMPointReadOnly::new(global, p.x, p.y, p.z, p.w)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl DOMPointReadOnlyMethods for DOMPointReadOnly {
|
impl DOMPointReadOnlyMethods for DOMPointReadOnly {
|
||||||
|
|
|
@ -7,7 +7,6 @@ use crate::dom::bindings::codegen::Bindings::XRReferenceSpaceBinding::XRReferenc
|
||||||
use crate::dom::bindings::inheritance::Castable;
|
use crate::dom::bindings::inheritance::Castable;
|
||||||
use crate::dom::bindings::reflector::reflect_dom_object;
|
use crate::dom::bindings::reflector::reflect_dom_object;
|
||||||
use crate::dom::bindings::root::{DomRoot, MutDom};
|
use crate::dom::bindings::root::{DomRoot, MutDom};
|
||||||
use crate::dom::dompointreadonly::DOMPointReadOnly;
|
|
||||||
use crate::dom::window::Window;
|
use crate::dom::window::Window;
|
||||||
use crate::dom::xrrigidtransform::XRRigidTransform;
|
use crate::dom::xrrigidtransform::XRRigidTransform;
|
||||||
use crate::dom::xrsession::XRSession;
|
use crate::dom::xrsession::XRSession;
|
||||||
|
@ -31,21 +30,6 @@ impl XRReferenceSpace {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
|
||||||
pub fn new(
|
|
||||||
global: &Window,
|
|
||||||
session: &XRSession,
|
|
||||||
position: &DOMPointReadOnly,
|
|
||||||
orientation: &DOMPointReadOnly,
|
|
||||||
) -> DomRoot<XRReferenceSpace> {
|
|
||||||
let transform = XRRigidTransform::new(global, position, orientation);
|
|
||||||
reflect_dom_object(
|
|
||||||
Box::new(XRReferenceSpace::new_inherited(session, &transform)),
|
|
||||||
global,
|
|
||||||
XRReferenceSpaceBinding::Wrap,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub fn identity(global: &Window, session: &XRSession) -> DomRoot<XRReferenceSpace> {
|
pub fn identity(global: &Window, session: &XRSession) -> DomRoot<XRReferenceSpace> {
|
||||||
let transform = XRRigidTransform::identity(global);
|
let transform = XRRigidTransform::identity(global);
|
||||||
|
|
|
@ -3,13 +3,12 @@
|
||||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
* 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::DOMPointBinding::DOMPointInit;
|
||||||
use crate::dom::bindings::codegen::Bindings::DOMPointReadOnlyBinding::DOMPointReadOnlyBinding::DOMPointReadOnlyMethods;
|
|
||||||
use crate::dom::bindings::codegen::Bindings::XRRigidTransformBinding;
|
use crate::dom::bindings::codegen::Bindings::XRRigidTransformBinding;
|
||||||
use crate::dom::bindings::codegen::Bindings::XRRigidTransformBinding::XRRigidTransformMethods;
|
use crate::dom::bindings::codegen::Bindings::XRRigidTransformBinding::XRRigidTransformMethods;
|
||||||
use crate::dom::bindings::error::Fallible;
|
use crate::dom::bindings::error::Fallible;
|
||||||
use crate::dom::bindings::reflector::DomObject;
|
use crate::dom::bindings::reflector::DomObject;
|
||||||
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
||||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
use crate::dom::bindings::root::{DomRoot, MutNullableDom};
|
||||||
use crate::dom::dompointreadonly::DOMPointReadOnly;
|
use crate::dom::dompointreadonly::DOMPointReadOnly;
|
||||||
use crate::dom::window::Window;
|
use crate::dom::window::Window;
|
||||||
use dom_struct::dom_struct;
|
use dom_struct::dom_struct;
|
||||||
|
@ -18,45 +17,26 @@ use euclid::{RigidTransform3D, Rotation3D, Transform3D, Vector3D};
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct XRRigidTransform {
|
pub struct XRRigidTransform {
|
||||||
reflector_: Reflector,
|
reflector_: Reflector,
|
||||||
position: Dom<DOMPointReadOnly>,
|
position: MutNullableDom<DOMPointReadOnly>,
|
||||||
orientation: Dom<DOMPointReadOnly>,
|
orientation: MutNullableDom<DOMPointReadOnly>,
|
||||||
#[ignore_malloc_size_of = "defined in euclid"]
|
#[ignore_malloc_size_of = "defined in euclid"]
|
||||||
transform: RigidTransform3D<f64>,
|
transform: RigidTransform3D<f64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XRRigidTransform {
|
impl XRRigidTransform {
|
||||||
fn new_inherited(
|
fn new_inherited(transform: RigidTransform3D<f64>) -> XRRigidTransform {
|
||||||
position: &DOMPointReadOnly,
|
|
||||||
orientation: &DOMPointReadOnly,
|
|
||||||
) -> XRRigidTransform {
|
|
||||||
let translate = Vector3D::new(
|
|
||||||
position.X() as f64,
|
|
||||||
position.Y() as f64,
|
|
||||||
position.Z() as f64,
|
|
||||||
);
|
|
||||||
let rotate = Rotation3D::unit_quaternion(
|
|
||||||
orientation.X() as f64,
|
|
||||||
orientation.Y() as f64,
|
|
||||||
orientation.Z() as f64,
|
|
||||||
orientation.W() as f64,
|
|
||||||
);
|
|
||||||
let transform = RigidTransform3D::new(rotate, translate);
|
|
||||||
XRRigidTransform {
|
XRRigidTransform {
|
||||||
reflector_: Reflector::new(),
|
reflector_: Reflector::new(),
|
||||||
position: Dom::from_ref(position),
|
position: MutNullableDom::default(),
|
||||||
orientation: Dom::from_ref(orientation),
|
orientation: MutNullableDom::default(),
|
||||||
transform,
|
transform,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub fn new(
|
pub fn new(global: &Window, transform: RigidTransform3D<f64>) -> DomRoot<XRRigidTransform> {
|
||||||
global: &Window,
|
|
||||||
position: &DOMPointReadOnly,
|
|
||||||
orientation: &DOMPointReadOnly,
|
|
||||||
) -> DomRoot<XRRigidTransform> {
|
|
||||||
reflect_dom_object(
|
reflect_dom_object(
|
||||||
Box::new(XRRigidTransform::new_inherited(position, orientation)),
|
Box::new(XRRigidTransform::new_inherited(transform)),
|
||||||
global,
|
global,
|
||||||
XRRigidTransformBinding::Wrap,
|
XRRigidTransformBinding::Wrap,
|
||||||
)
|
)
|
||||||
|
@ -64,14 +44,8 @@ impl XRRigidTransform {
|
||||||
|
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
pub fn identity(window: &Window) -> DomRoot<XRRigidTransform> {
|
pub fn identity(window: &Window) -> DomRoot<XRRigidTransform> {
|
||||||
let global = window.global();
|
let transform = RigidTransform3D::identity();
|
||||||
let position = DOMPointReadOnly::new(&global, 0., 0., 0., 1.);
|
XRRigidTransform::new(window, transform)
|
||||||
let orientation = DOMPointReadOnly::new(&global, 0., 0., 0., 1.);
|
|
||||||
reflect_dom_object(
|
|
||||||
Box::new(XRRigidTransform::new_inherited(&position, &orientation)),
|
|
||||||
window,
|
|
||||||
XRRigidTransformBinding::Wrap,
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://immersive-web.github.io/webxr/#dom-xrrigidtransform-xrrigidtransform
|
// https://immersive-web.github.io/webxr/#dom-xrrigidtransform-xrrigidtransform
|
||||||
|
@ -81,42 +55,37 @@ impl XRRigidTransform {
|
||||||
orientation: &DOMPointInit,
|
orientation: &DOMPointInit,
|
||||||
) -> Fallible<DomRoot<Self>> {
|
) -> Fallible<DomRoot<Self>> {
|
||||||
let global = window.global();
|
let global = window.global();
|
||||||
let position = DOMPointReadOnly::new_from_init(&global, &position);
|
let translate = Vector3D::new(position.x as f64, position.y as f64, position.z as f64);
|
||||||
// XXXManishearth normalize this
|
let rotate = Rotation3D::unit_quaternion(
|
||||||
let orientation = DOMPointReadOnly::new_from_init(&global, &orientation);
|
orientation.x as f64,
|
||||||
Ok(XRRigidTransform::new(window, &position, &orientation))
|
orientation.y as f64,
|
||||||
|
orientation.z as f64,
|
||||||
|
orientation.w as f64,
|
||||||
|
);
|
||||||
|
let transform = RigidTransform3D::new(rotate, translate);
|
||||||
|
Ok(XRRigidTransform::new(window, transform))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XRRigidTransformMethods for XRRigidTransform {
|
impl XRRigidTransformMethods for XRRigidTransform {
|
||||||
// https://immersive-web.github.io/webxr/#dom-xrrigidtransform-position
|
// https://immersive-web.github.io/webxr/#dom-xrrigidtransform-position
|
||||||
fn Position(&self) -> DomRoot<DOMPointReadOnly> {
|
fn Position(&self) -> DomRoot<DOMPointReadOnly> {
|
||||||
DomRoot::from_ref(&self.position)
|
self.position.or_init(|| {
|
||||||
|
let t = &self.transform.translation;
|
||||||
|
DOMPointReadOnly::new(&self.global(), t.x, t.y, t.z, 1.0)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
// https://immersive-web.github.io/webxr/#dom-xrrigidtransform-orientation
|
// https://immersive-web.github.io/webxr/#dom-xrrigidtransform-orientation
|
||||||
fn Orientation(&self) -> DomRoot<DOMPointReadOnly> {
|
fn Orientation(&self) -> DomRoot<DOMPointReadOnly> {
|
||||||
DomRoot::from_ref(&self.orientation)
|
self.position.or_init(|| {
|
||||||
|
let r = &self.transform.rotation;
|
||||||
|
DOMPointReadOnly::new(&self.global(), r.i, r.j, r.k, r.r)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
// https://immersive-web.github.io/webxr/#dom-xrrigidtransform-inverse
|
// https://immersive-web.github.io/webxr/#dom-xrrigidtransform-inverse
|
||||||
fn Inverse(&self) -> DomRoot<XRRigidTransform> {
|
fn Inverse(&self) -> DomRoot<XRRigidTransform> {
|
||||||
let global = self.global();
|
let global = self.global();
|
||||||
let inverse = self.transform.inverse();
|
XRRigidTransform::new(global.as_window(), self.transform.inverse())
|
||||||
|
|
||||||
let position = DOMPointReadOnly::new(
|
|
||||||
&global,
|
|
||||||
inverse.translation.x.into(),
|
|
||||||
inverse.translation.y.into(),
|
|
||||||
inverse.translation.z.into(),
|
|
||||||
1.,
|
|
||||||
);
|
|
||||||
let orientation = DOMPointReadOnly::new(
|
|
||||||
&global,
|
|
||||||
inverse.rotation.i.into(),
|
|
||||||
inverse.rotation.j.into(),
|
|
||||||
inverse.rotation.k.into(),
|
|
||||||
inverse.rotation.r.into(),
|
|
||||||
);
|
|
||||||
XRRigidTransform::new(global.as_window(), &position, &orientation)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue