@Test public void testUpdate () { int width = 800; int height = 600; CameraHelper camera = new CameraHelper(width, height); camera.setMode(CameraMode.DIRECT_CAMERA); assertEquals(0, camera.getX(), 0); assertEquals(0, camera.getY(), 0); camera.setTargetPos(0, 0); camera.update(GameTime.getInstance()); assertEquals(0, camera.getX(), 0); assertEquals(0, camera.getY(), 0); camera.setTargetPos(100, 200); camera.update(GameTime.getInstance()); assertEquals(100, camera.getX(), 0); assertEquals(200, camera.getY(), 0); }
public void update (GameTime time) { float lastX = this.x; float lastY = this.y; if (mode == CameraMode.DIRECT_CAMERA) { this.x = this.targetX; this.y = this.targetY; } else if (mode == CameraMode.SMOOTH_CAMERA) { } else if (mode == CameraMode.FIXED_CAMERA) { } else if (mode == CameraMode.MOUSE_CAMERA) { float mouseX = Gdx.input.getX(); float mouseY = Gdx.input.getY(); if (mouseX < 0 + this.mouseScrollBorder) { this.x = this.x - this.mouseScrollSpeed; } else if (mouseX > getViewportWidth() - this.mouseScrollBorder) { this.x = this.x + this.mouseScrollSpeed; } if (mouseY < 0 + this.mouseScrollBorder) { this.y = this.y - this.mouseScrollSpeed; } else if (mouseY > getViewportHeight() - this.mouseScrollBorder) { this.y = this.y + this.mouseScrollSpeed; } } else if (mode == CameraMode.SCROLL_CAMERA_WITH_MAX_DISTANCE) { } else { throw new IllegalStateException("Unknown camera mode: " + mode.name()); } if (this.mode != CameraMode.FIXED_CAMERA) { float deltaX = this.x - lastX; float deltaY = this.y - lastY; if (!this.canScrollX(deltaX)) { if (this.x + deltaX < this.minX) { this.targetX = this.minX; this.x = this.minX; } else if (this.x + deltaX + width > this.maxX) { if ((maxX - minX) < width) { this.x = minX; this.targetX = minX; } else { this.targetX = this.maxX - width; this.x = this.maxX - width; } } } if (!this.canScrollY(deltaY)) { if (this.y + deltaY < this.minY) { this.targetY = this.minY; this.y = this.minY; } else if (this.y + deltaY + height > this.maxY) { if ((maxY - minY) < height) { this.y = minY; this.targetY = minY; } else { this.targetY = this.maxY - height; this.y = this.maxY - height; } } } } this.tempCameraParams.reset(getX(), getY(), getZoom()); for (CameraModification mod : this.activeModifications) { mod.onUpdate(time, this.tempCameraParams, this); } this.syncPosToCamera(); this.camera.update(); }
CameraHelper implements ModificationFinishedListener { public void update (GameTime time) { float lastX = this.x; float lastY = this.y; if (mode == CameraMode.DIRECT_CAMERA) { this.x = this.targetX; this.y = this.targetY; } else if (mode == CameraMode.SMOOTH_CAMERA) { } else if (mode == CameraMode.FIXED_CAMERA) { } else if (mode == CameraMode.MOUSE_CAMERA) { float mouseX = Gdx.input.getX(); float mouseY = Gdx.input.getY(); if (mouseX < 0 + this.mouseScrollBorder) { this.x = this.x - this.mouseScrollSpeed; } else if (mouseX > getViewportWidth() - this.mouseScrollBorder) { this.x = this.x + this.mouseScrollSpeed; } if (mouseY < 0 + this.mouseScrollBorder) { this.y = this.y - this.mouseScrollSpeed; } else if (mouseY > getViewportHeight() - this.mouseScrollBorder) { this.y = this.y + this.mouseScrollSpeed; } } else if (mode == CameraMode.SCROLL_CAMERA_WITH_MAX_DISTANCE) { } else { throw new IllegalStateException("Unknown camera mode: " + mode.name()); } if (this.mode != CameraMode.FIXED_CAMERA) { float deltaX = this.x - lastX; float deltaY = this.y - lastY; if (!this.canScrollX(deltaX)) { if (this.x + deltaX < this.minX) { this.targetX = this.minX; this.x = this.minX; } else if (this.x + deltaX + width > this.maxX) { if ((maxX - minX) < width) { this.x = minX; this.targetX = minX; } else { this.targetX = this.maxX - width; this.x = this.maxX - width; } } } if (!this.canScrollY(deltaY)) { if (this.y + deltaY < this.minY) { this.targetY = this.minY; this.y = this.minY; } else if (this.y + deltaY + height > this.maxY) { if ((maxY - minY) < height) { this.y = minY; this.targetY = minY; } else { this.targetY = this.maxY - height; this.y = this.maxY - height; } } } } this.tempCameraParams.reset(getX(), getY(), getZoom()); for (CameraModification mod : this.activeModifications) { mod.onUpdate(time, this.tempCameraParams, this); } this.syncPosToCamera(); this.camera.update(); } }
CameraHelper implements ModificationFinishedListener { public void update (GameTime time) { float lastX = this.x; float lastY = this.y; if (mode == CameraMode.DIRECT_CAMERA) { this.x = this.targetX; this.y = this.targetY; } else if (mode == CameraMode.SMOOTH_CAMERA) { } else if (mode == CameraMode.FIXED_CAMERA) { } else if (mode == CameraMode.MOUSE_CAMERA) { float mouseX = Gdx.input.getX(); float mouseY = Gdx.input.getY(); if (mouseX < 0 + this.mouseScrollBorder) { this.x = this.x - this.mouseScrollSpeed; } else if (mouseX > getViewportWidth() - this.mouseScrollBorder) { this.x = this.x + this.mouseScrollSpeed; } if (mouseY < 0 + this.mouseScrollBorder) { this.y = this.y - this.mouseScrollSpeed; } else if (mouseY > getViewportHeight() - this.mouseScrollBorder) { this.y = this.y + this.mouseScrollSpeed; } } else if (mode == CameraMode.SCROLL_CAMERA_WITH_MAX_DISTANCE) { } else { throw new IllegalStateException("Unknown camera mode: " + mode.name()); } if (this.mode != CameraMode.FIXED_CAMERA) { float deltaX = this.x - lastX; float deltaY = this.y - lastY; if (!this.canScrollX(deltaX)) { if (this.x + deltaX < this.minX) { this.targetX = this.minX; this.x = this.minX; } else if (this.x + deltaX + width > this.maxX) { if ((maxX - minX) < width) { this.x = minX; this.targetX = minX; } else { this.targetX = this.maxX - width; this.x = this.maxX - width; } } } if (!this.canScrollY(deltaY)) { if (this.y + deltaY < this.minY) { this.targetY = this.minY; this.y = this.minY; } else if (this.y + deltaY + height > this.maxY) { if ((maxY - minY) < height) { this.y = minY; this.targetY = minY; } else { this.targetY = this.maxY - height; this.y = this.maxY - height; } } } } this.tempCameraParams.reset(getX(), getY(), getZoom()); for (CameraModification mod : this.activeModifications) { mod.onUpdate(time, this.tempCameraParams, this); } this.syncPosToCamera(); this.camera.update(); } CameraHelper(int width, int height); }
CameraHelper implements ModificationFinishedListener { public void update (GameTime time) { float lastX = this.x; float lastY = this.y; if (mode == CameraMode.DIRECT_CAMERA) { this.x = this.targetX; this.y = this.targetY; } else if (mode == CameraMode.SMOOTH_CAMERA) { } else if (mode == CameraMode.FIXED_CAMERA) { } else if (mode == CameraMode.MOUSE_CAMERA) { float mouseX = Gdx.input.getX(); float mouseY = Gdx.input.getY(); if (mouseX < 0 + this.mouseScrollBorder) { this.x = this.x - this.mouseScrollSpeed; } else if (mouseX > getViewportWidth() - this.mouseScrollBorder) { this.x = this.x + this.mouseScrollSpeed; } if (mouseY < 0 + this.mouseScrollBorder) { this.y = this.y - this.mouseScrollSpeed; } else if (mouseY > getViewportHeight() - this.mouseScrollBorder) { this.y = this.y + this.mouseScrollSpeed; } } else if (mode == CameraMode.SCROLL_CAMERA_WITH_MAX_DISTANCE) { } else { throw new IllegalStateException("Unknown camera mode: " + mode.name()); } if (this.mode != CameraMode.FIXED_CAMERA) { float deltaX = this.x - lastX; float deltaY = this.y - lastY; if (!this.canScrollX(deltaX)) { if (this.x + deltaX < this.minX) { this.targetX = this.minX; this.x = this.minX; } else if (this.x + deltaX + width > this.maxX) { if ((maxX - minX) < width) { this.x = minX; this.targetX = minX; } else { this.targetX = this.maxX - width; this.x = this.maxX - width; } } } if (!this.canScrollY(deltaY)) { if (this.y + deltaY < this.minY) { this.targetY = this.minY; this.y = this.minY; } else if (this.y + deltaY + height > this.maxY) { if ((maxY - minY) < height) { this.y = minY; this.targetY = minY; } else { this.targetY = this.maxY - height; this.y = this.maxY - height; } } } } this.tempCameraParams.reset(getX(), getY(), getZoom()); for (CameraModification mod : this.activeModifications) { mod.onUpdate(time, this.tempCameraParams, this); } this.syncPosToCamera(); this.camera.update(); } CameraHelper(int width, int height); void calculateOffset(); void translate(float x, float y, float zoom); float getX(); float getY(); float getZoom(); void setZoom(float zoom); Viewport getViewport(); int getViewportWidth(); int getViewportHeight(); void resize(int width, int height); void addResizeListener(ResizeListener listener); void removeResizeListener(ResizeListener listener); void update(GameTime time); CameraMode getMode(); void setMode(CameraMode mode); float getTargetX(); void setTargetX(float targetX); float getTargetY(); void setTargetY(float targetY); void setTargetPos(float targetX, float targetY); void forcePos(float x, float y); void forcePos(); void setTargetMiddlePos(float targetX, float targetY); float getOffsetX(); float getOffsetY(); boolean canScrollX(float deltaX); boolean canScrollY(float deltaY); void setXBounds(float minX, float maxX); void setYBounds(float minY, float maxY); void setBounds(float minX, float maxX, float minY, float maxY); void resetPosition(); void resetBounds(); void reset(); Matrix4 getCombined(); Matrix4 getViewMatrix(); Matrix4 getProjectionMatrix(); Frustum getFrustum(); Vector3 getMousePosition(); @Override void onModificationFinished(T mod, Class<T> cls); void registerMod(T mod, Class<T> cls); void removeMod(Class<T> cls); T getMod(Class<T> cls); void activateMod(Class<T> cls); void deactivateMod(Class<T> cls); OrthographicCamera getOriginalCamera(); int countActiveMods(); @Override String toString(); }
CameraHelper implements ModificationFinishedListener { public void update (GameTime time) { float lastX = this.x; float lastY = this.y; if (mode == CameraMode.DIRECT_CAMERA) { this.x = this.targetX; this.y = this.targetY; } else if (mode == CameraMode.SMOOTH_CAMERA) { } else if (mode == CameraMode.FIXED_CAMERA) { } else if (mode == CameraMode.MOUSE_CAMERA) { float mouseX = Gdx.input.getX(); float mouseY = Gdx.input.getY(); if (mouseX < 0 + this.mouseScrollBorder) { this.x = this.x - this.mouseScrollSpeed; } else if (mouseX > getViewportWidth() - this.mouseScrollBorder) { this.x = this.x + this.mouseScrollSpeed; } if (mouseY < 0 + this.mouseScrollBorder) { this.y = this.y - this.mouseScrollSpeed; } else if (mouseY > getViewportHeight() - this.mouseScrollBorder) { this.y = this.y + this.mouseScrollSpeed; } } else if (mode == CameraMode.SCROLL_CAMERA_WITH_MAX_DISTANCE) { } else { throw new IllegalStateException("Unknown camera mode: " + mode.name()); } if (this.mode != CameraMode.FIXED_CAMERA) { float deltaX = this.x - lastX; float deltaY = this.y - lastY; if (!this.canScrollX(deltaX)) { if (this.x + deltaX < this.minX) { this.targetX = this.minX; this.x = this.minX; } else if (this.x + deltaX + width > this.maxX) { if ((maxX - minX) < width) { this.x = minX; this.targetX = minX; } else { this.targetX = this.maxX - width; this.x = this.maxX - width; } } } if (!this.canScrollY(deltaY)) { if (this.y + deltaY < this.minY) { this.targetY = this.minY; this.y = this.minY; } else if (this.y + deltaY + height > this.maxY) { if ((maxY - minY) < height) { this.y = minY; this.targetY = minY; } else { this.targetY = this.maxY - height; this.y = this.maxY - height; } } } } this.tempCameraParams.reset(getX(), getY(), getZoom()); for (CameraModification mod : this.activeModifications) { mod.onUpdate(time, this.tempCameraParams, this); } this.syncPosToCamera(); this.camera.update(); } CameraHelper(int width, int height); void calculateOffset(); void translate(float x, float y, float zoom); float getX(); float getY(); float getZoom(); void setZoom(float zoom); Viewport getViewport(); int getViewportWidth(); int getViewportHeight(); void resize(int width, int height); void addResizeListener(ResizeListener listener); void removeResizeListener(ResizeListener listener); void update(GameTime time); CameraMode getMode(); void setMode(CameraMode mode); float getTargetX(); void setTargetX(float targetX); float getTargetY(); void setTargetY(float targetY); void setTargetPos(float targetX, float targetY); void forcePos(float x, float y); void forcePos(); void setTargetMiddlePos(float targetX, float targetY); float getOffsetX(); float getOffsetY(); boolean canScrollX(float deltaX); boolean canScrollY(float deltaY); void setXBounds(float minX, float maxX); void setYBounds(float minY, float maxY); void setBounds(float minX, float maxX, float minY, float maxY); void resetPosition(); void resetBounds(); void reset(); Matrix4 getCombined(); Matrix4 getViewMatrix(); Matrix4 getProjectionMatrix(); Frustum getFrustum(); Vector3 getMousePosition(); @Override void onModificationFinished(T mod, Class<T> cls); void registerMod(T mod, Class<T> cls); void removeMod(Class<T> cls); T getMod(Class<T> cls); void activateMod(Class<T> cls); void deactivateMod(Class<T> cls); OrthographicCamera getOriginalCamera(); int countActiveMods(); @Override String toString();  }