Skip to content
Permalink
Browse files

Add XRRigidTransform.matrix

  • Loading branch information...
Manishearth committed Apr 3, 2019
1 parent 646647e commit e73920ee97907683c8d60224c03b6a67c2f0f613
@@ -9,6 +9,6 @@
interface XRRigidTransform {
readonly attribute DOMPointReadOnly position;
readonly attribute DOMPointReadOnly orientation;
// readonly attribute Float32Array matrix;
readonly attribute Float32Array matrix;
readonly attribute XRRigidTransform inverse;
};
@@ -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 {

0 comments on commit e73920e

Please sign in to comment.
You can’t perform that action at this time.