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    pub(crate) fn new(
32        window: &Window,
33        pose: ApiRigidTransform,
34        radius: Option<f32>,
35        can_gc: CanGc,
36    ) -> DomRoot<XRJointPose> {
37        let transform = XRRigidTransform::new(window, pose, can_gc);
38        reflect_dom_object(
39            Box::new(XRJointPose::new_inherited(&transform, radius)),
40            window,
41            can_gc,
42        )
43    }
44}
45
46impl XRJointPoseMethods<crate::DomTypeHolder> for XRJointPose {
47    /// <https://immersive-web.github.io/webxr/#dom-XRJointPose-views>
48    fn GetRadius(&self) -> Option<Finite<f32>> {
49        self.radius.map(Finite::wrap)
50    }
51}