Start experimenting with a generic joint implementation for joint drives.

This commit is contained in:
Crozet Sébastien
2021-02-10 11:56:51 +01:00
parent 3be8669206
commit 5b80c4efbf
14 changed files with 1350 additions and 7 deletions

View File

@@ -1,6 +1,8 @@
#[cfg(feature = "dim3")]
use crate::dynamics::RevoluteJoint;
use crate::dynamics::{BallJoint, FixedJoint, JointHandle, PrismaticJoint, RigidBodyHandle};
use crate::dynamics::{
BallJoint, FixedJoint, GenericJoint, JointHandle, PrismaticJoint, RigidBodyHandle,
};
#[derive(Copy, Clone)]
#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
@@ -17,6 +19,7 @@ pub enum JointParams {
/// A revolute joint that removes all degrees of degrees of freedom between the affected
/// bodies except for the translation along one axis.
RevoluteJoint(RevoluteJoint),
GenericJoint(GenericJoint),
}
impl JointParams {
@@ -26,8 +29,9 @@ impl JointParams {
JointParams::BallJoint(_) => 0,
JointParams::FixedJoint(_) => 1,
JointParams::PrismaticJoint(_) => 2,
JointParams::GenericJoint(_) => 3,
#[cfg(feature = "dim3")]
JointParams::RevoluteJoint(_) => 3,
JointParams::RevoluteJoint(_) => 4,
}
}
@@ -49,6 +53,15 @@ impl JointParams {
}
}
/// Gets a reference to the underlying generic joint, if `self` is one.
pub fn as_generic_joint(&self) -> Option<&GenericJoint> {
if let JointParams::GenericJoint(j) = self {
Some(j)
} else {
None
}
}
/// Gets a reference to the underlying prismatic joint, if `self` is one.
pub fn as_prismatic_joint(&self) -> Option<&PrismaticJoint> {
if let JointParams::PrismaticJoint(j) = self {
@@ -81,6 +94,12 @@ impl From<FixedJoint> for JointParams {
}
}
impl From<GenericJoint> for JointParams {
fn from(j: GenericJoint) -> Self {
JointParams::GenericJoint(j)
}
}
#[cfg(feature = "dim3")]
impl From<RevoluteJoint> for JointParams {
fn from(j: RevoluteJoint) -> Self {