bevy_rapier3d/geometry/shape_views/
capsule.rs1use super::SegmentView;
2use crate::math::{Real, Rot, Vect};
3use rapier::parry::shape::Capsule;
4
5#[derive(Copy, Clone)]
7pub struct CapsuleView<'a> {
8 pub raw: &'a Capsule,
10}
11
12macro_rules! impl_ref_methods(
13 ($View: ident) => {
14 impl<'a> $View<'a> {
15 pub fn segment(&self) -> SegmentView<'_> {
17 SegmentView {
18 raw: &self.raw.segment,
19 }
20 }
21
22 pub fn radius(&self) -> Real {
24 self.raw.radius
25 }
26
27 pub fn height(&self) -> Real {
29 self.raw.height()
30 }
31
32 pub fn half_height(&self) -> Real {
34 self.raw.half_height()
35 }
36
37 pub fn center(&self) -> Vect {
39 self.raw.center().into()
40 }
41
42 pub fn canonical_transform(&self) -> (Vect, Rot) {
45 self.raw.canonical_transform().into()
46 }
47
48 #[cfg(feature = "dim2")]
50 pub fn rotation_wrt_y(&self) -> Rot {
51 self.raw.rotation_wrt_y().angle()
52 }
53
54 #[cfg(feature = "dim3")]
56 pub fn rotation_wrt_y(&self) -> Rot {
57 self.raw.rotation_wrt_y().into()
58 }
59
60 pub fn transform_wrt_y(&self) -> (Vect, Rot) {
62 self.raw.transform_wrt_y().into()
63 }
64 }
65 }
66);
67
68impl_ref_methods!(CapsuleView);
69
70pub struct CapsuleViewMut<'a> {
72 pub raw: &'a mut Capsule,
74}
75
76impl_ref_methods!(CapsuleViewMut);
77
78impl CapsuleViewMut<'_> {
79 pub fn set_segment(&mut self, start: Vect, end: Vect) {
81 self.raw.segment.a = start.into();
82 self.raw.segment.b = end.into();
83 }
84
85 pub fn set_radius(&mut self, radius: Real) {
87 self.raw.radius = radius;
88 }
89}