From cec71341adcee78503d64886a44842a7e953dc19 Mon Sep 17 00:00:00 2001 From: stolk Date: Sat, 24 Nov 2018 12:56:23 -0800 Subject: [PATCH] Optionally enable infinite constraint error. --- .../btGeneric6DofSpring2Constraint.cpp | 11 +++++------ .../ConstraintSolver/btGeneric6DofSpring2Constraint.h | 3 ++- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpring2Constraint.cpp b/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpring2Constraint.cpp index 4593a47c7..2e14cdec2 100644 --- a/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpring2Constraint.cpp +++ b/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpring2Constraint.cpp @@ -860,12 +860,11 @@ int btGeneric6DofSpring2Constraint::get_limit_motor_info2( // will we not request a velocity with the wrong direction ? // and the answare is not, because in practice during the solving the current velocity is subtracted from the m_constraintError // so the sign of the force that is really matters -#if 0 - info->m_constraintError[srow] = (rotational ? -1 : 1) * (f < 0 ? -SIMD_INFINITY : SIMD_INFINITY); -#else - // Using infinite constraints makes the damping not work, and oscillate for ever. - info->m_constraintError[srow] = vel + f / m * (rotational ? -1 : 1); -#endif + // BEWARE! This whole approach has shown osciliation issues that prevent proper damping. + if ( m_flags & BT_6DOF_FLAGS_USE_INFINITE_ERROR ) + info->m_constraintError[srow] = (rotational ? -1 : 1) * (f < 0 ? -SIMD_INFINITY : SIMD_INFINITY); + else + info->m_constraintError[srow] = vel + f / m * (rotational ? -1 : 1); btScalar minf = f < fd ? f : fd; btScalar maxf = f < fd ? fd : f; diff --git a/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpring2Constraint.h b/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpring2Constraint.h index 55c1363ed..c0507a3b2 100644 --- a/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpring2Constraint.h +++ b/src/BulletDynamics/ConstraintSolver/btGeneric6DofSpring2Constraint.h @@ -264,7 +264,8 @@ enum bt6DofFlags2 BT_6DOF_FLAGS_CFM_STOP2 = 1, BT_6DOF_FLAGS_ERP_STOP2 = 2, BT_6DOF_FLAGS_CFM_MOTO2 = 4, - BT_6DOF_FLAGS_ERP_MOTO2 = 8 + BT_6DOF_FLAGS_ERP_MOTO2 = 8, + BT_6DOF_FLAGS_USE_INFINITE_ERROR = (1<<31), }; #define BT_6DOF_FLAGS_AXIS_SHIFT2 4 // bits per axis