Libgdx two-finger pan instead of single finger?
Solution 1:
After 3+ years of research I finally made it.
@Override
public boolean pinch(Vector2 initialPointer1, Vector2 initialPointer2, Vector2 pointer1, Vector2 pointer2) {
// Calculate distances
float initialDistance = initialPointer1.dst(initialPointer2);
float distance = pointer1.dst(pointer2);
// Calculate pinch coordinates
float initialPinchX = (initialPointer1.x + initialPointer2.x) / 2;
float initialPinchY = (initialPointer1.y + initialPointer2.y) / 2;
float pinchX = (pointer1.x + pointer2.x) / 2;
float pinchY = (pointer1.y + pointer2.y) / 2;
// This to avoid first time zooming or panning horrible behavior
if (lastZoomDistance == 0) {
lastZoomDistance = initialDistance;
}
if (lastPinchX == lastPinchY && lastPinchX == 0) {
lastPinchX = initialPinchX;
lastPinchY = initialPinchY;
}
// Zoom
float distanceDifference = distance - lastZoomDistance;
camera.zoom -= distanceDifference / 300;
// Pan
float deltaX = (pinchX - lastPinchX) * camera.zoom;
float deltaY = (pinchY - lastPinchY) * camera.zoom;
camera.translate(-deltaX, deltaY);
// We need to update these for future calculations
lastZoomDistance = distance;
lastPinchX = (pointer1.x + pointer2.x) / 2;
lastPinchY = (pointer1.y + pointer2.y) / 2;
return false;
}