rapier3d/dynamics/joint/
fixed_joint.rs

1use 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)]
7/// A fixed joint, locks all relative motion between two bodies.
8pub struct FixedJoint {
9    /// The underlying joint data.
10    pub data: GenericJoint,
11}
12
13impl Default for FixedJoint {
14    fn default() -> Self {
15        FixedJoint::new()
16    }
17}
18
19impl FixedJoint {
20    /// Creates a new fixed joint.
21    #[must_use]
22    pub fn new() -> Self {
23        let data = GenericJointBuilder::new(JointAxesMask::LOCKED_FIXED_AXES).build();
24        Self { data }
25    }
26
27    /// Are contacts between the attached rigid-bodies enabled?
28    pub fn contacts_enabled(&self) -> bool {
29        self.data.contacts_enabled
30    }
31
32    /// Sets whether contacts between the attached rigid-bodies are enabled.
33    pub fn set_contacts_enabled(&mut self, enabled: bool) -> &mut Self {
34        self.data.set_contacts_enabled(enabled);
35        self
36    }
37
38    /// The joint’s frame, expressed in the first rigid-body’s local-space.
39    #[must_use]
40    pub fn local_frame1(&self) -> &Isometry<Real> {
41        &self.data.local_frame1
42    }
43
44    /// Sets the joint’s frame, expressed in the first rigid-body’s local-space.
45    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    /// The joint’s frame, expressed in the second rigid-body’s local-space.
51    #[must_use]
52    pub fn local_frame2(&self) -> &Isometry<Real> {
53        &self.data.local_frame2
54    }
55
56    /// Sets joint’s frame, expressed in the second rigid-body’s local-space.
57    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    /// The joint’s anchor, expressed in the local-space of the first rigid-body.
63    #[must_use]
64    pub fn local_anchor1(&self) -> Point<Real> {
65        self.data.local_anchor1()
66    }
67
68    /// Sets the joint’s anchor, expressed in the local-space of the first rigid-body.
69    pub fn set_local_anchor1(&mut self, anchor1: Point<Real>) -> &mut Self {
70        self.data.set_local_anchor1(anchor1);
71        self
72    }
73
74    /// The joint’s anchor, expressed in the local-space of the second rigid-body.
75    #[must_use]
76    pub fn local_anchor2(&self) -> Point<Real> {
77        self.data.local_anchor2()
78    }
79
80    /// Sets the joint’s anchor, expressed in the local-space of the second rigid-body.
81    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/// Create fixed joints using the builder pattern.
94#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
95#[derive(Copy, Clone, Debug, PartialEq, Default)]
96pub struct FixedJointBuilder(pub FixedJoint);
97
98impl FixedJointBuilder {
99    /// Creates a new builder for fixed joints.
100    pub fn new() -> Self {
101        Self(FixedJoint::new())
102    }
103
104    /// Sets whether contacts between the attached rigid-bodies are enabled.
105    #[must_use]
106    pub fn contacts_enabled(mut self, enabled: bool) -> Self {
107        self.0.set_contacts_enabled(enabled);
108        self
109    }
110
111    /// Sets the joint’s frame, expressed in the first rigid-body’s local-space.
112    #[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    /// Sets joint’s frame, expressed in the second rigid-body’s local-space.
119    #[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    /// Sets the joint’s anchor, expressed in the local-space of the first rigid-body.
126    #[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    /// Sets the joint’s anchor, expressed in the local-space of the second rigid-body.
133    #[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    /// Build the fixed joint.
140    #[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}