mirror of
https://github.com/servo/servo.git
synced 2025-08-04 05:00:08 +01:00
Move XRRigidTransform to using RigidTransform3D
This commit is contained in:
parent
67694dc90d
commit
feb3517ad5
2 changed files with 23 additions and 38 deletions
|
@ -57,7 +57,8 @@ use devtools_traits::{CSSError, TimelineMarkerType, WorkerId};
|
||||||
use encoding_rs::{Decoder, Encoding};
|
use encoding_rs::{Decoder, Encoding};
|
||||||
use euclid::Length as EuclidLength;
|
use euclid::Length as EuclidLength;
|
||||||
use euclid::{
|
use euclid::{
|
||||||
Point2D, Rect, Rotation3D, Transform2D, Transform3D, TypedScale, TypedSize2D, Vector2D,
|
Point2D, Rect, RigidTransform3D, Rotation3D, Transform2D, Transform3D, TypedScale, TypedSize2D,
|
||||||
|
Vector2D,
|
||||||
};
|
};
|
||||||
use html5ever::buffer_queue::BufferQueue;
|
use html5ever::buffer_queue::BufferQueue;
|
||||||
use html5ever::{LocalName, Namespace, Prefix, QualName};
|
use html5ever::{LocalName, Namespace, Prefix, QualName};
|
||||||
|
@ -494,7 +495,8 @@ unsafe_no_jsmanaged_fields!(ResourceFetchTiming);
|
||||||
unsafe_no_jsmanaged_fields!(Timespec);
|
unsafe_no_jsmanaged_fields!(Timespec);
|
||||||
unsafe_no_jsmanaged_fields!(HTMLMediaElementFetchContext);
|
unsafe_no_jsmanaged_fields!(HTMLMediaElementFetchContext);
|
||||||
unsafe_no_jsmanaged_fields!(Rotation3D<f64>, Transform2D<f32>, Transform3D<f64>);
|
unsafe_no_jsmanaged_fields!(Rotation3D<f64>, Transform2D<f32>, Transform3D<f64>);
|
||||||
unsafe_no_jsmanaged_fields!(Point2D<f32>, Vector2D<f32>, Rect<Au>, Rect<f32>);
|
unsafe_no_jsmanaged_fields!(Point2D<f32>, Vector2D<f32>, Rect<Au>);
|
||||||
|
unsafe_no_jsmanaged_fields!(Rect<f32>, RigidTransform3D<f64>);
|
||||||
|
|
||||||
unsafe impl<'a> JSTraceable for &'a str {
|
unsafe impl<'a> JSTraceable for &'a str {
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -13,7 +13,7 @@ use crate::dom::bindings::root::{Dom, DomRoot};
|
||||||
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;
|
||||||
use euclid::{Rotation3D, Transform3D};
|
use euclid::{RigidTransform3D, Rotation3D, Transform3D, Vector3D};
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct XRRigidTransform {
|
pub struct XRRigidTransform {
|
||||||
|
@ -21,9 +21,7 @@ pub struct XRRigidTransform {
|
||||||
position: Dom<DOMPointReadOnly>,
|
position: Dom<DOMPointReadOnly>,
|
||||||
orientation: Dom<DOMPointReadOnly>,
|
orientation: Dom<DOMPointReadOnly>,
|
||||||
#[ignore_malloc_size_of = "defined in euclid"]
|
#[ignore_malloc_size_of = "defined in euclid"]
|
||||||
translate: Transform3D<f64>,
|
transform: RigidTransform3D<f64>,
|
||||||
#[ignore_malloc_size_of = "defined in euclid"]
|
|
||||||
rotate: Rotation3D<f64>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XRRigidTransform {
|
impl XRRigidTransform {
|
||||||
|
@ -31,7 +29,7 @@ impl XRRigidTransform {
|
||||||
position: &DOMPointReadOnly,
|
position: &DOMPointReadOnly,
|
||||||
orientation: &DOMPointReadOnly,
|
orientation: &DOMPointReadOnly,
|
||||||
) -> XRRigidTransform {
|
) -> XRRigidTransform {
|
||||||
let translate = Transform3D::create_translation(
|
let translate = Vector3D::new(
|
||||||
position.X() as f64,
|
position.X() as f64,
|
||||||
position.Y() as f64,
|
position.Y() as f64,
|
||||||
position.Z() as f64,
|
position.Z() as f64,
|
||||||
|
@ -42,12 +40,12 @@ impl XRRigidTransform {
|
||||||
orientation.Z() as f64,
|
orientation.Z() as f64,
|
||||||
orientation.W() 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: Dom::from_ref(position),
|
||||||
orientation: Dom::from_ref(orientation),
|
orientation: Dom::from_ref(orientation),
|
||||||
translate,
|
transform,
|
||||||
rotate,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -101,37 +99,22 @@ impl XRRigidTransformMethods for XRRigidTransform {
|
||||||
}
|
}
|
||||||
// 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> {
|
||||||
// An XRRigidTransform is a rotation and a translation,
|
|
||||||
// i.e. T * R
|
|
||||||
//
|
|
||||||
// Its inverse is (T * R)^-1
|
|
||||||
// = R^-1 * T^-1
|
|
||||||
// = R^-1 * T^-1 * (R * R^-1)
|
|
||||||
// = (R^-1 * T^-1 * R) * R^-1
|
|
||||||
// = T' * R^-1
|
|
||||||
// = T' * R'
|
|
||||||
//
|
|
||||||
// (R^-1 * T^-1 * R) is a translation matrix, and R^-1 is a
|
|
||||||
// rotation matrix, so we can use these in the new rigid transform
|
|
||||||
let r_1 = self.rotate.inverse();
|
|
||||||
let t_1 = self
|
|
||||||
.translate
|
|
||||||
.inverse()
|
|
||||||
.expect("translation matrices should be invertible");
|
|
||||||
let t_p = r_1
|
|
||||||
.to_transform()
|
|
||||||
.post_mul(&t_1)
|
|
||||||
.post_mul(&self.rotate.to_transform());
|
|
||||||
|
|
||||||
let global = self.global();
|
let global = self.global();
|
||||||
let position =
|
let inverse = self.transform.inverse();
|
||||||
DOMPointReadOnly::new(&global, t_p.m41.into(), t_p.m42.into(), t_p.m43.into(), 1.);
|
|
||||||
|
let position = DOMPointReadOnly::new(
|
||||||
|
&global,
|
||||||
|
inverse.translation.x.into(),
|
||||||
|
inverse.translation.y.into(),
|
||||||
|
inverse.translation.z.into(),
|
||||||
|
1.,
|
||||||
|
);
|
||||||
let orientation = DOMPointReadOnly::new(
|
let orientation = DOMPointReadOnly::new(
|
||||||
&global,
|
&global,
|
||||||
r_1.i.into(),
|
inverse.rotation.i.into(),
|
||||||
r_1.j.into(),
|
inverse.rotation.j.into(),
|
||||||
r_1.k.into(),
|
inverse.rotation.k.into(),
|
||||||
r_1.r.into(),
|
inverse.rotation.r.into(),
|
||||||
);
|
);
|
||||||
XRRigidTransform::new(global.as_window(), &position, &orientation)
|
XRRigidTransform::new(global.as_window(), &position, &orientation)
|
||||||
}
|
}
|
||||||
|
@ -141,6 +124,6 @@ impl XRRigidTransform {
|
||||||
pub fn matrix(&self) -> Transform3D<f64> {
|
pub fn matrix(&self) -> Transform3D<f64> {
|
||||||
// Spec says the orientation applies first,
|
// Spec says the orientation applies first,
|
||||||
// so post-multiply (?)
|
// so post-multiply (?)
|
||||||
self.translate.post_mul(&self.rotate.to_transform())
|
self.transform.to_transform()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue