From 886d2b03b8806e61b2cca276d4d7273620978a68 Mon Sep 17 00:00:00 2001 From: badlogic Date: Sun, 6 Oct 2013 15:25:23 +0200 Subject: [PATCH] added PixelPerfectTest, removed iso cam stuff from ortho camera --- .../badlogic/gdx/graphics/OrthographicCamera.java | 60 -------- .../gdx/tests/lwjgl/LwjglDebugStarter.java | 7 +- .../src/com/badlogic/gdx/tests/IsoCamTest.java | 151 --------------------- .../com/badlogic/gdx/tests/PixelPerfectTest.java | 42 ++++++ .../com/badlogic/gdx/tests/gwt/GwtTestWrapper.java | 6 - .../src/com/badlogic/gdx/tests/utils/GdxTests.java | 2 +- 6 files changed, 47 insertions(+), 221 deletions(-) delete mode 100644 tests/gdx-tests/src/com/badlogic/gdx/tests/IsoCamTest.java create mode 100644 tests/gdx-tests/src/com/badlogic/gdx/tests/PixelPerfectTest.java diff --git a/gdx/src/com/badlogic/gdx/graphics/OrthographicCamera.java b/gdx/src/com/badlogic/gdx/graphics/OrthographicCamera.java index e01a88ce7..263b80ff4 100644 --- a/gdx/src/com/badlogic/gdx/graphics/OrthographicCamera.java +++ b/gdx/src/com/badlogic/gdx/graphics/OrthographicCamera.java @@ -44,66 +44,6 @@ public class OrthographicCamera extends Camera { update(); } - /** Constructs a new OrthographicCamera, using the given viewport width and height. This will create a camera useable for - * iso-metric views. The diamond angle is specifies the angle of a tile viewed isometrically. - * - * @param viewportWidth the viewport width - * @param viewportHeight the viewport height - * @param diamondAngle the angle in degrees */ - public OrthographicCamera (float viewportWidth, float viewportHeight, float diamondAngle) { - this.viewportWidth = viewportWidth; - this.viewportHeight = viewportHeight; - this.near = 0; - findDirectionForIsoView(diamondAngle, 0.00000001f, 20); - update(); - } - - public void findDirectionForIsoView (float targetAngle, float epsilon, int maxIterations) { - float start = targetAngle - 5; - float end = targetAngle + 5; - float mid = targetAngle; - - int iterations = 0; - float aMid = 0; - while (Math.abs(targetAngle - aMid) > epsilon && iterations++ < maxIterations) { - aMid = calculateAngle(mid); - - if (targetAngle < aMid) { - end = mid; - } else { - start = mid; - } - mid = start + (end - start) / 2; - } - position.set(calculateDirection(mid)); - position.y = -position.y; - lookAt(0, 0, 0); - normalizeUp(); - } - - private float calculateAngle (float a) { - Vector3 camPos = calculateDirection(a); - position.set(camPos.scl(30)); - lookAt(0, 0, 0); - normalizeUp(); - update(); - - Vector3 orig = new Vector3(0, 0, 0); - Vector3 vec = new Vector3(1, 0, 0); - project(orig); - project(vec); - Vector2 d = new Vector2(vec.x - orig.x, -(vec.y - orig.y)); - return d.angle(); - } - - private Vector3 calculateDirection (float angle) { - Matrix4 transform = new Matrix4(); - Vector3 dir = new Vector3(-1, 0, 1).nor(); - transform.setToRotation(new Vector3(1, 0, 1).nor(), angle); - dir.mul(transform).nor(); - return dir; - } - private final Vector3 tmp = new Vector3(); @Override diff --git a/tests/gdx-tests-lwjgl/src/com/badlogic/gdx/tests/lwjgl/LwjglDebugStarter.java b/tests/gdx-tests-lwjgl/src/com/badlogic/gdx/tests/lwjgl/LwjglDebugStarter.java index 2726c39e7..8d13ab929 100644 --- a/tests/gdx-tests-lwjgl/src/com/badlogic/gdx/tests/lwjgl/LwjglDebugStarter.java +++ b/tests/gdx-tests-lwjgl/src/com/badlogic/gdx/tests/lwjgl/LwjglDebugStarter.java @@ -31,6 +31,7 @@ import com.badlogic.gdx.tests.DelaunayTriangulatorTest; import com.badlogic.gdx.tests.EarClippingTriangulatorTest; import com.badlogic.gdx.tests.MeshShaderTest; import com.badlogic.gdx.tests.MipMapTest; +import com.badlogic.gdx.tests.PixelPerfectTest; import com.badlogic.gdx.tests.TextureAtlasTest; import com.badlogic.gdx.tests.TimerTest; import com.badlogic.gdx.tests.g3d.Basic3DSceneTest; @@ -53,11 +54,11 @@ public class LwjglDebugStarter { // new SharedLibraryLoader("../../extensions/gdx-controllers/gdx-controllers-desktop/libs/gdx-controllers-desktop-natives.jar").load("gdx-controllers-desktop"); // new SharedLibraryLoader("../../gdx/libs/gdx-natives.jar").load("gdx"); - GdxTest test = new NetAPITest(); + GdxTest test = new PixelPerfectTest(); LwjglApplicationConfiguration config = new LwjglApplicationConfiguration(); config.useGL20 = test.needsGL20(); - config.width = 1024; - config.height = 768; + config.width = 320; + config.height = 240; new LwjglApplication(test, config); } } diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/IsoCamTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/IsoCamTest.java deleted file mode 100644 index 8b33eb893..000000000 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/IsoCamTest.java +++ /dev/null @@ -1,151 +0,0 @@ -/******************************************************************************* - * Copyright 2011 See AUTHORS file. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - ******************************************************************************/ - -package com.badlogic.gdx.tests; - -import com.badlogic.gdx.Gdx; -import com.badlogic.gdx.InputAdapter; -import com.badlogic.gdx.graphics.Camera; -import com.badlogic.gdx.graphics.GL10; -import com.badlogic.gdx.graphics.OrthographicCamera; -import com.badlogic.gdx.graphics.Texture; -import com.badlogic.gdx.graphics.g2d.Sprite; -import com.badlogic.gdx.graphics.g2d.SpriteBatch; -import com.badlogic.gdx.math.Intersector; -import com.badlogic.gdx.math.Matrix4; -import com.badlogic.gdx.math.Plane; -import com.badlogic.gdx.math.Vector3; -import com.badlogic.gdx.math.collision.Ray; -import com.badlogic.gdx.tests.utils.GdxTest; - -public class IsoCamTest extends GdxTest { - private static final int TARGET_WIDTH = 480; - private static final float UNIT_TO_PIXEL = TARGET_WIDTH * 0.15f; - Texture texture; - OrthographicCamera cam; - SpriteBatch batch; - final Sprite[][] sprites = new Sprite[10][10]; - final Matrix4 matrix = new Matrix4(); - - @Override - public void create () { - texture = new Texture(Gdx.files.internal("data/badlogicsmall.jpg")); - float unitsOnX = (float)Math.sqrt(2) * TARGET_WIDTH / (UNIT_TO_PIXEL); - float pixelsOnX = Gdx.graphics.getWidth() / unitsOnX; - float unitsOnY = Gdx.graphics.getHeight() / pixelsOnX; - cam = new OrthographicCamera(unitsOnX, unitsOnY, 25); - cam.position.scl(30); - cam.near = 1; - cam.far = 1000; - matrix.setToRotation(new Vector3(1, 0, 0), 90); - - for (int z = 0; z < 10; z++) { - for (int x = 0; x < 10; x++) { - sprites[x][z] = new Sprite(texture); - sprites[x][z].setPosition(x, z); - sprites[x][z].setSize(1, 1); - } - } - - batch = new SpriteBatch(); - - Gdx.input.setInputProcessor(new IsoCamController(cam)); - } - - @Override - public void dispose () { - texture.dispose(); - batch.dispose(); - } - - @Override - public void render () { - Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT); - cam.update(); - - batch.setProjectionMatrix(cam.combined); - batch.setTransformMatrix(matrix); - batch.begin(); - for (int z = 0; z < 10; z++) { - for (int x = 0; x < 10; x++) { - sprites[x][z].draw(batch); - } - } - batch.end(); - - checkTileTouched(); - } - - final Plane xzPlane = new Plane(new Vector3(0, 1, 0), 0); - final Vector3 intersection = new Vector3(); - Sprite lastSelectedTile = null; - - private void checkTileTouched () { - if (Gdx.input.justTouched()) { - Ray pickRay = cam.getPickRay(Gdx.input.getX(), Gdx.input.getY()); - Intersector.intersectRayPlane(pickRay, xzPlane, intersection); - System.out.println(intersection); - int x = (int)intersection.x; - int z = (int)intersection.z; - if (x >= 0 && x < 10 && z >= 0 && z < 10) { - if (lastSelectedTile != null) lastSelectedTile.setColor(1, 1, 1, 1); - Sprite sprite = sprites[x][z]; - sprite.setColor(1, 0, 0, 1); - lastSelectedTile = sprite; - } - } - } - - public class IsoCamController extends InputAdapter { - final Plane xzPlane = new Plane(new Vector3(0, 1, 0), 0); - final Vector3 intersection = new Vector3(); - final Vector3 curr = new Vector3(); - final Vector3 last = new Vector3(-1, -1, -1); - final Vector3 delta = new Vector3(); - final Camera camera; - - public IsoCamController (Camera camera) { - this.camera = camera; - } - - @Override - public boolean touchDragged (int x, int y, int pointer) { - Ray pickRay = camera.getPickRay(x, y); - Intersector.intersectRayPlane(pickRay, xzPlane, curr); - - if (!(last.x == -1 && last.y == -1 && last.z == -1)) { - pickRay = camera.getPickRay(last.x, last.y); - Intersector.intersectRayPlane(pickRay, xzPlane, delta); - delta.sub(curr); - camera.position.add(delta.x, 0, delta.z); - } - last.set(x, y, 0); - return false; - } - - @Override - public boolean touchUp (int x, int y, int pointer, int button) { - last.set(-1, -1, -1); - return false; - } - } - - @Override - public boolean needsGL20 () { - return false; - } - -} diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/PixelPerfectTest.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/PixelPerfectTest.java new file mode 100644 index 000000000..c4d05e801 --- /dev/null +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/PixelPerfectTest.java @@ -0,0 +1,42 @@ +package com.badlogic.gdx.tests; + +import com.badlogic.gdx.Gdx; +import com.badlogic.gdx.graphics.Color; +import com.badlogic.gdx.graphics.GL20; +import com.badlogic.gdx.graphics.OrthographicCamera; +import com.badlogic.gdx.graphics.Pixmap; +import com.badlogic.gdx.graphics.Texture; +import com.badlogic.gdx.graphics.g2d.SpriteBatch; +import com.badlogic.gdx.tests.utils.GdxTest; + +public class PixelPerfectTest extends GdxTest { + SpriteBatch batch; + OrthographicCamera cam; + Texture tex; + + @Override + public void create () { + Pixmap pixmap = new Pixmap(16, 16, Pixmap.Format.RGBA8888); + pixmap.setColor(Color.BLUE); + pixmap.fill(); + pixmap.setColor(Color.RED); + pixmap.drawLine(0, 0, 15, 15); + pixmap.drawLine(0, 15, 15, 0); + + tex = new Texture(pixmap); + batch = new SpriteBatch(); + cam = new OrthographicCamera(); + cam.setToOrtho(false, Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); + } + + @Override + public void render () { + Gdx.gl.glClearColor(1, 0, 1, 1); + Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); + cam.update(); + batch.setProjectionMatrix(cam.combined); + batch.begin(); + batch.draw(tex, 1, 1); + batch.end(); + } +} diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/gwt/GwtTestWrapper.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/gwt/GwtTestWrapper.java index 4b3ce83f8..5427b87c6 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/gwt/GwtTestWrapper.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/gwt/GwtTestWrapper.java @@ -63,7 +63,6 @@ import com.badlogic.gdx.tests.ImageTest; import com.badlogic.gdx.tests.IndexBufferObjectShaderTest; import com.badlogic.gdx.tests.IntegerBitmapFontTest; import com.badlogic.gdx.tests.InverseKinematicsTest; -import com.badlogic.gdx.tests.IsoCamTest; import com.badlogic.gdx.tests.IsometricTileTest; import com.badlogic.gdx.tests.KinematicBodyTest; import com.badlogic.gdx.tests.LabelScaleTest; @@ -78,7 +77,6 @@ import com.badlogic.gdx.tests.ParticleEmitterTest; import com.badlogic.gdx.tests.PixelsPerInchTest; import com.badlogic.gdx.tests.ProjectiveTextureTest; import com.badlogic.gdx.tests.RotationTest; -import com.badlogic.gdx.tests.RunnablePostTest; import com.badlogic.gdx.tests.ShadowMappingTest; import com.badlogic.gdx.tests.ShapeRendererTest; import com.badlogic.gdx.tests.SimpleAnimationTest; @@ -530,10 +528,6 @@ public class GwtTestWrapper extends GdxTest { } }, new Instancer() { public GdxTest instance () { - return new IsoCamTest(); - } - }, new Instancer() { - public GdxTest instance () { return new IsometricTileTest(); } }, new Instancer() { diff --git a/tests/gdx-tests/src/com/badlogic/gdx/tests/utils/GdxTests.java b/tests/gdx-tests/src/com/badlogic/gdx/tests/utils/GdxTests.java index b2b6a3362..43dedb6e4 100644 --- a/tests/gdx-tests/src/com/badlogic/gdx/tests/utils/GdxTests.java +++ b/tests/gdx-tests/src/com/badlogic/gdx/tests/utils/GdxTests.java @@ -65,7 +65,7 @@ public class GdxTests { ScrollPaneTest.class, FloatTest.class, FloatTextureTest.class, FrameBufferTest.class, FramebufferToTextureTest.class, FrustumTest.class, FullscreenTest.class, Gdx2DTest.class, GroupFadeTest.class, ImmediateModeRendererTest.class, Scene2dTest.class, ImmediateModeRendererAlphaTest.class, IndexBufferObjectClassTest.class, TreeTest.class, IndexBufferObjectShaderTest.class, - InputTest.class, IntegerBitmapFontTest.class, InverseKinematicsTest.class, IsoCamTest.class, IsometricTileTest.class, + InputTest.class, IntegerBitmapFontTest.class, InverseKinematicsTest.class, IsometricTileTest.class, KinematicBodyTest.class, LifeCycleTest.class, LineDrawingTest.class, ScrollPane2Test.class, ManagedTest.class, ManualBindTest.class, MaterialTest.class, MatrixJNITest.class, MeshMultitextureTest.class, MeshShaderTest.class, MeshTest.class, MipMapTest.class, MultitouchTest.class, MusicTest.class, MyFirstTriangle.class, ObjTest.class, OnscreenKeyboardTest.class, -- 2.11.0