mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Fill in XR frame/pose/view implementations
This commit is contained in:
parent
7e043a33f1
commit
28dff81dbf
12 changed files with 152 additions and 38 deletions
|
@ -3,28 +3,63 @@
|
|||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use crate::dom::bindings::codegen::Bindings::XRFrameBinding;
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
||||
use crate::dom::bindings::root::DomRoot;
|
||||
use crate::dom::bindings::codegen::Bindings::XRFrameBinding::XRFrameMethods;
|
||||
use crate::dom::bindings::codegen::Bindings::XRViewBinding::XREye;
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::xrreferencespace::XRReferenceSpace;
|
||||
use crate::dom::xrsession::XRSession;
|
||||
use crate::dom::xrview::XRView;
|
||||
use crate::dom::xrviewerpose::XRViewerPose;
|
||||
use dom_struct::dom_struct;
|
||||
use webvr_traits::WebVRFrameData;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct XRFrame {
|
||||
reflector_: Reflector,
|
||||
session: Dom<XRSession>,
|
||||
#[ignore_malloc_size_of = "defined in rust-webvr"]
|
||||
data: WebVRFrameData,
|
||||
}
|
||||
|
||||
impl XRFrame {
|
||||
fn new_inherited() -> XRFrame {
|
||||
fn new_inherited(session: &XRSession, data: WebVRFrameData) -> XRFrame {
|
||||
XRFrame {
|
||||
reflector_: Reflector::new(),
|
||||
session: Dom::from_ref(session),
|
||||
data,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn new(global: &GlobalScope) -> DomRoot<XRFrame> {
|
||||
pub fn new(
|
||||
global: &GlobalScope,
|
||||
session: &XRSession,
|
||||
data: WebVRFrameData,
|
||||
) -> DomRoot<XRFrame> {
|
||||
reflect_dom_object(
|
||||
Box::new(XRFrame::new_inherited()),
|
||||
Box::new(XRFrame::new_inherited(session, data)),
|
||||
global,
|
||||
XRFrameBinding::Wrap,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl XRFrameMethods for XRFrame {
|
||||
fn Session(&self) -> DomRoot<XRSession> {
|
||||
DomRoot::from_ref(&self.session)
|
||||
}
|
||||
|
||||
fn GetViewerPose(&self, reference: Option<&XRReferenceSpace>) -> Option<DomRoot<XRViewerPose>> {
|
||||
// We assume the reference space is eye level for now
|
||||
// since it's the only one 3DOF devices support
|
||||
if reference.is_some() {
|
||||
// it's not possible to obtain a reference
|
||||
// space at all yet
|
||||
return None;
|
||||
}
|
||||
let left = XRView::new(&self.global(), &self.session, XREye::Left, &self.data);
|
||||
let right = XRView::new(&self.global(), &self.session, XREye::Right, &self.data);
|
||||
Some(XRViewerPose::new(&self.global(), &left, &right))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue