diff options
| author | Crozet Sébastien <developer@crozet.re> | 2021-02-10 11:56:51 +0100 |
|---|---|---|
| committer | Crozet Sébastien <developer@crozet.re> | 2021-02-11 15:58:46 +0100 |
| commit | 5b80c4efbf93ad1294c9d3d390d8c8f090681b0e (patch) | |
| tree | d82cef06b68a078dc23230e4e596021f7071b9b7 /src/dynamics/joint/generic_joint.rs | |
| parent | 3be866920657f7a13a49486795e06f14d92f4969 (diff) | |
| download | rapier-5b80c4efbf93ad1294c9d3d390d8c8f090681b0e.tar.gz rapier-5b80c4efbf93ad1294c9d3d390d8c8f090681b0e.tar.bz2 rapier-5b80c4efbf93ad1294c9d3d390d8c8f090681b0e.zip | |
Start experimenting with a generic joint implementation for joint drives.
Diffstat (limited to 'src/dynamics/joint/generic_joint.rs')
| -rw-r--r-- | src/dynamics/joint/generic_joint.rs | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/dynamics/joint/generic_joint.rs b/src/dynamics/joint/generic_joint.rs new file mode 100644 index 0000000..cfea537 --- /dev/null +++ b/src/dynamics/joint/generic_joint.rs @@ -0,0 +1,46 @@ +use crate::math::{Isometry, Real, SpacialVector, SPATIAL_DIM}; + +#[derive(Copy, Clone, Debug)] +#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] +/// A joint that prevents all relative movement between two bodies. +/// +/// Given two frames of references, this joint aims to ensure these frame always coincide in world-space. +pub struct GenericJoint { + /// The frame of reference for the first body affected by this joint, expressed in the local frame + /// of the first body. + pub local_anchor1: Isometry<Real>, + /// The frame of reference for the second body affected by this joint, expressed in the local frame + /// of the first body. + pub local_anchor2: Isometry<Real>, + /// The impulse applied to the first body affected by this joint. + /// + /// The impulse applied to the second body affected by this joint is given by `-impulse`. + /// This combines both linear and angular impulses: + /// - In 2D, `impulse.xy()` gives the linear impulse, and `impulse.z` the angular impulse. + /// - In 3D, `impulse.xyz()` gives the linear impulse, and `(impulse[3], impulse[4], impulse[5])` the angular impulse. + pub impulse: SpacialVector<Real>, + + pub min_position: SpacialVector<Real>, + pub max_position: SpacialVector<Real>, + pub target_velocity: SpacialVector<Real>, + /// The maximum negative impulse the joint can apply on each DoF. Must be <= 0.0 + pub max_negative_impulse: SpacialVector<Real>, + /// The maximum positive impulse the joint can apply on each DoF. Must be >= 0.0 + pub max_positive_impulse: SpacialVector<Real>, +} + +impl GenericJoint { + /// Creates a new fixed joint from the frames of reference of both bodies. + pub fn new(local_anchor1: Isometry<Real>, local_anchor2: Isometry<Real>) -> Self { + Self { + local_anchor1, + local_anchor2, + impulse: SpacialVector::zeros(), + min_position: SpacialVector::zeros(), + max_position: SpacialVector::zeros(), + target_velocity: SpacialVector::zeros(), + max_negative_impulse: SpacialVector::repeat(-Real::MAX), + max_positive_impulse: SpacialVector::repeat(Real::MAX), + } + } +} |
