aboutsummaryrefslogtreecommitdiffstats
path: root/components/script/dom/xrrigidtransform.rs
diff options
context:
space:
mode:
authorManish Goregaokar <manishsmail@gmail.com>2019-03-21 14:50:02 -0700
committerManish Goregaokar <manishsmail@gmail.com>2019-03-25 15:35:20 -0700
commitd1d8e97c304b31f292c17d8d8f84a13cf12f74cd (patch)
tree3f4628bfcc3638821647e4ebbc355d558f3f621b /components/script/dom/xrrigidtransform.rs
parent1e1f527c8271463adea170eb9e93508fa0c261b5 (diff)
downloadservo-d1d8e97c304b31f292c17d8d8f84a13cf12f74cd.tar.gz
servo-d1d8e97c304b31f292c17d8d8f84a13cf12f74cd.zip
Add XRSpace::get_viewer_pose()
Diffstat (limited to 'components/script/dom/xrrigidtransform.rs')
-rw-r--r--components/script/dom/xrrigidtransform.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/components/script/dom/xrrigidtransform.rs b/components/script/dom/xrrigidtransform.rs
index 3f726475517..2999ce7a1b1 100644
--- a/components/script/dom/xrrigidtransform.rs
+++ b/components/script/dom/xrrigidtransform.rs
@@ -3,6 +3,7 @@
* 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::DOMPointReadOnlyBinding::DOMPointReadOnlyMethods;
use crate::dom::bindings::codegen::Bindings::XRRigidTransformBinding;
use crate::dom::bindings::codegen::Bindings::XRRigidTransformBinding::XRRigidTransformMethods;
use crate::dom::bindings::error::Fallible;
@@ -12,6 +13,7 @@ use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::dompointreadonly::DOMPointReadOnly;
use crate::dom::window::Window;
use dom_struct::dom_struct;
+use euclid::{Rotation3D, Transform3D};
#[dom_struct]
pub struct XRRigidTransform {
@@ -65,6 +67,7 @@ impl XRRigidTransform {
) -> Fallible<DomRoot<Self>> {
let global = window.global();
let position = DOMPointReadOnly::new_from_init(&global, &position);
+ // XXXManishearth normalize this
let orientation = DOMPointReadOnly::new_from_init(&global, &orientation);
Ok(XRRigidTransform::new(window, &position, &orientation))
}
@@ -80,3 +83,21 @@ impl XRRigidTransformMethods for XRRigidTransform {
DomRoot::from_ref(&self.orientation)
}
}
+
+impl XRRigidTransform {
+ pub fn matrix(&self) -> Transform3D<f64> {
+ // XXXManishearth compute this during initialization
+ let translate = Transform3D::create_translation(
+ self.position.X(),
+ self.position.Y(),
+ self.position.Z(),
+ );
+ let rotation = Rotation3D::unit_quaternion(
+ self.orientation.X(),
+ self.orientation.Y(),
+ self.orientation.Z(),
+ self.orientation.W(),
+ );
+ translate.pre_mul(&rotation.to_transform())
+ }
+}