diff options
author | Manish Goregaokar <manishsmail@gmail.com> | 2019-04-03 12:32:47 -0700 |
---|---|---|
committer | Manish Goregaokar <manishsmail@gmail.com> | 2019-04-03 23:55:33 -0700 |
commit | e73920ee97907683c8d60224c03b6a67c2f0f613 (patch) | |
tree | 4e89e03875ba1e850d895f1fe65967c566c1a38e /components/script/dom/xrrigidtransform.rs | |
parent | 646647e8d9cb2f679c872495ecf0fdc820243cb1 (diff) | |
download | servo-e73920ee97907683c8d60224c03b6a67c2f0f613.tar.gz servo-e73920ee97907683c8d60224c03b6a67c2f0f613.zip |
Add XRRigidTransform.matrix
Diffstat (limited to 'components/script/dom/xrrigidtransform.rs')
-rw-r--r-- | components/script/dom/xrrigidtransform.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/components/script/dom/xrrigidtransform.rs b/components/script/dom/xrrigidtransform.rs index 3c2cd955d47..030905d84fa 100644 --- a/components/script/dom/xrrigidtransform.rs +++ b/components/script/dom/xrrigidtransform.rs @@ -12,9 +12,12 @@ use crate::dom::bindings::reflector::{reflect_dom_object, Reflector}; use crate::dom::bindings::root::{DomRoot, MutNullableDom}; use crate::dom::dompointreadonly::DOMPointReadOnly; use crate::dom::globalscope::GlobalScope; +use crate::dom::vrframedata::create_typed_array; use crate::dom::window::Window; use dom_struct::dom_struct; use euclid::{RigidTransform3D, Rotation3D, Vector3D}; +use js::jsapi::{Heap, JSContext, JSObject}; +use std::ptr::NonNull; #[dom_struct] pub struct XRRigidTransform { @@ -24,6 +27,7 @@ pub struct XRRigidTransform { #[ignore_malloc_size_of = "defined in euclid"] transform: RigidTransform3D<f64>, inverse: MutNullableDom<XRRigidTransform>, + matrix: Heap<*mut JSObject>, } impl XRRigidTransform { @@ -34,6 +38,7 @@ impl XRRigidTransform { orientation: MutNullableDom::default(), transform, inverse: MutNullableDom::default(), + matrix: Heap::default(), } } @@ -98,6 +103,18 @@ impl XRRigidTransformMethods for XRRigidTransform { self.inverse .or_init(|| XRRigidTransform::new(&self.global(), self.transform.inverse())) } + // https://immersive-web.github.io/webxr/#dom-xrrigidtransform-matrix + #[allow(unsafe_code)] + unsafe fn Matrix(&self, _cx: *mut JSContext) -> NonNull<JSObject> { + if self.matrix.get().is_null() { + let cx = self.global().get_cx(); + // According to the spec all matrices are column-major, + // however euclid uses row vectors so we use .to_row_major_array() + let arr = self.transform.to_transform().cast().to_row_major_array(); + create_typed_array(cx, &arr, &self.matrix); + } + NonNull::new(self.matrix.get()).unwrap() + } } impl XRRigidTransform { |