【发布时间】:2017-04-04 05:50:28
【问题描述】:
我正在用 C++ 创建一个攻击船游戏,但我的船在屏幕上跟随鼠标时出现问题。我的计划是让船像船一样跟随鼠标(缓慢旋转,而不是瞬时旋转,大约需要 4 秒来完成 360 转),并且在大多数情况下它会做它应该做的事情。
当鼠标位于屏幕左侧时(当我的鼠标越过 -x 轴时)时会发生该错误,因为船跟随鼠标,船会转向错误的方向并进行 360 度旋转,而不是跟随鼠标。
这是我用来转船的代码。
angle = atan2(delta_y, delta_x) * 180.0 / PI;
//Rotate the boat towards the mouse and
//make the boat turn more realistically
if (angle - rotate > 0) {
rotate += 1.0f; // turns left
} else if (angle - rotate < 0) {
rotate -= 1.0f; // turns right
}
if (angle - rotate >= 360.0f) {
rotate = 0.0f;
}`
【问题讨论】:
标签: c++ animation rotation 2d glut