在以下代码中:
@Override
public boolean touchDragged(int p1, int p2, int p3)
{
float x=p1;
float y=Gdx.graphics.getHeight()-p2;
float diff;
float diff2;
if(x>touchX){
diff=(x-touchX)/2;
cam.rotateAround(new Vector3(0f,0f,0f),new Vector3(0f,1f,0f),-diff);
}
if(x<touchX){
diff=(touchX-x)/2;
cam.rotateAround(new Vector3(0f,0f,0f),new Vector3(0f,1f,0f),diff);
}
if(y>touchY){
diff2=(y-touchY)/2;
cam.rotateAround(new Vector3(0f,0f,0f),new Vector3(1f,0f,0f),-diff2);
}
if(y<touchY){
diff2=(touchY-y)/2;
cam.rotateAround(new Vector3(0f,0f,0f),new Vector3(1f,0f,0f),diff2);
}
touchY=y;
touchX=x;
// TODO: Implement this method
return true;
}
Note:TouchX and TouchY are the original touch down positions
相机将在指定的轴(0 1 0)或(1 0 0)上旋转。因此,如果我在x轴上旋转90度并开始在y轴上旋转,它似乎会旋转通过相机的视图,而不是在屏幕上按下手指。我知道为什么会发生这种情况(由于轴是预先指定的并且不会根据相机的变量而改变)但我想知道如何优化这一点以便相机将遵循触摸拖动