Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update XR code to use rigid transforms and new pose/transform stuff from the spec #23159

Merged
merged 13 commits into from Apr 4, 2019

Add XRRigidTransform.matrix

  • Loading branch information
Manishearth committed Apr 4, 2019
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 {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.