3

I'm trying to rotate an actor using the pinch gesture. The actor is actually rotating but there are times that the rotation is "stucked". I logged the deltaRotDeg (delta rotation in degrees) and there are times when the values jump. For example it's rotating in -42.25918 degrees then it will jump to 317.7408 degrees. I followed the rotation math here http://www.codeproject.com/Articles/319401/Simple-Gestures-on-Android

And here's my code. Is my math wrong or there's something wrong in the code?

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);
        }
    }
4

1 回答 1

0

代替

float deltaRotDeg = (float)((deltaRot*180)/Math.PI);

float deltaRotDeg = (float)(((deltaRot*180)/Math.PI + 360) % 360);
于 2014-02-01T19:50:43.643 回答