summaryrefslogtreecommitdiffstats
path: root/core/src
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2015-01-06 12:08:18 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2015-01-06 12:08:18 +0100
commit0ed98a8a3c3dbd66d80b6c13dbb8c94b850ca7cd (patch)
treec9441e48e64168b63a0df467d264ae657fb70b0b /core/src
parent626dd256d06ae65328065a4bb3e8590fb6cd4d99 (diff)
downloadRustAndDust-0ed98a8a3c3dbd66d80b6c13dbb8c94b850ca7cd.zip
RustAndDust-0ed98a8a3c3dbd66d80b6c13dbb8c94b850ca7cd.tar.gz
GameCamera: adapt viewport and window width on zoom
Diffstat (limited to 'core/src')
-rw-r--r--core/src/ch/asynk/tankontank/screens/GameCamera.java22
-rw-r--r--core/src/ch/asynk/tankontank/screens/GameScreen.java2
2 files changed, 15 insertions, 9 deletions
diff --git a/core/src/ch/asynk/tankontank/screens/GameCamera.java b/core/src/ch/asynk/tankontank/screens/GameCamera.java
index 94b31c0..b812269 100644
--- a/core/src/ch/asynk/tankontank/screens/GameCamera.java
+++ b/core/src/ch/asynk/tankontank/screens/GameCamera.java
@@ -20,6 +20,7 @@ public class GameCamera extends OrthographicCamera
private float viewportAspect;
private float widthFactor;
private float heightFactor;
+ private Rectangle virtual;
private Rectangle window;
private Matrix4 hudMatrix;
private Matrix4 hudInvProjMatrix;
@@ -30,6 +31,8 @@ public class GameCamera extends OrthographicCamera
this.zoomOut = zoomOut;
this.zoomIn = zoomIn;
this.viewportAspect = (viewportWidth / viewportHeight);
+ this.virtual = new Rectangle();
+ this.virtual.set(0, 0, virtualWidth, virtualHeight);
this.window = new Rectangle();
this.hudMatrix = new Matrix4();
this.hudInvProjMatrix = new Matrix4();
@@ -44,15 +47,17 @@ public class GameCamera extends OrthographicCamera
float diff = (viewportAspect - aspect);
if (diff < -ZEROF) {
- window.width = (screenHeight * viewportAspect);
+ window.width = java.lang.Math.min((screenHeight * viewportAspect / zoom), screenWidth);
window.height = screenHeight;
window.x = ((screenWidth - window.width) / 2f);
window.y = 0f;
+ viewportWidth = (viewportHeight * (window.width / window.height));
} else if (diff > ZEROF) {
window.width = screenWidth;
- window.height = (screenWidth / viewportAspect);
+ window.height = java.lang.Math.min((screenWidth * viewportAspect / zoom), screenHeight);
window.x = 0f;
window.y = ((screenHeight - window.height) / 2f);
+ viewportHeight = (viewportWidth * (window.height / window.width));
}
Gdx.gl.glViewport((int)window.x, (int)window.y, (int)window.width, (int)window.height);
@@ -100,7 +105,6 @@ public class GameCamera extends OrthographicCamera
public void zoom(float dz)
{
- // TODO adapt screen -> glViewport
zoom += dz;
clampZoom();
updateViewport(screenWidth, screenHeight);
@@ -125,17 +129,17 @@ public class GameCamera extends OrthographicCamera
float cx = (viewportWidth * zoom);
float cy = (viewportHeight * zoom);
- if ((viewportWidth - cx) > ZEROF) {
+ if ((virtual.width - cx) > ZEROF) {
cx /= 2f;
- position.x = MathUtils.clamp(position.x, cx, (viewportWidth - cx));
+ position.x = MathUtils.clamp(position.x, cx, (virtual.width - cx));
} else
- position.x = (viewportWidth / 2f);
+ position.x = (virtual.width / 2f);
- if ((viewportHeight - cy) > ZEROF) {
+ if ((virtual.height - cy) > ZEROF) {
cy /= 2f;
- position.y = MathUtils.clamp(position.y, cy, (viewportHeight - cy));
+ position.y = MathUtils.clamp(position.y, cy, (virtual.height - cy));
} else
- position.y = (viewportHeight / 2f);
+ position.y = (virtual.height / 2f);
}
public void debug()
diff --git a/core/src/ch/asynk/tankontank/screens/GameScreen.java b/core/src/ch/asynk/tankontank/screens/GameScreen.java
index ec17cd9..0eb16a7 100644
--- a/core/src/ch/asynk/tankontank/screens/GameScreen.java
+++ b/core/src/ch/asynk/tankontank/screens/GameScreen.java
@@ -70,6 +70,7 @@ public class GameScreen implements Screen
cam.zoom(ZOOM_GESTURE_FACTOR);
else
cam.zoom(-ZOOM_GESTURE_FACTOR);
+ ctrl.hud.resize(cam.getHudWidth(), cam.getHudHeight());
blocked = true;
inputDelay = INPUT_DELAY;
return true;
@@ -110,6 +111,7 @@ public class GameScreen implements Screen
public boolean scrolled(int amount)
{
cam.zoom(amount * ZOOM_SCROLL_FACTOR);
+ ctrl.hud.resize(cam.getHudWidth(), cam.getHudHeight());
return true;
}
});