Got this thing to render on Ouya.

This commit is contained in:
2014-01-29 03:30:40 -04:30
parent e5b43beaea
commit 5c795ce8e3

View File

@@ -46,6 +46,8 @@ public class NxtARCore implements ApplicationListener, NetworkConnectionListener
private static final String TAG = "NXTAR_CORE_MAIN";
private static final String CLASS_NAME = NxtARCore.class.getSimpleName();
private float overscan;
private OrthographicCamera camera;
private OrthographicCamera pixelPerfectCamera;
private SpriteBatch batch;
@@ -88,8 +90,6 @@ public class NxtARCore implements ApplicationListener, NetworkConnectionListener
@Override
public void create(){
image = null;
fontX = -(Gdx.graphics.getWidth() / 2) + 10;
fontY = (Gdx.graphics.getHeight() / 2) - 10;
win2world = new Vector3(0.0f, 0.0f, 0.0f);
touchPointWorldCoords = new Vector2();
motorButtonsTouched = new boolean[4];
@@ -109,15 +109,22 @@ public class NxtARCore implements ApplicationListener, NetworkConnectionListener
font = new BitmapFont();
font.setColor(1.0f, 1.0f, 0.0f, 1.0f);
if(!Ouya.runningOnOuya){
font.setScale(1.0f);
}else{
font.setScale(2.5f);
}
Gdx.app.setLogLevel(Application.LOG_DEBUG);
Gdx.app.setLogLevel(Application.LOG_INFO);
//Gdx.app.setLogLevel(Application.LOG_NONE);
pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
camera = new OrthographicCamera(1.0f, Gdx.graphics.getHeight() / Gdx.graphics.getWidth());
batch = new SpriteBatch();
overscan = Ouya.runningOnOuya ? 0.9f : 1.0f;
fontX = -((Gdx.graphics.getWidth() * overscan) / 2) + 10;
fontY = ((Gdx.graphics.getHeight() * overscan) / 2) - 10;
if(!Ouya.runningOnOuya) setUpButtons();
Gdx.app.debug(TAG, CLASS_NAME + ".create() :: Creating network threads");
@@ -137,7 +144,9 @@ public class NxtARCore implements ApplicationListener, NetworkConnectionListener
@Override
public void dispose() {
batch.dispose();
if(texture != null)
texture.dispose();
if(buttonTexture != null)
buttonTexture.dispose();
font.dispose();
image.dispose();
@@ -178,15 +187,19 @@ public class NxtARCore implements ApplicationListener, NetworkConnectionListener
if(!Ouya.runningOnOuya){
sprite.setSize(1.0f, sprite.getHeight() / sprite.getWidth() );
sprite.rotate90(true);
}else{
//float scaleRatioY = Gdx.graphics.getHeight() / dimensions.getHeight();
//sprite.scale(scaleRatioY);
//sprite.setSize(dimensions.getWidth() * scaleRatioY, dimensions.getHeight() * scaleRatioY);
sprite.setSize(1.0f, sprite.getHeight() / sprite.getWidth() );
}
sprite.translate(-sprite.getWidth() / 2, 0.5f - sprite.getHeight());
}else{
float xSize = Gdx.graphics.getHeight() * (dimensions.getWidth() / dimensions.getHeight());
sprite.setSize(xSize * overscan, Gdx.graphics.getHeight() * overscan);
sprite.rotate90(true);
sprite.translate(-sprite.getWidth() / 2, -sprite.getHeight() / 2);
}
if(!Ouya.runningOnOuya){
batch.setProjectionMatrix(camera.combined);
}else{
batch.setProjectionMatrix(pixelPerfectCamera.combined);
}
batch.begin();{
sprite.draw(batch);
}batch.end();
@@ -205,6 +218,8 @@ public class NxtARCore implements ApplicationListener, NetworkConnectionListener
font.draw(batch, String.format("Render FPS: %d", Gdx.graphics.getFramesPerSecond()), fontX, fontY);
font.draw(batch, String.format("Network FPS: %d", videoThread.getFps()), fontX, fontY - font.getCapHeight() - 5);
font.draw(batch, String.format("Lost Network FPS: %d", videoThread.getLostFrames()), fontX, fontY - (2 * font.getCapHeight()) - 10);
if(dimensions != null)
font.draw(batch, String.format("Frame size: (%d, %d)", dimensions.getWidth(), dimensions.getHeight()), fontX, fontY - (3 * font.getCapHeight()) - 15);
}batch.end();
}
@@ -294,6 +309,7 @@ public class NxtARCore implements ApplicationListener, NetworkConnectionListener
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
if(!Ouya.runningOnOuya){
win2world.set(screenX, screenY, 0.0f);
camera.unproject(win2world);
touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight());
@@ -318,11 +334,13 @@ public class NxtARCore implements ApplicationListener, NetworkConnectionListener
motorButtonsTouched[3] = true;
motorButtonsPointers[3] = pointer;
}
}
return true;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
if(!Ouya.runningOnOuya){
win2world.set(screenX, screenY, 0.0f);
camera.unproject(win2world);
touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight());
@@ -347,18 +365,17 @@ public class NxtARCore implements ApplicationListener, NetworkConnectionListener
motorButtonsPointers[3] = -1;
motorButtonsTouched[3] = false;
}
}
return true;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
if(!Ouya.runningOnOuya){
win2world.set(screenX, screenY, 0.0f);
camera.unproject(win2world);
touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight());
/*Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp(%d, %d, %d)", screenX, screenY, pointer));
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp() :: Unprojected touch point: (%f, %f)", touchPountWorldCoords.x, touchPountWorldCoords.y));*/
if(pointer == motorButtonsPointers[0] && !motorA.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Motor A button released");
motorButtonsPointers[0] = -1;
@@ -376,12 +393,13 @@ public class NxtARCore implements ApplicationListener, NetworkConnectionListener
motorButtonsPointers[3] = -1;
motorButtonsTouched[3] = false;
}
}
return true;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
// TODO Auto-generated method stub
Gdx.app.error(TAG, "MOUSE MOVED!");
return false;
}