- 我在2D X平面,Y
- 我通過點擊屏幕上的X設定了目的地 'Y'
- 我想這需要轉身面對這個目的與角度:
// Calculate the angle between plane position and destination point
CVector3 facingVec = m_vDestination - m_vPosition;
fAngle = -Math::radiansToDegrees ( (float)atan2f(m_vDestination.x - m_vPosition.x, m_vDestination.y - m_vPosition.y) ) ;
//This doesn't work, when rotating from ex. 350 degree to 0
//plane has to go all the way around 360,350,340,330,
//...,120,...100,90,..down to zero
float angleToTurn = fAngle - m_fRotationAngle;
if(angleToTurn < 0)
{
angleToTurn += 360.0f;
}
m_fRotationAngle += (angleToTurn)/5;
// Move the unit towards the calculated angle m_fRotationAngle
m_vDirection.x = (-sin(Math::degreesToRadians(m_fRotationAngle)));
m_vDirection.y = (cos(Math::degreesToRadians(m_fRotationAngle)));
m_vPosition += (2 * m_vDirection * fDelta);
這是怎麼看起來像
YT Video - 遺憾的演示版,我無法獲得自由在這一刻什麼。
這就是我需要
- 我需要這個正確的行爲,比方說飛機在角度350 旋轉,我設定的目標和新的角度應在15
而不是去的:350,340,330,320,310,300,290,... 10,0,15 應該繼續:350,0,15
希望你能幫助我和這些傢伙在一起,我已經放棄了貝塞爾的方法 - 而且我幾天以來一直在努力解決這個問題。
試圖觀看視頻時你說的「這個視頻是私人的」。請公開。 – 2012-01-14 09:33:20
已更新,對不起。 – PeeS 2012-01-14 09:34:59
座標系可能在視頻中旋轉嗎?在我看來,當光標在平面下時出現問題。當m_vDestination.y - m_vPosition.y == 0分開時,你應該處理這種情況,因爲atan2f會有問題 – 2012-01-14 09:40:07