bevy_rapier3d/dynamics/
fixed_joint.rs1use crate::dynamics::{GenericJoint, GenericJointBuilder};
2use crate::math::{Rot, Vect};
3use rapier::dynamics::JointAxesMask;
4
5use super::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 local_basis1(&self) -> Rot {
43 self.data.local_basis1()
44 }
45
46 pub fn set_local_basis1(&mut self, local_basis: Rot) -> &mut Self {
48 self.data.set_local_basis1(local_basis);
49 self
50 }
51
52 #[must_use]
54 pub fn local_basis2(&self) -> Rot {
55 self.data.local_basis2()
56 }
57
58 pub fn set_local_basis2(&mut self, local_basis: Rot) -> &mut Self {
60 self.data.set_local_basis2(local_basis);
61 self
62 }
63
64 #[must_use]
66 pub fn local_anchor1(&self) -> Vect {
67 self.data.local_anchor1()
68 }
69
70 pub fn set_local_anchor1(&mut self, anchor1: Vect) -> &mut Self {
72 self.data.set_local_anchor1(anchor1);
73 self
74 }
75
76 #[must_use]
78 pub fn local_anchor2(&self) -> Vect {
79 self.data.local_anchor2()
80 }
81
82 pub fn set_local_anchor2(&mut self, anchor2: Vect) -> &mut Self {
84 self.data.set_local_anchor2(anchor2);
85 self
86 }
87}
88
89impl From<FixedJoint> for GenericJoint {
90 fn from(joint: FixedJoint) -> GenericJoint {
91 joint.data
92 }
93}
94
95#[derive(Copy, Clone, Debug, PartialEq, Default)]
97pub struct FixedJointBuilder(FixedJoint);
98
99impl FixedJointBuilder {
100 pub fn new() -> Self {
102 Self(FixedJoint::new())
103 }
104
105 #[must_use]
107 pub fn local_basis1(mut self, local_basis: Rot) -> Self {
108 self.0.set_local_basis1(local_basis);
109 self
110 }
111
112 #[must_use]
114 pub fn local_basis2(mut self, local_basis: Rot) -> Self {
115 self.0.set_local_basis2(local_basis);
116 self
117 }
118
119 #[must_use]
121 pub fn local_anchor1(mut self, anchor1: Vect) -> Self {
122 self.0.set_local_anchor1(anchor1);
123 self
124 }
125
126 #[must_use]
128 pub fn local_anchor2(mut self, anchor2: Vect) -> Self {
129 self.0.set_local_anchor2(anchor2);
130 self
131 }
132
133 #[must_use]
135 pub fn build(self) -> FixedJoint {
136 self.0
137 }
138}
139
140impl From<FixedJointBuilder> for TypedJoint {
141 fn from(joint: FixedJointBuilder) -> TypedJoint {
142 joint.0.into()
143 }
144}
145
146impl From<FixedJoint> for TypedJoint {
147 fn from(joint: FixedJoint) -> TypedJoint {
148 TypedJoint::FixedJoint(joint)
149 }
150}