Fill in XR frame/pose/view implementations

This commit is contained in:
Manish Goregaokar 2018-12-21 15:20:51 -08:00
parent 7e043a33f1
commit 28dff81dbf
12 changed files with 152 additions and 38 deletions

View file

@ -7,14 +7,20 @@ use crate::dom::bindings::codegen::Bindings::XRViewBinding::{XREye, XRViewMethod
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::xrsession::XRSession;
use dom_struct::dom_struct;
use js::jsapi::{Heap, JSContext, JSObject};
use std::ptr::NonNull;
use webvr_traits::WebVRFrameData;
#[dom_struct]
pub struct XRView {
reflector_: Reflector,
session: Dom<XRSession>,
eye: XREye,
proj: Heap<*mut JSObject>,
view: Heap<*mut JSObject>,
}
impl XRView {
@ -22,16 +28,34 @@ impl XRView {
XRView {
reflector_: Reflector::new(),
session: Dom::from_ref(session),
eye
eye,
proj: Heap::default(),
view: Heap::default(),
}
}
pub fn new(global: &GlobalScope, session: &XRSession, eye: XREye) -> DomRoot<XRView> {
reflect_dom_object(
pub fn new(
global: &GlobalScope,
session: &XRSession,
eye: XREye,
data: &WebVRFrameData,
) -> DomRoot<XRView> {
let ret = reflect_dom_object(
Box::new(XRView::new_inherited(session, eye)),
global,
XRViewBinding::Wrap,
)
);
let (proj, view) = if eye == XREye::Left {
(&data.left_projection_matrix, &data.left_view_matrix)
} else {
(&data.right_projection_matrix, &data.right_view_matrix)
};
let cx = global.get_cx();
create_typed_array(cx, proj, &ret.proj);
create_typed_array(cx, view, &ret.view);
ret
}
pub fn session(&self) -> &XRSession {
@ -44,4 +68,16 @@ impl XRViewMethods for XRView {
fn Eye(&self) -> XREye {
self.eye
}
}
#[allow(unsafe_code)]
/// https://immersive-web.github.io/webxr/#dom-xrview-projectionmatrix
unsafe fn ProjectionMatrix(&self, _cx: *mut JSContext) -> NonNull<JSObject> {
NonNull::new_unchecked(self.proj.get())
}
#[allow(unsafe_code)]
/// https://immersive-web.github.io/webxr/#dom-xrview-projectionmatrix
unsafe fn ViewMatrix(&self, _cx: *mut JSContext) -> NonNull<JSObject> {
NonNull::new_unchecked(self.view.get())
}
}