Fix warnings and add comments.

This commit is contained in:
Sébastien Crozet
2022-03-19 16:10:49 +01:00
committed by Sébastien Crozet
parent e2e6fc7871
commit db6a8c526d
23 changed files with 391 additions and 131 deletions

View File

@@ -1,10 +1,13 @@
use crate::dynamics::joint::{GenericJoint, GenericJointBuilder, JointAxesMask};
use crate::dynamics::{JointAxis, MotorModel};
use crate::dynamics::{JointAxis, JointMotor, MotorModel};
use crate::math::{Point, Real};
use super::JointLimits;
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq)]
#[repr(transparent)]
/// A spherical joint, locks all relative translations between two bodies.
pub struct SphericalJoint {
data: GenericJoint,
}
@@ -16,25 +19,47 @@ impl Default for SphericalJoint {
}
impl SphericalJoint {
/// Creates a new spherical joint locking all relative translations between two bodies.
pub fn new() -> Self {
let data = GenericJointBuilder::new(JointAxesMask::LOCKED_SPHERICAL_AXES).build();
Self { data }
}
/// The underlying generic joint.
pub fn data(&self) -> &GenericJoint {
&self.data
}
/// The joints 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 joints 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 joints 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 joints 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 joints rotational degree of freedom along the specified axis.
#[must_use]
pub fn motor(&self, axis: JointAxis) -> Option<&JointMotor> {
self.data.motor(axis)
}
/// Set the spring-like model used by the motor to reach the desired target velocity and position.
pub fn set_motor_model(&mut self, axis: JointAxis, model: MotorModel) -> &mut Self {
self.data.set_motor_model(axis, model);
@@ -79,11 +104,19 @@ impl SphericalJoint {
self
}
/// Sets the maximum force the motor can deliver along the specified axis.
pub fn set_motor_max_force(&mut self, axis: JointAxis, max_force: Real) -> &mut Self {
self.data.set_motor_max_force(axis, max_force);
self
}
/// The limit distance attached bodies can translate along the specified axis.
#[must_use]
pub fn limits(&self, axis: JointAxis) -> Option<&JointLimits<Real>> {
self.data.limits(axis)
}
/// Sets the `[min,max]` limit angles attached bodies can translate along the joints principal axis.
pub fn set_limits(&mut self, axis: JointAxis, limits: [Real; 2]) -> &mut Self {
self.data.set_limits(axis, limits);
self
@@ -96,6 +129,7 @@ impl Into<GenericJoint> for SphericalJoint {
}
}
/// Create spherical joints using the builder pattern.
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
#[derive(Copy, Clone, Debug, PartialEq)]
pub struct SphericalJointBuilder(SphericalJoint);
@@ -107,16 +141,19 @@ impl Default for SphericalJointBuilder {
}
impl SphericalJointBuilder {
/// Creates a new builder for spherical joints.
pub fn new() -> Self {
Self(SphericalJoint::new())
}
/// Sets the joints 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 joints 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);
@@ -166,18 +203,21 @@ impl SphericalJointBuilder {
self
}
/// Sets the maximum force the motor can deliver along the specified axis.
#[must_use]
pub fn motor_max_force(mut self, axis: JointAxis, max_force: Real) -> Self {
self.0.set_motor_max_force(axis, max_force);
self
}
/// Sets the `[min,max]` limit distances attached bodies can rotate along the specified axis.
#[must_use]
pub fn limits(mut self, axis: JointAxis, limits: [Real; 2]) -> Self {
self.0.set_limits(axis, limits);
self
}
/// Builds the spherical joint.
#[must_use]
pub fn build(self) -> SphericalJoint {
self.0