/** * Sets the camera center position */ public void setCamera(Vec2 worldCenter) { transform.setCenter(worldCenter); }
/** * Moves the camera by the given distance in screen coordinates. */ public void moveWorld(Vec2 screenDiff) { transform.getScreenVectorToWorld(screenDiff, worldDiff); if (!transform.isYFlip()) { worldDiff.y = -worldDiff.y; } transform.setCenter(transform.getCenter().addLocal(worldDiff)); }
/** * Zooms the camera to a point on the screen. The zoom amount is given on camera initialization. */ public void zoomToPoint(Vec2 screenPosition, ZoomType zoomType) { Mat22 zoom; switch (zoomType) { case ZOOM_IN: zoom = upScale; break; case ZOOM_OUT: zoom = downScale; break; default: Preconditions.checkArgument(false, "Zoom type invalid"); return; } transform.getScreenToWorld(screenPosition, oldCenter); transform.mulByTransform(zoom); transform.getScreenToWorld(screenPosition, newCenter); Vec2 transformedMove = oldCenter.subLocal(newCenter); // set, just in case bad impl by someone if (!transform.isYFlip()) { transformedMove.y = -transformedMove.y; } transform.setCenter(transform.getCenter().addLocal(transformedMove)); }
public void setCamera(Vec2 argPos) { model.getDebugDraw().getViewportTranform().setCenter(argPos); }
public void mouseWheelMoved(MouseWheelEvent e) { DebugDraw d = draw; int notches = e.getWheelRotation(); TestbedTest currTest = model.getCurrTest(); if (currTest == null) { return; } OBBViewportTransform trans = (OBBViewportTransform) d.getViewportTranform(); oldCenter.set(model.getCurrTest().getWorldMouse()); // Change the zoom and clamp it to reasonable values - can't clamp now. if (notches < 0) { trans.mulByTransform(upScale); currTest.setCachedCameraScale(currTest.getCachedCameraScale() * ZOOM_IN_SCALE); } else if (notches > 0) { trans.mulByTransform(downScale); currTest.setCachedCameraScale(currTest.getCachedCameraScale() * ZOOM_OUT_SCALE); } d.getScreenToWorldToOut(model.getMouse(), newCenter); Vec2 transformedMove = oldCenter.subLocal(newCenter); d.getViewportTranform().setCenter( d.getViewportTranform().getCenter().addLocal(transformedMove)); currTest.setCachedCameraPos(d.getViewportTranform().getCenter()); } });