this is how I do mine in rcbot2. it's similar but no damping, just has a momentum and a 'mouse sensitivity'
Code:
void CBot :: changeAngles ( float fSpeed, float *fIdeal, float *fCurrent, float *fUpdate )
{
float current = *fCurrent;
float ideal = *fIdeal;
float diff;
float delta;
float alpha;
float alphaspeed;
extern ConVar bot_anglespeed;
// fSpeed = 1 to 20 (mouse sensitivity)
alphaspeed = (fSpeed/20);
alpha = alphaspeed * bot_anglespeed.GetFloat();
diff = ideal - current;
if ( diff < -180.0f )
diff += 360.0f;
else if ( diff > 180.0f )
diff -= 360.0f;
delta = (diff*alpha) + (m_fAimMoment*alphaspeed);
//check for QNAN
if ( delta != delta )
delta = 1.0f;
m_fAimMoment = (m_fAimMoment * alphaspeed) + (delta * (1.0f-alphaspeed));
//check for QNAN
if ( m_fAimMoment != m_fAimMoment )
m_fAimMoment = 1.0f;
current = current + delta;
if ( current > 180.0f )
current -= 360.0f;
else if ( current < -180.0f )
current += 360.0f;
*fCurrent = current;
if ( *fCurrent > 180.0f )
*fCurrent -= 360.0f;
else if ( *fCurrent < -180.0f )
*fCurrent += 360.0f;
}
the problem with most of these algorithms are they are all linear as far as I've seen, would be nice to see a bi-linear algorithm