aboutsummaryrefslogtreecommitdiff
path: root/src/dynamics/joint/fixed_joint.rs
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2022-02-20 12:55:00 +0100
committerSébastien Crozet <sebastien@crozet.re>2022-03-20 21:49:16 +0100
commitfb20d72ee29de9311a81aec6eb9f02fd2aa35fc4 (patch)
tree45827ac4c754c3670d1ddb2f91fc498515d6b3b8 /src/dynamics/joint/fixed_joint.rs
parente740493b980dc9856864ead3206a4fa02aff965f (diff)
downloadrapier-fb20d72ee29de9311a81aec6eb9f02fd2aa35fc4.tar.gz
rapier-fb20d72ee29de9311a81aec6eb9f02fd2aa35fc4.tar.bz2
rapier-fb20d72ee29de9311a81aec6eb9f02fd2aa35fc4.zip
Joint API and joint motors improvements
Diffstat (limited to 'src/dynamics/joint/fixed_joint.rs')
-rw-r--r--src/dynamics/joint/fixed_joint.rs93
1 files changed, 73 insertions, 20 deletions
diff --git a/src/dynamics/joint/fixed_joint.rs b/src/dynamics/joint/fixed_joint.rs
index c7ca904..192b7d9 100644
--- a/src/dynamics/joint/fixed_joint.rs
+++ b/src/dynamics/joint/fixed_joint.rs
@@ -1,10 +1,11 @@
-use crate::dynamics::{JointAxesMask, JointData};
+use crate::dynamics::{GenericJoint, GenericJointBuilder, JointAxesMask};
use crate::math::{Isometry, Point, Real};
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq)]
+#[repr(transparent)]
pub struct FixedJoint {
- data: JointData,
+ data: GenericJoint,
}
impl Default for FixedJoint {
@@ -14,48 +15,100 @@ impl Default for FixedJoint {
}
impl FixedJoint {
+ #[must_use]
pub fn new() -> Self {
- #[cfg(feature = "dim2")]
- let mask = JointAxesMask::X | JointAxesMask::Y | JointAxesMask::ANG_X;
- #[cfg(feature = "dim3")]
- let mask = JointAxesMask::X
- | JointAxesMask::Y
- | JointAxesMask::Z
- | JointAxesMask::ANG_X
- | JointAxesMask::ANG_Y
- | JointAxesMask::ANG_Z;
-
- let data = JointData::default().lock_axes(mask);
+ let data = GenericJointBuilder::new(JointAxesMask::LOCKED_FIXED_AXES).build();
Self { data }
}
#[must_use]
+ pub fn local_frame1(&self) -> &Isometry<Real> {
+ &self.data.local_frame1
+ }
+
+ pub fn set_local_frame1(&mut self, local_frame: Isometry<Real>) -> &mut Self {
+ self.data.set_local_frame1(local_frame);
+ self
+ }
+
+ #[must_use]
+ pub fn local_frame2(&self) -> &Isometry<Real> {
+ &self.data.local_frame2
+ }
+
+ pub fn set_local_frame2(&mut self, local_frame: Isometry<Real>) -> &mut Self {
+ self.data.set_local_frame2(local_frame);
+ self
+ }
+
+ #[must_use]
+ pub fn local_anchor1(&self) -> Point<Real> {
+ self.data.local_anchor1()
+ }
+
+ pub fn set_local_anchor1(&mut self, anchor1: Point<Real>) -> &mut Self {
+ self.data.set_local_anchor1(anchor1);
+ self
+ }
+
+ #[must_use]
+ pub fn local_anchor2(&self) -> Point<Real> {
+ self.data.local_anchor2()
+ }
+
+ pub fn set_local_anchor2(&mut self, anchor2: Point<Real>) -> &mut Self {
+ self.data.set_local_anchor2(anchor2);
+ self
+ }
+}
+
+impl Into<GenericJoint> for FixedJoint {
+ fn into(self) -> GenericJoint {
+ self.data
+ }
+}
+
+#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
+#[derive(Copy, Clone, Debug, PartialEq, Default)]
+pub struct FixedJointBuilder(FixedJoint);
+
+impl FixedJointBuilder {
+ pub fn new() -> Self {
+ Self(FixedJoint::new())
+ }
+
+ #[must_use]
pub fn local_frame1(mut self, local_frame: Isometry<Real>) -> Self {
- self.data = self.data.local_frame1(local_frame);
+ self.0.set_local_frame1(local_frame);
self
}
#[must_use]
pub fn local_frame2(mut self, local_frame: Isometry<Real>) -> Self {
- self.data = self.data.local_frame2(local_frame);
+ self.0.set_local_frame2(local_frame);
self
}
#[must_use]
pub fn local_anchor1(mut self, anchor1: Point<Real>) -> Self {
- self.data = self.data.local_anchor1(anchor1);
+ self.0.set_local_anchor1(anchor1);
self
}
#[must_use]
pub fn local_anchor2(mut self, anchor2: Point<Real>) -> Self {
- self.data = self.data.local_anchor2(anchor2);
+ self.0.set_local_anchor2(anchor2);
self
}
+
+ #[must_use]
+ pub fn build(self) -> FixedJoint {
+ self.0
+ }
}
-impl Into<JointData> for FixedJoint {
- fn into(self) -> JointData {
- self.data
+impl Into<GenericJoint> for FixedJointBuilder {
+ fn into(self) -> GenericJoint {
+ self.0.into()
}
}