bevy_rapier3d/geometry/shape_views/
halfspace.rs

1use crate::math::Vect;
2use rapier::parry::shape::HalfSpace;
3
4/// Read-only access to the properties of a half-space.
5#[derive(Copy, Clone)]
6pub struct HalfSpaceView<'a> {
7    /// The raw shape from Rapier.
8    pub raw: &'a HalfSpace,
9}
10
11macro_rules! impl_ref_methods(
12    ($View: ident) => {
13        impl<'a> $View<'a> {
14            /// The halfspace planar boundary's outward normal.
15            pub fn normal(&self) -> Vect {
16                (*self.raw.normal).into()
17            }
18        }
19    }
20);
21
22impl_ref_methods!(HalfSpaceView);
23
24/// Read-write access to the properties of a half-space.
25pub struct HalfSpaceViewMut<'a> {
26    /// The raw shape from Rapier.
27    pub raw: &'a mut HalfSpace,
28}
29
30impl_ref_methods!(HalfSpaceViewMut);
31
32impl HalfSpaceViewMut<'_> {
33    /// Set the normal of the half-space.
34    pub fn set_normal(&mut self, normal: Vect) {
35        let normal: rapier::math::Vector<_> = normal.into();
36        if let Some(unit_normal) = na::Unit::try_new(normal, 1.0e-6) {
37            self.raw.normal = unit_normal;
38        }
39    }
40}