bevy_rapier3d/dynamics/
fixed_joint.rs1use crate::dynamics::{GenericJoint, GenericJointBuilder};
2use crate::math::{Real, Rot, Vect};
3use rapier::dynamics::JointAxesMask;
4
5use super::{SpringCoefficients, TypedJoint};
6
7#[derive(Copy, Clone, Debug, PartialEq)]
8#[repr(transparent)]
9pub struct FixedJoint {
11 pub data: GenericJoint,
13}
14
15impl Default for FixedJoint {
16 fn default() -> Self {
17 FixedJoint::new()
18 }
19}
20
21impl FixedJoint {
22 #[must_use]
24 pub fn new() -> Self {
25 let data = GenericJointBuilder::new(JointAxesMask::LOCKED_FIXED_AXES).build();
26 Self { data }
27 }
28
29 pub fn contacts_enabled(&self) -> bool {
31 self.data.contacts_enabled()
32 }
33
34 pub fn set_contacts_enabled(&mut self, enabled: bool) -> &mut Self {
36 self.data.set_contacts_enabled(enabled);
37 self
38 }
39
40 #[must_use]
42 pub fn softness(&self) -> SpringCoefficients<Real> {
43 self.data.softness()
44 }
45
46 pub fn set_softness(&mut self, softness: SpringCoefficients<Real>) -> &mut Self {
48 self.data.set_softness(softness);
49 self
50 }
51
52 #[must_use]
54 pub fn local_basis1(&self) -> Rot {
55 self.data.local_basis1()
56 }
57
58 pub fn set_local_basis1(&mut self, local_basis: Rot) -> &mut Self {
60 self.data.set_local_basis1(local_basis);
61 self
62 }
63
64 #[must_use]
66 pub fn local_basis2(&self) -> Rot {
67 self.data.local_basis2()
68 }
69
70 pub fn set_local_basis2(&mut self, local_basis: Rot) -> &mut Self {
72 self.data.set_local_basis2(local_basis);
73 self
74 }
75
76 #[must_use]
78 pub fn local_anchor1(&self) -> Vect {
79 self.data.local_anchor1()
80 }
81
82 pub fn set_local_anchor1(&mut self, anchor1: Vect) -> &mut Self {
84 self.data.set_local_anchor1(anchor1);
85 self
86 }
87
88 #[must_use]
90 pub fn local_anchor2(&self) -> Vect {
91 self.data.local_anchor2()
92 }
93
94 pub fn set_local_anchor2(&mut self, anchor2: Vect) -> &mut Self {
96 self.data.set_local_anchor2(anchor2);
97 self
98 }
99}
100
101impl From<FixedJoint> for GenericJoint {
102 fn from(joint: FixedJoint) -> GenericJoint {
103 joint.data
104 }
105}
106
107#[derive(Copy, Clone, Debug, PartialEq, Default)]
109pub struct FixedJointBuilder(FixedJoint);
110
111impl FixedJointBuilder {
112 pub fn new() -> Self {
114 Self(FixedJoint::new())
115 }
116
117 #[must_use]
119 pub fn local_basis1(mut self, local_basis: Rot) -> Self {
120 self.0.set_local_basis1(local_basis);
121 self
122 }
123
124 #[must_use]
126 pub fn local_basis2(mut self, local_basis: Rot) -> Self {
127 self.0.set_local_basis2(local_basis);
128 self
129 }
130
131 #[must_use]
133 pub fn local_anchor1(mut self, anchor1: Vect) -> Self {
134 self.0.set_local_anchor1(anchor1);
135 self
136 }
137
138 #[must_use]
140 pub fn local_anchor2(mut self, anchor2: Vect) -> Self {
141 self.0.set_local_anchor2(anchor2);
142 self
143 }
144
145 #[must_use]
147 pub fn contacts_enabled(mut self, enabled: bool) -> Self {
148 self.0.set_contacts_enabled(enabled);
149 self
150 }
151
152 #[must_use]
154 pub fn softness(mut self, softness: SpringCoefficients<Real>) -> Self {
155 self.0.set_softness(softness);
156 self
157 }
158
159 #[must_use]
161 pub fn build(self) -> FixedJoint {
162 self.0
163 }
164}
165
166impl From<FixedJointBuilder> for TypedJoint {
167 fn from(joint: FixedJointBuilder) -> TypedJoint {
168 joint.0.into()
169 }
170}
171
172impl From<FixedJoint> for TypedJoint {
173 fn from(joint: FixedJoint) -> TypedJoint {
174 TypedJoint::FixedJoint(joint)
175 }
176}