Skip to content

Commit

Permalink
Enabled y-up viewport!
Browse files Browse the repository at this point in the history
  • Loading branch information
Regiden committed Sep 21, 2012
1 parent 7bca2c1 commit 968e1d2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 25 deletions.
16 changes: 15 additions & 1 deletion _RadicalFishGDX/src/de/radicalfish/graphics/Graphics.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
* A wrapper for translating the context, drawing sprites with the {@link SpriteBatch} and drawing primitives.
*
* @author Stefan Lange
* @version 0.8.0
* @version 1.0.0
* @since 08.08.2012
*/
public class Graphics implements Disposable {
Expand Down Expand Up @@ -473,6 +473,13 @@ public void setBlendMode(int src, int dst) {
spriteBatch.setBlendFunction(src, dst);
}

/**
* Sets the y direction of the viewport. true stand for y-down while false stand for y-up.
*/
public void setYDown(boolean ydown) {
gContext.setYDown(ydown);
}

// GETTER
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
/**
Expand Down Expand Up @@ -521,6 +528,13 @@ public float getScaleY() {
return gContext.getScaleY();
}

/**
* @return true if the viewport direction is y-down, false otherwise.
*/
public boolean isYDown() {
return gContext.isYDown();
}

// INTERN CLASSES
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
private static class GraphicsTransform {
Expand Down
65 changes: 41 additions & 24 deletions _RadicalFishGDX/src/de/radicalfish/graphics/GraphicsContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,21 @@
* scaling, translating the whole context.
*
* @author Stefan Lange
* @version 0.0.0
* @version 1.0.0
* @since 09.08.2012
*/
public class GraphicsContext extends OrthographicCamera {

private final Vector3 temp;
private static final Vector3 temp = new Vector3();
private static float y, height;

private float scaleX, scaleY;
private float scaleX = 1.0f, scaleY = 1.0f;
private boolean ydown = true;

public GraphicsContext(int viewportWidth, int viewportHeight) {
scaleX = 1.0f;
scaleY = 1.0f;
temp = new Vector3();

this.viewportWidth = viewportWidth;
this.viewportHeight = viewportHeight;
this.near = 0;

}

// METHODS
Expand All @@ -74,34 +71,22 @@ public void scale(float x, float y) {
scaleX *= x;
scaleY *= y;
}
/**
* sets the scale on both axis.
*/
public void setScale(float scale) {
scaleX = scale;
scaleY = scale;
}
/**
* Sets <code>x</code> and <code>y</code> to the x scale and y scale.
*/
public void setScale(float x, float y) {
scaleX = x;
scaleY = y;
}

// OVERRIDE
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
public void update() {
checkScale();
projection.setToOrtho(0, viewportWidth / scaleX, viewportHeight / scaleY, 0, Math.abs(near), Math.abs(far));
y = ydown ? viewportHeight / scaleY : 0;
height = ydown ? 0 : viewportHeight / scaleY;
projection.setToOrtho(0, viewportWidth / scaleX, y, height, Math.abs(near), Math.abs(far));
view.setToLookAt(position, temp.set(position).add(direction), up);
combined.set(projection);
Matrix4.mul(combined.val, view.val);
invProjectionView.set(combined);
Matrix4.inv(invProjectionView.val);
frustum.update(invProjectionView);
}
public void setToOrtho (float viewportWidth, float viewportHeight) {
public void setToOrtho(float viewportWidth, float viewportHeight) {
this.viewportWidth = viewportWidth;
this.viewportHeight = viewportHeight;
update();
Expand All @@ -118,8 +103,40 @@ private void checkScale() {
}
}

// SETTER
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
/**
* Sets the y direction of the viewport. true stand for y-down while false stand for y-up.
*/
public void setYDown(boolean ydown) {
this.ydown = ydown;
update();
}

/**
* sets the scale on both axis.
*/
public void setScale(float scale) {
scaleX = scale;
scaleY = scale;
}
/**
* Sets <code>x</code> and <code>y</code> to the x scale and y scale.
*/
public void setScale(float x, float y) {
scaleX = x;
scaleY = y;
}

// GETTER
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯
/**
* @return true if the viewport direction is y-down, false otherwise.
*/
public boolean isYDown() {
return ydown;
}

public float getScaleX() {
return scaleX;
}
Expand Down

0 comments on commit 968e1d2

Please sign in to comment.