mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Add XRInputSource.targetRaySpace
This commit is contained in:
parent
e5716624d4
commit
d4a6a4987d
5 changed files with 55 additions and 13 deletions
|
@ -7,12 +7,13 @@ use crate::dom::bindings::codegen::Bindings::XRInputSourceBinding;
|
|||
use crate::dom::bindings::codegen::Bindings::XRInputSourceBinding::{
|
||||
XRHandedness, XRInputSourceMethods,
|
||||
};
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, Reflector};
|
||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||
use crate::dom::bindings::reflector::{reflect_dom_object, DomObject, Reflector};
|
||||
use crate::dom::bindings::root::{Dom, DomRoot, MutNullableDom};
|
||||
use crate::dom::globalscope::GlobalScope;
|
||||
use crate::dom::xrsession::XRSession;
|
||||
use crate::dom::xrspace::XRSpace;
|
||||
use dom_struct::dom_struct;
|
||||
use webvr_traits::{WebVRGamepadData, WebVRGamepadHand, WebVRGamepadState};
|
||||
use webvr_traits::{WebVRGamepadData, WebVRGamepadHand, WebVRGamepadState, WebVRPose};
|
||||
|
||||
#[dom_struct]
|
||||
pub struct XRInputSource {
|
||||
|
@ -22,6 +23,7 @@ pub struct XRInputSource {
|
|||
data: WebVRGamepadData,
|
||||
#[ignore_malloc_size_of = "Defined in rust-webvr"]
|
||||
state: DomRefCell<WebVRGamepadState>,
|
||||
target_ray_space: MutNullableDom<XRSpace>,
|
||||
}
|
||||
|
||||
impl XRInputSource {
|
||||
|
@ -35,6 +37,7 @@ impl XRInputSource {
|
|||
session: Dom::from_ref(session),
|
||||
data,
|
||||
state: DomRefCell::new(state),
|
||||
target_ray_space: Default::default(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,6 +57,10 @@ impl XRInputSource {
|
|||
pub fn update_state(&self, state: WebVRGamepadState) {
|
||||
*self.state.borrow_mut() = state;
|
||||
}
|
||||
|
||||
pub fn pose(&self) -> WebVRPose {
|
||||
self.state.borrow().pose
|
||||
}
|
||||
}
|
||||
|
||||
impl XRInputSourceMethods for XRInputSource {
|
||||
|
@ -65,4 +72,12 @@ impl XRInputSourceMethods for XRInputSource {
|
|||
WebVRGamepadHand::Right => XRHandedness::Right,
|
||||
}
|
||||
}
|
||||
|
||||
/// https://immersive-web.github.io/webxr/#dom-xrinputsource-targetrayspace
|
||||
fn TargetRaySpace(&self) -> DomRoot<XRSpace> {
|
||||
self.target_ray_space.or_init(|| {
|
||||
let global = self.global();
|
||||
XRSpace::new_inputspace(&global, &self.session, &self)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue