script/dom/webxr/
xrjointpose.rs

1/* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at https://mozilla.org/MPL/2.0/. */
4
5use dom_struct::dom_struct;
6
7use crate::dom::bindings::codegen::Bindings::XRJointPoseBinding::XRJointPoseMethods;
8use crate::dom::bindings::num::Finite;
9use crate::dom::bindings::reflector::reflect_dom_object;
10use crate::dom::bindings::root::DomRoot;
11use crate::dom::window::Window;
12use crate::dom::xrpose::XRPose;
13use crate::dom::xrrigidtransform::XRRigidTransform;
14use crate::dom::xrsession::ApiRigidTransform;
15use crate::script_runtime::CanGc;
16
17#[dom_struct]
18pub(crate) struct XRJointPose {
19    pose: XRPose,
20    radius: Option<f32>,
21}
22
23impl XRJointPose {
24    fn new_inherited(transform: &XRRigidTransform, radius: Option<f32>) -> XRJointPose {
25        XRJointPose {
26            pose: XRPose::new_inherited(transform),
27            radius,
28        }
29    }
30
31    #[allow(unsafe_code)]
32    pub(crate) fn new(
33        window: &Window,
34        pose: ApiRigidTransform,
35        radius: Option<f32>,
36        can_gc: CanGc,
37    ) -> DomRoot<XRJointPose> {
38        let transform = XRRigidTransform::new(window, pose, can_gc);
39        reflect_dom_object(
40            Box::new(XRJointPose::new_inherited(&transform, radius)),
41            window,
42            can_gc,
43        )
44    }
45}
46
47impl XRJointPoseMethods<crate::DomTypeHolder> for XRJointPose {
48    /// <https://immersive-web.github.io/webxr/#dom-XRJointPose-views>
49    fn GetRadius(&self) -> Option<Finite<f32>> {
50        self.radius.map(Finite::wrap)
51    }
52}