i have 2 angles, lets say 350 degrees and 40 degrees.
if i want to go from 350 to 40, the current code i use goes CCW, which is 310 degrees of rotation instead of 50.
how can i calculate which direction to rotate in? (shortest direction)
ive been working at this for 2 days now, maybe im over thinking it, i know it has to be simple.
heres the code i use:
Code:
static uint nLastTime = timeGetTime();
static float fRotationSpeed = 0.0005f;
if (m_bTrackCamera && m_bRotateToAngle)
{
if (timeGetTime() - nLastTime >= 10) // rotate every 10 ms
{
nLastTime = timeGetTime();
float fAngleFrom = D3DXToDegree(m_fRotZ);
float fAngleTo = D3DXToDegree(m_fRotateToAngle);
// find shorter rotation path ?
if (fAngleTo > fAngleFrom) // CW
{
m_fRotZ += fRotationSpeed + (0.001f * (fAngleTo - fAngleFrom));
if (m_fRotZ > D3DX_PI * 2.0f)
m_fRotZ -= D3DX_PI * 2.0f;
if (m_fRotZ >= m_fRotateToAngle)
{
m_fRotZ = m_fRotateToAngle;
m_bRotateToAngle = false;
}
}
else // CCW
{
m_fRotZ -= fRotationSpeed + (0.001f * (fAngleFrom - fAngleTo));
if (m_fRotZ < 0.0f)
m_fRotZ += D3DX_PI * 2.0f;
if (m_fRotZ <= m_fRotateToAngle)
{
m_fRotZ = m_fRotateToAngle;
m_bRotateToAngle = false;
}
}
}
}