aboutsummaryrefslogtreecommitdiff
path: root/src/dynamics/joint/spring_model.rs
diff options
context:
space:
mode:
authorSébastien Crozet <developer@crozet.re>2022-01-02 14:47:40 +0100
committerSébastien Crozet <developer@crozet.re>2022-01-02 16:58:36 +0100
commitf74b8401ad9ef50b8cdbf1f43a2b21f6c42b0ebc (patch)
tree53ac492fea5942a7d466f58a0095f39505674ea4 /src/dynamics/joint/spring_model.rs
parentb45d4b5ac2b31856c15e802b31e288a58940cbf2 (diff)
downloadrapier-f74b8401ad9ef50b8cdbf1f43a2b21f6c42b0ebc.tar.gz
rapier-f74b8401ad9ef50b8cdbf1f43a2b21f6c42b0ebc.tar.bz2
rapier-f74b8401ad9ef50b8cdbf1f43a2b21f6c42b0ebc.zip
Implement multibody joints and the new solver
Diffstat (limited to 'src/dynamics/joint/spring_model.rs')
-rw-r--r--src/dynamics/joint/spring_model.rs65
1 files changed, 0 insertions, 65 deletions
diff --git a/src/dynamics/joint/spring_model.rs b/src/dynamics/joint/spring_model.rs
deleted file mode 100644
index c2c9ebd..0000000
--- a/src/dynamics/joint/spring_model.rs
+++ /dev/null
@@ -1,65 +0,0 @@
-use crate::math::Real;
-
-/// The spring-like model used for constraints resolution.
-#[derive(Copy, Clone, Debug, PartialEq, Eq)]
-#[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))]
-pub enum SpringModel {
- /// No equation is solved.
- Disabled,
- /// The solved spring-like equation is:
- /// `delta_velocity(t + dt) = stiffness / dt * (target_pos - pos(t)) + damping * (target_vel - vel(t))`
- ///
- /// Here the `stiffness` is the ratio of position error to be solved at each timestep (like
- /// a velocity-based ERP), and the `damping` is the ratio of velocity error to be solved at
- /// each timestep.
- VelocityBased,
- /// The solved spring-like equation is:
- /// `acceleration(t + dt) = stiffness * (target_pos - pos(t)) + damping * (target_vel - vel(t))`
- AccelerationBased,
- /// The solved spring-like equation is:
- /// `force(t + dt) = stiffness * (target_pos - pos(t + dt)) + damping * (target_vel - vel(t + dt))`
- ForceBased,
-}
-
-impl Default for SpringModel {
- fn default() -> Self {
- SpringModel::VelocityBased
- }
-}
-
-impl SpringModel {
- /// Combines the coefficients used for solving the spring equation.
- ///
- /// Returns the new coefficients (stiffness, damping, inv_lhs_scale, keep_inv_lhs)
- /// coefficients for the equivalent impulse-based equation. These new
- /// coefficients must be used in the following way:
- /// - `rhs = (stiffness * pos_err + damping * vel_err) / gamma`.
- /// - `new_inv_lhs = gamma * if keep_inv_lhs { inv_lhs } else { 1.0 }`.
- /// Note that the returned `gamma` will be zero if both `stiffness` and `damping` are zero.
- pub fn combine_coefficients(
- self,
- dt: Real,
- stiffness: Real,
- damping: Real,
- ) -> (Real, Real, Real, bool) {
- match self {
- SpringModel::VelocityBased => (stiffness * crate::utils::inv(dt), damping, 1.0, true),
- SpringModel::AccelerationBased => {
- let effective_stiffness = stiffness * dt;
- let effective_damping = damping * dt;
- // TODO: Using gamma behaves very badly for some reasons.
- // Maybe I got the formulation wrong, so let's keep it to 1.0 for now,
- // and get back to this later.
- // let gamma = effective_stiffness * dt + effective_damping;
- (effective_stiffness, effective_damping, 1.0, true)
- }
- SpringModel::ForceBased => {
- let effective_stiffness = stiffness * dt;
- let effective_damping = damping * dt;
- let gamma = effective_stiffness * dt + effective_damping;
- (effective_stiffness, effective_damping, gamma, false)
- }
- SpringModel::Disabled => return (0.0, 0.0, 0.0, false),
- }
- }
-}