- 我在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