Skip to content

Instantly share code, notes, and snippets.

@xaguzman
Created February 19, 2015 05:28
Show Gist options
  • Save xaguzman/b0a644ea7ee5d3e25a12 to your computer and use it in GitHub Desktop.
Save xaguzman/b0a644ea7ee5d3e25a12 to your computer and use it in GitHub Desktop.
Libgdx - Orthographic Camera Pan & Zoom Input processor
public class PanZoomCameraInput extends InputAdapter {
OrthographicCamera cam;
Vector3 lastTouch, tmp;
public PanZoomCameraInput(OrthographicCamera cam){
this.cam = cam;
lastTouch = new Vector3();
tmp = new Vector3();
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
lastTouch.set(screenX, screenY, 0);
return false;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
tmp.set(screenX, screenY, 0).sub(lastTouch).scl(-1, 1, 0).scl(cam.zoom);
cam.translate(tmp);
lastTouch.set(screenX, screenY, 0);
return false;
}
@Override
public boolean scrolled(int amount) {
cam.zoom *= amount > 0 ? 1.05f : 0.95f;
return false;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment