aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/xrrigidtransform.rs
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2019-03-26 00:08:19 -0700
committerManish Goregaokar <manishsmail@gmail.com>2019-03-26 00:09:15 -0700
commit4f128e47e53d2cad4e299d73a647f278f035aa30 (patch)
treee1b36d4a8e487b72e9570f9bc73fc5f3c84892c4 /components/script/dom/xrrigidtransform.rs
parent6fda2f28a6ad9ca63da3853ed5b6164b50948bd6 (diff)
downloadservo-4f128e47e53d2cad4e299d73a647f278f035aa30.tar.gz
servo-4f128e47e53d2cad4e299d73a647f278f035aa30.zip
Add XRRigidTransform::Inverse
Diffstat (limited to 'components/script/dom/xrrigidtransform.rs')
-rw-r--r--components/script/dom/xrrigidtransform.rs39
1 files changed, 38 insertions, 1 deletions
diff --git a/components/script/dom/xrrigidtransform.rs b/components/script/dom/xrrigidtransform.rs
index e019f90d678..ad7cbe7543b 100644
--- a/components/script/dom/xrrigidtransform.rs
+++ b/components/script/dom/xrrigidtransform.rs
@@ -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 {