我正在尝试使用捏合手势旋转演员。演员实际上在旋转,但有时旋转被“卡住”。我记录了deltaRotDeg(以度为单位的增量旋转),有时值会跳转。例如,它在-42.25918度旋转,然后它将跳到317.7408度。我在这里跟着轮换数学http://www.codeproject.com/Articles/319401/Simple-Gestures-on-Android
这是我的代码。我的数学错了或代码中有什么问题吗?
public ActorGestureListener gestureListener = new ActorGestureListener() {
@Override
public void pinch(InputEvent event, Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
Actor actor = event.getListenerActor();
if(actor.getName().equals("valve")){
Vector2 a = initialPointer2.sub(initialPointer1);
Vector2 b = pointer2.sub(pointer1);
a = a.nor();
b = b.nor();
float deltaRot = (float)(Math.atan2(b.y,b.x) - Math.atan2(a.y,a.x));
float deltaRotDeg = (float)((deltaRot*180)/Math.PI);
world.getValve().rotate(deltaRotDeg);
}
}
答案 0 :(得分:0)
替换
float deltaRotDeg = (float)((deltaRot*180)/Math.PI);
与
float deltaRotDeg = (float)(((deltaRot*180)/Math.PI + 360) % 360);