我有一个多边形,我想旋转 360 度以上,但仍跟踪整轮。
我将手指的角度定义为可变角度,并且我知道我正在旋转的暴徒的角度,但是在每转一圈后,角度就会重置,因为触摸点和暴徒之间的角度从 360 变为 0,反之亦然。
我怎样才能解决这个问题?
当前代码:
double rotation = angle - lastAngle;
selectedMob.rotate((float) (rotation));
其中 angle 是接触点和 mob 之间的角度,lastAngle 是之前的角度。
方法 rotate 只是将旋转添加到当前角度,如下所示:
public void rotate(float angle) {
this.angle += angle;
}
角度定义为
double rads = Math.atan2(dy, dx);
double angle = Math.toDegrees(rads);
然后我调整角度,让它从 0 开始,但我确保它从 0 到 360
调试:
09-13 00:03:53.708: V/GameActivity(23389): updating frame
09-13 00:03:53.708: V/GameActivity(23389): checked for all mobs
09-13 00:03:53.825: V/GameActivity(23389): Angle of finger is 360.0
09-13 00:03:53.825: V/GameActivity(23389): Angle of mob is 344.94818
09-13 00:03:53.825: V/GameActivity(23389): Last angle is 359.56921278299137
09-13 00:03:53.825: V/GameActivity(23389): Rotation will be 0.43078721700862843
09-13 00:03:53.825: V/GameActivity(23389): ****************
09-13 00:03:53.825: V/GameActivity(23389): updating frame
09-13 00:03:53.825: V/GameActivity(23389): checked for all mobs
09-13 00:03:54.137: V/GameActivity(23389): Angle of finger is 0.4275725068334077
09-13 00:03:54.137: V/GameActivity(23389): Angle of mob is 345.37897
09-13 00:03:54.137: V/GameActivity(23389): Last angle is 360.0
09-13 00:03:54.137: V/GameActivity(23389): Rotation will be -359.5724274931666
09-13 00:03:54.137: V/GameActivity(23389): ****************