Implementing proper damping in springs

kc297
Posts: 4
Joined: Wed Jul 13, 2011 6:26 pm

Implementing proper damping in springs

Post by kc297 »

I have tried to implement proper second order damping in the spring constraint.
For linear motion damping the following code works well:

Code: Select all

inline btVector3 get_linear_velocity(double time)
    {

        btVector3 vel= (m_calculatedLinearDiff-old_pos1)/time;

        return vel;
    }


  for(i = 0; i < 3; i++)
    {
        if(m_springEnabled[i])
        {
            // get current position of constraint
            btScalar currPos = m_calculatedLinearDiff[i];
            // calculate difference
            btScalar delta = currPos - m_equilibriumPoint[i];
            // spring force is (delta * m_stiffness) according to Hooke's Law
            btScalar force = delta * m_springStiffness[i];
            m_linearLimits.m_targetVelocity[i]=SIMD_INFINITY;
            m_linearLimits.m_maxMotorForce[i]=(force+(m_springDamping[i]*get_linear_velocity(time_step)[i]))/ info->fps;
        }
old_pos1=m_calculatedLinearDiff;

However the same thing fails for the angular damping case.
It seems as if m_targetVelocity and m_maxMotorForce work differently in the angular case, or that the angular integration works differently .
Does anybody have any ideas about this issue?