Skip to content

Instantly share code, notes, and snippets.

@allsey87
Created April 20, 2018 12:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save allsey87/86e04ebdf3f159ba9b1b5883690a01c2 to your computer and use it in GitHub Desktop.
Save allsey87/86e04ebdf3f159ba9b1b5883690a01c2 to your computer and use it in GitHub Desktop.
Damping in the magnetism plug-in
/* start test code here */
/* Link 0 */
CDynamics3DMultiBodyObjectModel::CLink* pcLink0 =
dynamic_cast<CDynamics3DMultiBodyObjectModel::CLink*>(itDipole0->Body);
btMultiBodyLinkCollider& col0 = pcLink0->m_cMultiBodyLink;
btScalar* vel0 = col0.m_multiBody->getJointVelMultiDof(col0.m_link);
btVector3 cDampingTorque0(vel0[0],vel0[1],vel0[2]);
//btVector3 cDampingTorque0(vel0[0]*vel0[0]+vel0[0],
// vel0[1]*vel0[1]+vel0[1],
// vel0[2]*vel0[2]+vel0[2]);
//it is not right to use 2nd level as (vel0[0]*vel0[0]+vel0[0]), this changes the direction
//btScalar fConstant = 0.00;
// actually, I think there is no bad to remove the friction. The key problem is not lacking of friction, but the overreact within a timestep, which leads to the vibration.
btScalar fConstant = 0.000001;
cDampingTorque0 *= -fConstant;
itDipole0->Body->ApplyTorque(cDampingTorque0);
/* Link 1 */
CDynamics3DMultiBodyObjectModel::CLink* pcLink1 =
dynamic_cast<CDynamics3DMultiBodyObjectModel::CLink*>(itDipole1->Body);
btMultiBodyLinkCollider& col1 = pcLink1->m_cMultiBodyLink;
btScalar* vel1 = col1.m_multiBody->getJointVelMultiDof(col1.m_link);
btVector3 cDampingTorque1(vel1[0],vel1[1],vel1[2]);
cDampingTorque1 *= -fConstant;
itDipole1->Body->ApplyTorque(cDampingTorque1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment