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
|
@ -46,7 +46,8 @@ impl XRRigidTransform {
|
|||
reflector_: Reflector::new(),
|
||||
position: Dom::from_ref(position),
|
||||
orientation: Dom::from_ref(orientation),
|
||||
translate, rotate
|
||||
translate,
|
||||
rotate,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -98,6 +99,42 @@ impl XRRigidTransformMethods for XRRigidTransform {
|
|||
fn Orientation(&self) -> DomRoot<DOMPointReadOnly> {
|
||||
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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue