rapier3d/dynamics/joint/
fixed_joint.rs1use crate::dynamics::{GenericJoint, GenericJointBuilder, JointAxesMask};
2use crate::math::{Isometry, Point, Real};
3
4#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
5#[derive(Copy, Clone, Debug, PartialEq)]
6#[repr(transparent)]
7pub struct FixedJoint {
9 pub data: GenericJoint,
11}
12
13impl Default for FixedJoint {
14 fn default() -> Self {
15 FixedJoint::new()
16 }
17}
18
19impl FixedJoint {
20 #[must_use]
22 pub fn new() -> Self {
23 let data = GenericJointBuilder::new(JointAxesMask::LOCKED_FIXED_AXES).build();
24 Self { data }
25 }
26
27 pub fn contacts_enabled(&self) -> bool {
29 self.data.contacts_enabled
30 }
31
32 pub fn set_contacts_enabled(&mut self, enabled: bool) -> &mut Self {
34 self.data.set_contacts_enabled(enabled);
35 self
36 }
37
38 #[must_use]
40 pub fn local_frame1(&self) -> &Isometry<Real> {
41 &self.data.local_frame1
42 }
43
44 pub fn set_local_frame1(&mut self, local_frame: Isometry<Real>) -> &mut Self {
46 self.data.set_local_frame1(local_frame);
47 self
48 }
49
50 #[must_use]
52 pub fn local_frame2(&self) -> &Isometry<Real> {
53 &self.data.local_frame2
54 }
55
56 pub fn set_local_frame2(&mut self, local_frame: Isometry<Real>) -> &mut Self {
58 self.data.set_local_frame2(local_frame);
59 self
60 }
61
62 #[must_use]
64 pub fn local_anchor1(&self) -> Point<Real> {
65 self.data.local_anchor1()
66 }
67
68 pub fn set_local_anchor1(&mut self, anchor1: Point<Real>) -> &mut Self {
70 self.data.set_local_anchor1(anchor1);
71 self
72 }
73
74 #[must_use]
76 pub fn local_anchor2(&self) -> Point<Real> {
77 self.data.local_anchor2()
78 }
79
80 pub fn set_local_anchor2(&mut self, anchor2: Point<Real>) -> &mut Self {
82 self.data.set_local_anchor2(anchor2);
83 self
84 }
85}
86
87impl From<FixedJoint> for GenericJoint {
88 fn from(val: FixedJoint) -> GenericJoint {
89 val.data
90 }
91}
92
93#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
95#[derive(Copy, Clone, Debug, PartialEq, Default)]
96pub struct FixedJointBuilder(pub FixedJoint);
97
98impl FixedJointBuilder {
99 pub fn new() -> Self {
101 Self(FixedJoint::new())
102 }
103
104 #[must_use]
106 pub fn contacts_enabled(mut self, enabled: bool) -> Self {
107 self.0.set_contacts_enabled(enabled);
108 self
109 }
110
111 #[must_use]
113 pub fn local_frame1(mut self, local_frame: Isometry<Real>) -> Self {
114 self.0.set_local_frame1(local_frame);
115 self
116 }
117
118 #[must_use]
120 pub fn local_frame2(mut self, local_frame: Isometry<Real>) -> Self {
121 self.0.set_local_frame2(local_frame);
122 self
123 }
124
125 #[must_use]
127 pub fn local_anchor1(mut self, anchor1: Point<Real>) -> Self {
128 self.0.set_local_anchor1(anchor1);
129 self
130 }
131
132 #[must_use]
134 pub fn local_anchor2(mut self, anchor2: Point<Real>) -> Self {
135 self.0.set_local_anchor2(anchor2);
136 self
137 }
138
139 #[must_use]
141 pub fn build(self) -> FixedJoint {
142 self.0
143 }
144}
145
146impl From<FixedJointBuilder> for GenericJoint {
147 fn from(val: FixedJointBuilder) -> GenericJoint {
148 val.0.into()
149 }
150}