bevy_rapier3d/geometry/shape_views/
cylinder.rs

1use crate::math::Real;
2use rapier::parry::shape::Cylinder;
3
4/// Read-only access to the properties of a cylinder.
5#[derive(Copy, Clone)]
6pub struct CylinderView<'a> {
7    /// The raw shape from Rapier.
8    pub raw: &'a Cylinder,
9}
10
11macro_rules! impl_ref_methods(
12    ($View: ident) => {
13        impl<'a> $View<'a> {
14            /// The half-height of the cylinder.
15            pub fn half_height(&self) -> Real {
16                self.raw.half_height
17            }
18
19            /// The base radius of the cylinder.
20            pub fn radius(&self) -> Real {
21                self.raw.radius
22            }
23        }
24    }
25);
26
27impl_ref_methods!(CylinderView);
28
29/// Read-write access to the properties of a cylinder.
30pub struct CylinderViewMut<'a> {
31    /// The raw shape from Rapier.
32    pub raw: &'a mut Cylinder,
33}
34
35impl_ref_methods!(CylinderViewMut);
36
37impl CylinderViewMut<'_> {
38    /// Set the half-height of the cylinder.
39    pub fn set_half_height(&mut self, half_height: Real) {
40        self.raw.half_height = half_height;
41    }
42
43    /// Set the radius of the basis of the cylinder.
44    pub fn set_radius(&mut self, radius: Real) {
45        self.raw.radius = radius;
46    }
47}