diff options
| author | Sébastien Crozet <developer@crozet.re> | 2022-03-19 16:10:49 +0100 |
|---|---|---|
| committer | Sébastien Crozet <sebastien@crozet.re> | 2022-03-20 21:49:16 +0100 |
| commit | db6a8c526d939a125485c89cfb6e540422fe6b4b (patch) | |
| tree | 32738172c6bd27e07ed9a4b8f90f5fbbfc07fd5e /src/dynamics/joint/revolute_joint.rs | |
| parent | e2e6fc787112ab35a3d4858aa2cf83fcf41c16a2 (diff) | |
| download | rapier-db6a8c526d939a125485c89cfb6e540422fe6b4b.tar.gz rapier-db6a8c526d939a125485c89cfb6e540422fe6b4b.tar.bz2 rapier-db6a8c526d939a125485c89cfb6e540422fe6b4b.zip | |
Fix warnings and add comments.
Diffstat (limited to 'src/dynamics/joint/revolute_joint.rs')
| -rw-r--r-- | src/dynamics/joint/revolute_joint.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/dynamics/joint/revolute_joint.rs b/src/dynamics/joint/revolute_joint.rs index a9d74f5..28e3968 100644 --- a/src/dynamics/joint/revolute_joint.rs +++ b/src/dynamics/joint/revolute_joint.rs @@ -8,17 +8,22 @@ use crate::math::UnitVector; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[derive(Copy, Clone, Debug, PartialEq)] #[repr(transparent)] +/// A revolute joint, locks all relative motion except for rotation along the joint’s principal axis. pub struct RevoluteJoint { data: GenericJoint, } impl RevoluteJoint { + /// Creates a new revolute joint allowing only relative rotations. #[cfg(feature = "dim2")] pub fn new() -> Self { let data = GenericJointBuilder::new(JointAxesMask::LOCKED_REVOLUTE_AXES); Self { data: data.build() } } + /// Creates a new revolute joint allowing only relative rotations along the specified axis. + /// + /// This axis is expressed in the local-space of both rigid-bodies. #[cfg(feature = "dim3")] pub fn new(axis: UnitVector<Real>) -> Self { let data = GenericJointBuilder::new(JointAxesMask::LOCKED_REVOLUTE_AXES) @@ -28,30 +33,36 @@ impl RevoluteJoint { Self { data } } + /// The underlying generic joint. pub fn data(&self) -> &GenericJoint { &self.data } + /// The joint’s anchor, expressed in the local-space of the first rigid-body. #[must_use] pub fn local_anchor1(&self) -> Point<Real> { self.data.local_anchor1() } + /// Sets the joint’s anchor, expressed in the local-space of the first rigid-body. pub fn set_local_anchor1(&mut self, anchor1: Point<Real>) -> &mut Self { self.data.set_local_anchor1(anchor1); self } + /// The joint’s anchor, expressed in the local-space of the second rigid-body. #[must_use] pub fn local_anchor2(&self) -> Point<Real> { self.data.local_anchor2() } + /// Sets the joint’s anchor, expressed in the local-space of the second rigid-body. pub fn set_local_anchor2(&mut self, anchor2: Point<Real>) -> &mut Self { self.data.set_local_anchor2(anchor2); self } + /// The motor affecting the joint’s rotational degree of freedom. #[must_use] pub fn motor(&self) -> Option<&JointMotor> { self.data.motor(JointAxis::AngX) @@ -95,16 +106,19 @@ impl RevoluteJoint { self } + /// Sets the maximum force the motor can deliver. pub fn set_motor_max_force(&mut self, max_force: Real) -> &mut Self { self.data.set_motor_max_force(JointAxis::AngX, max_force); self } + /// The limit angle attached bodies can translate along the joint’s principal axis. #[must_use] pub fn limits(&self) -> Option<&JointLimits<Real>> { self.data.limits(JointAxis::AngX) } + /// Sets the `[min,max]` limit angle attached bodies can translate along the joint’s principal axis. pub fn set_limits(&mut self, limits: [Real; 2]) -> &mut Self { self.data.set_limits(JointAxis::AngX, limits); self @@ -117,27 +131,36 @@ impl Into<GenericJoint> for RevoluteJoint { } } +/// Create revolute joints using the builder pattern. +/// +/// A revolute joint locks all relative motion except for rotations along the joint’s principal axis. #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[derive(Copy, Clone, Debug, PartialEq)] pub struct RevoluteJointBuilder(RevoluteJoint); impl RevoluteJointBuilder { + /// Creates a new revolute joint builder. #[cfg(feature = "dim2")] pub fn new() -> Self { Self(RevoluteJoint::new()) } + /// Creates a new revolute joint builder, allowing only relative rotations along the specified axis. + /// + /// This axis is expressed in the local-space of both rigid-bodies. #[cfg(feature = "dim3")] pub fn new(axis: UnitVector<Real>) -> Self { Self(RevoluteJoint::new(axis)) } + /// Sets the joint’s anchor, expressed in the local-space of the first rigid-body. #[must_use] pub fn local_anchor1(mut self, anchor1: Point<Real>) -> Self { self.0.set_local_anchor1(anchor1); self } + /// Sets the joint’s anchor, expressed in the local-space of the second rigid-body. #[must_use] pub fn local_anchor2(mut self, anchor2: Point<Real>) -> Self { self.0.set_local_anchor2(anchor2); @@ -178,18 +201,21 @@ impl RevoluteJointBuilder { self } + /// Sets the maximum force the motor can deliver. #[must_use] pub fn motor_max_force(mut self, max_force: Real) -> Self { self.0.set_motor_max_force(max_force); self } + /// Sets the `[min,max]` limit angles attached bodies can rotate along the joint’s principal axis. #[must_use] pub fn limits(mut self, limits: [Real; 2]) -> Self { self.0.set_limits(limits); self } + /// Builds the revolute joint. #[must_use] pub fn build(self) -> RevoluteJoint { self.0 |
