mirror of
https://github.com/servo/servo.git
synced 2025-07-23 07:13:52 +01:00
Add XRRigidTransform::Inverse
This commit is contained in:
parent
6fda2f28a6
commit
4f128e47e5
3 changed files with 42 additions and 2 deletions
|
@ -56,7 +56,9 @@ use cssparser::RGBA;
|
||||||
use devtools_traits::{CSSError, TimelineMarkerType, WorkerId};
|
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::{Point2D, Rect, Rotation3D, Transform2D, Transform3D, TypedScale, TypedSize2D, Vector2D};
|
use euclid::{
|
||||||
|
Point2D, Rect, 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};
|
||||||
use http::header::HeaderMap;
|
use http::header::HeaderMap;
|
||||||
|
|
|
@ -10,4 +10,5 @@ interface XRRigidTransform {
|
||||||
readonly attribute DOMPointReadOnly position;
|
readonly attribute DOMPointReadOnly position;
|
||||||
readonly attribute DOMPointReadOnly orientation;
|
readonly attribute DOMPointReadOnly orientation;
|
||||||
// readonly attribute Float32Array matrix;
|
// readonly attribute Float32Array matrix;
|
||||||
|
XRRigidTransform inverse();
|
||||||
};
|
};
|
||||||
|
|
|
@ -46,7 +46,8 @@ impl 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, rotate
|
translate,
|
||||||
|
rotate,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,6 +99,42 @@ impl XRRigidTransformMethods for XRRigidTransform {
|
||||||
fn Orientation(&self) -> DomRoot<DOMPointReadOnly> {
|
fn Orientation(&self) -> DomRoot<DOMPointReadOnly> {
|
||||||
DomRoot::from_ref(&self.orientation)
|
DomRoot::from_ref(&self.orientation)
|
||||||
}
|
}
|
||||||
|
// https://immersive-web.github.io/webxr/#dom-xrrigidtransform-inverse
|
||||||
|
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 position =
|
||||||
|
DOMPointReadOnly::new(&global, t_p.m41.into(), t_p.m42.into(), t_p.m43.into(), 1.);
|
||||||
|
let orientation = DOMPointReadOnly::new(
|
||||||
|
&global,
|
||||||
|
r_1.i.into(),
|
||||||
|
r_1.j.into(),
|
||||||
|
r_1.k.into(),
|
||||||
|
r_1.r.into(),
|
||||||
|
);
|
||||||
|
XRRigidTransform::new(global.as_window(), &position, &orientation)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl XRRigidTransform {
|
impl XRRigidTransform {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue