Skip to content
Permalink
Browse files

Add XRView.transform

  • Loading branch information...
Manishearth committed Apr 3, 2019
1 parent eb837d1 commit 646647e8d9cb2f679c872495ecf0fdc820243cb1
@@ -14,5 +14,5 @@ interface XRView {
readonly attribute XREye eye;
readonly attribute Float32Array projectionMatrix;
readonly attribute Float32Array viewMatrix;
// readonly attribute XRRigidTransform transform;
readonly attribute XRRigidTransform transform;
};
@@ -95,9 +95,8 @@ impl XRRigidTransformMethods for XRRigidTransform {
}
// https://immersive-web.github.io/webxr/#dom-xrrigidtransform-inverse
fn Inverse(&self) -> DomRoot<XRRigidTransform> {
self.inverse.or_init(|| {
XRRigidTransform::new(&self.global(), self.transform.inverse())
})
self.inverse
.or_init(|| XRRigidTransform::new(&self.global(), self.transform.inverse()))
}
}

@@ -8,6 +8,7 @@ use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::globalscope::GlobalScope;
use crate::dom::vrframedata::create_typed_array;
use crate::dom::xrrigidtransform::XRRigidTransform;
use crate::dom::xrsession::XRSession;
use dom_struct::dom_struct;
use euclid::{RigidTransform3D, Vector3D};
@@ -22,16 +23,18 @@ pub struct XRView {
eye: XREye,
proj: Heap<*mut JSObject>,
view: Heap<*mut JSObject>,
transform: Dom<XRRigidTransform>,
}

impl XRView {
fn new_inherited(session: &XRSession, eye: XREye) -> XRView {
fn new_inherited(session: &XRSession, transform: &XRRigidTransform, eye: XREye) -> XRView {
XRView {
reflector_: Reflector::new(),
session: Dom::from_ref(session),
eye,
proj: Heap::default(),
view: Heap::default(),
transform: Dom::from_ref(transform),
}
}

@@ -43,12 +46,6 @@ impl XRView {
pose: &RigidTransform3D<f64>,
data: &WebVRFrameData,
) -> DomRoot<XRView> {
let ret = reflect_dom_object(
Box::new(XRView::new_inherited(session, eye)),
global,
XRViewBinding::Wrap,
);

let vr_display = session.display();

// XXXManishearth compute and cache projection matrices on the Display
@@ -65,11 +62,15 @@ impl XRView {
};

let offset = Vector3D::new(offset[0] as f64, offset[1] as f64, offset[2] as f64);
let view = pose
.post_mul(&offset.into())
.to_transform()
.cast()
.to_column_major_array();
let transform = pose.post_mul(&offset.into());
let view = transform.to_transform().cast().to_column_major_array();
let transform = XRRigidTransform::new(global, transform);

let ret = reflect_dom_object(
Box::new(XRView::new_inherited(session, &transform, eye)),
global,
XRViewBinding::Wrap,
);

let cx = global.get_cx();
unsafe {
@@ -101,4 +102,9 @@ impl XRViewMethods for XRView {
unsafe fn ViewMatrix(&self, _cx: *mut JSContext) -> NonNull<JSObject> {
NonNull::new(self.view.get()).unwrap()
}

/// https://immersive-web.github.io/webxr/#dom-xrview-transform
fn Transform(&self) -> DomRoot<XRRigidTransform> {
DomRoot::from_ref(&self.transform)
}
}

0 comments on commit 646647e

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