summaryrefslogtreecommitdiffstats
path: root/core/src/ch
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2015-01-05 14:55:19 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2015-01-05 14:55:19 +0100
commit7d346869ba8028b2d12bf2ed2d8bcaa7f11f5766 (patch)
tree863b627dccb5e353e8c566501307f268033f9ab5 /core/src/ch
parentd02429526b4bf74e21583f69a81e84d7679914f2 (diff)
downloadRustAndDust-7d346869ba8028b2d12bf2ed2d8bcaa7f11f5766.zip
RustAndDust-7d346869ba8028b2d12bf2ed2d8bcaa7f11f5766.tar.gz
MenuCamera: replace uiCamera with uiMatrix, and uiInvProjMatrix
Diffstat (limited to 'core/src/ch')
-rw-r--r--core/src/ch/asynk/tankontank/screens/MenuCamera.java26
1 files changed, 20 insertions, 6 deletions
diff --git a/core/src/ch/asynk/tankontank/screens/MenuCamera.java b/core/src/ch/asynk/tankontank/screens/MenuCamera.java
index d71d839..99edc87 100644
--- a/core/src/ch/asynk/tankontank/screens/MenuCamera.java
+++ b/core/src/ch/asynk/tankontank/screens/MenuCamera.java
@@ -13,7 +13,9 @@ public class MenuCamera extends OrthographicCamera
private float virtualAspect;
private final Rectangle virtual;
private final Rectangle window;
- private final OrthographicCamera uiCamera;
+
+ private Matrix4 uiMatrix;
+ private Matrix4 uiInvProjMatrix;
public MenuCamera(int cx, int cy, int width, int height)
{
@@ -24,7 +26,9 @@ public class MenuCamera extends OrthographicCamera
this.window = new Rectangle();
this.window.set(0, 0, 0, 0);
this.position.set(virtual.x, virtual.y, 0f);
- this.uiCamera = new OrthographicCamera();
+
+ this.uiMatrix = new Matrix4();
+ this.uiInvProjMatrix = new Matrix4();
}
public void updateViewport(int screenWidth, int screenHeight)
@@ -46,7 +50,11 @@ public class MenuCamera extends OrthographicCamera
Gdx.gl.glViewport((int)window.x, (int)window.y, (int)window.width, (int)window.height);
update(true);
- uiCamera.setToOrtho(false, screenWidth, screenHeight);
+
+ uiMatrix.set(combined);
+ uiMatrix.setToOrtho2D(0, 0, screenWidth, screenHeight);
+ uiInvProjMatrix.set(uiMatrix);
+ Matrix4.inv(uiInvProjMatrix.val);
}
public float getScreenWidth()
@@ -59,13 +67,19 @@ public class MenuCamera extends OrthographicCamera
return window.height;
}
- public Vector3 uiUnproject(float x, float y, Vector3 v)
+ public void uiUnproject(float x, float y, Vector3 v)
{
- return uiCamera.unproject(v.set(x, y, 0f));
+ x = x - window.x;
+ y = Gdx.graphics.getHeight() - y - 1;
+ y = y - window.y;
+ v.x = (2 * x) / window.width - 1;
+ v.y = (2 * y) / window.height - 1;
+ v.z = 2 * v.z - 1;
+ v.prj(uiInvProjMatrix);
}
public Matrix4 uiCombined()
{
- return uiCamera.combined;
+ return uiMatrix;
}
}