From fb20d72ee29de9311a81aec6eb9f02fd2aa35fc4 Mon Sep 17 00:00:00 2001 From: Sébastien Crozet Date: Sun, 20 Feb 2022 12:55:00 +0100 Subject: Joint API and joint motors improvements --- src/dynamics/joint/fixed_joint.rs | 93 ++++++++++++++++++++++++++++++--------- 1 file changed, 73 insertions(+), 20 deletions(-) (limited to 'src/dynamics/joint/fixed_joint.rs') 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 { + &self.data.local_frame1 + } + + pub fn set_local_frame1(&mut self, local_frame: Isometry) -> &mut Self { + self.data.set_local_frame1(local_frame); + self + } + + #[must_use] + pub fn local_frame2(&self) -> &Isometry { + &self.data.local_frame2 + } + + pub fn set_local_frame2(&mut self, local_frame: Isometry) -> &mut Self { + self.data.set_local_frame2(local_frame); + self + } + + #[must_use] + pub fn local_anchor1(&self) -> Point { + self.data.local_anchor1() + } + + pub fn set_local_anchor1(&mut self, anchor1: Point) -> &mut Self { + self.data.set_local_anchor1(anchor1); + self + } + + #[must_use] + pub fn local_anchor2(&self) -> Point { + self.data.local_anchor2() + } + + pub fn set_local_anchor2(&mut self, anchor2: Point) -> &mut Self { + self.data.set_local_anchor2(anchor2); + self + } +} + +impl Into 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) -> 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) -> 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) -> 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) -> 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 for FixedJoint { - fn into(self) -> JointData { - self.data +impl Into for FixedJointBuilder { + fn into(self) -> GenericJoint { + self.0.into() } } -- cgit