rapier2d/dynamics/joint/
fixed_joint.rs1use crate::dynamics::integration_parameters::SpringCoefficients;
2use crate::dynamics::{GenericJoint, GenericJointBuilder, JointAxesMask};
3use crate::math::{Isometry, Point, Real};
4
5#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
6#[derive(Copy, Clone, Debug, PartialEq)]
7#[repr(transparent)]
8pub struct FixedJoint {
19 pub data: GenericJoint,
21}
22
23impl Default for FixedJoint {
24 fn default() -> Self {
25 FixedJoint::new()
26 }
27}
28
29impl FixedJoint {
30 #[must_use]
32 pub fn new() -> Self {
33 let data = GenericJointBuilder::new(JointAxesMask::LOCKED_FIXED_AXES).build();
34 Self { data }
35 }
36
37 pub fn contacts_enabled(&self) -> bool {
39 self.data.contacts_enabled
40 }
41
42 pub fn set_contacts_enabled(&mut self, enabled: bool) -> &mut Self {
44 self.data.set_contacts_enabled(enabled);
45 self
46 }
47
48 #[must_use]
50 pub fn local_frame1(&self) -> &Isometry<Real> {
51 &self.data.local_frame1
52 }
53
54 pub fn set_local_frame1(&mut self, local_frame: Isometry<Real>) -> &mut Self {
56 self.data.set_local_frame1(local_frame);
57 self
58 }
59
60 #[must_use]
62 pub fn local_frame2(&self) -> &Isometry<Real> {
63 &self.data.local_frame2
64 }
65
66 pub fn set_local_frame2(&mut self, local_frame: Isometry<Real>) -> &mut Self {
68 self.data.set_local_frame2(local_frame);
69 self
70 }
71
72 #[must_use]
74 pub fn local_anchor1(&self) -> Point<Real> {
75 self.data.local_anchor1()
76 }
77
78 pub fn set_local_anchor1(&mut self, anchor1: Point<Real>) -> &mut Self {
80 self.data.set_local_anchor1(anchor1);
81 self
82 }
83
84 #[must_use]
86 pub fn local_anchor2(&self) -> Point<Real> {
87 self.data.local_anchor2()
88 }
89
90 pub fn set_local_anchor2(&mut self, anchor2: Point<Real>) -> &mut Self {
92 self.data.set_local_anchor2(anchor2);
93 self
94 }
95
96 #[must_use]
98 pub fn softness(&self) -> SpringCoefficients<Real> {
99 self.data.softness
100 }
101
102 #[must_use]
104 pub fn set_softness(&mut self, softness: SpringCoefficients<Real>) -> &mut Self {
105 self.data.softness = softness;
106 self
107 }
108}
109
110impl From<FixedJoint> for GenericJoint {
111 fn from(val: FixedJoint) -> GenericJoint {
112 val.data
113 }
114}
115
116#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
118#[derive(Copy, Clone, Debug, PartialEq, Default)]
119pub struct FixedJointBuilder(pub FixedJoint);
120
121impl FixedJointBuilder {
122 pub fn new() -> Self {
124 Self(FixedJoint::new())
125 }
126
127 #[must_use]
129 pub fn contacts_enabled(mut self, enabled: bool) -> Self {
130 self.0.set_contacts_enabled(enabled);
131 self
132 }
133
134 #[must_use]
136 pub fn local_frame1(mut self, local_frame: Isometry<Real>) -> Self {
137 self.0.set_local_frame1(local_frame);
138 self
139 }
140
141 #[must_use]
143 pub fn local_frame2(mut self, local_frame: Isometry<Real>) -> Self {
144 self.0.set_local_frame2(local_frame);
145 self
146 }
147
148 #[must_use]
150 pub fn local_anchor1(mut self, anchor1: Point<Real>) -> Self {
151 self.0.set_local_anchor1(anchor1);
152 self
153 }
154
155 #[must_use]
157 pub fn local_anchor2(mut self, anchor2: Point<Real>) -> Self {
158 self.0.set_local_anchor2(anchor2);
159 self
160 }
161
162 #[must_use]
164 pub fn softness(mut self, softness: SpringCoefficients<Real>) -> Self {
165 self.0.data.softness = softness;
166 self
167 }
168
169 #[must_use]
171 pub fn build(self) -> FixedJoint {
172 self.0
173 }
174}
175
176impl From<FixedJointBuilder> for GenericJoint {
177 fn from(val: FixedJointBuilder) -> GenericJoint {
178 val.0.into()
179 }
180}