Got this thing to render on Ouya.
This commit is contained in:
@@ -46,6 +46,8 @@ public class NxtARCore implements ApplicationListener, NetworkConnectionListener
|
|||||||
private static final String TAG = "NXTAR_CORE_MAIN";
|
private static final String TAG = "NXTAR_CORE_MAIN";
|
||||||
private static final String CLASS_NAME = NxtARCore.class.getSimpleName();
|
private static final String CLASS_NAME = NxtARCore.class.getSimpleName();
|
||||||
|
|
||||||
|
private float overscan;
|
||||||
|
|
||||||
private OrthographicCamera camera;
|
private OrthographicCamera camera;
|
||||||
private OrthographicCamera pixelPerfectCamera;
|
private OrthographicCamera pixelPerfectCamera;
|
||||||
private SpriteBatch batch;
|
private SpriteBatch batch;
|
||||||
@@ -88,8 +90,6 @@ public class NxtARCore implements ApplicationListener, NetworkConnectionListener
|
|||||||
@Override
|
@Override
|
||||||
public void create(){
|
public void create(){
|
||||||
image = null;
|
image = null;
|
||||||
fontX = -(Gdx.graphics.getWidth() / 2) + 10;
|
|
||||||
fontY = (Gdx.graphics.getHeight() / 2) - 10;
|
|
||||||
win2world = new Vector3(0.0f, 0.0f, 0.0f);
|
win2world = new Vector3(0.0f, 0.0f, 0.0f);
|
||||||
touchPointWorldCoords = new Vector2();
|
touchPointWorldCoords = new Vector2();
|
||||||
motorButtonsTouched = new boolean[4];
|
motorButtonsTouched = new boolean[4];
|
||||||
@@ -109,15 +109,22 @@ public class NxtARCore implements ApplicationListener, NetworkConnectionListener
|
|||||||
font = new BitmapFont();
|
font = new BitmapFont();
|
||||||
|
|
||||||
font.setColor(1.0f, 1.0f, 0.0f, 1.0f);
|
font.setColor(1.0f, 1.0f, 0.0f, 1.0f);
|
||||||
|
if(!Ouya.runningOnOuya){
|
||||||
font.setScale(1.0f);
|
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);
|
//Gdx.app.setLogLevel(Application.LOG_NONE);
|
||||||
|
|
||||||
pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
camera = new OrthographicCamera(1.0f, Gdx.graphics.getHeight() / Gdx.graphics.getWidth());
|
camera = new OrthographicCamera(1.0f, Gdx.graphics.getHeight() / Gdx.graphics.getWidth());
|
||||||
batch = new SpriteBatch();
|
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();
|
if(!Ouya.runningOnOuya) setUpButtons();
|
||||||
|
|
||||||
Gdx.app.debug(TAG, CLASS_NAME + ".create() :: Creating network threads");
|
Gdx.app.debug(TAG, CLASS_NAME + ".create() :: Creating network threads");
|
||||||
@@ -137,7 +144,9 @@ public class NxtARCore implements ApplicationListener, NetworkConnectionListener
|
|||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
batch.dispose();
|
batch.dispose();
|
||||||
|
if(texture != null)
|
||||||
texture.dispose();
|
texture.dispose();
|
||||||
|
if(buttonTexture != null)
|
||||||
buttonTexture.dispose();
|
buttonTexture.dispose();
|
||||||
font.dispose();
|
font.dispose();
|
||||||
image.dispose();
|
image.dispose();
|
||||||
@@ -178,15 +187,19 @@ public class NxtARCore implements ApplicationListener, NetworkConnectionListener
|
|||||||
if(!Ouya.runningOnOuya){
|
if(!Ouya.runningOnOuya){
|
||||||
sprite.setSize(1.0f, sprite.getHeight() / sprite.getWidth() );
|
sprite.setSize(1.0f, sprite.getHeight() / sprite.getWidth() );
|
||||||
sprite.rotate90(true);
|
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());
|
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);
|
batch.setProjectionMatrix(camera.combined);
|
||||||
|
}else{
|
||||||
|
batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
||||||
|
}
|
||||||
batch.begin();{
|
batch.begin();{
|
||||||
sprite.draw(batch);
|
sprite.draw(batch);
|
||||||
}batch.end();
|
}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("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("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);
|
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();
|
}batch.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,6 +309,7 @@ public class NxtARCore implements ApplicationListener, NetworkConnectionListener
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
|
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
|
||||||
|
if(!Ouya.runningOnOuya){
|
||||||
win2world.set(screenX, screenY, 0.0f);
|
win2world.set(screenX, screenY, 0.0f);
|
||||||
camera.unproject(win2world);
|
camera.unproject(win2world);
|
||||||
touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight());
|
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;
|
motorButtonsTouched[3] = true;
|
||||||
motorButtonsPointers[3] = pointer;
|
motorButtonsPointers[3] = pointer;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
|
||||||
|
if(!Ouya.runningOnOuya){
|
||||||
win2world.set(screenX, screenY, 0.0f);
|
win2world.set(screenX, screenY, 0.0f);
|
||||||
camera.unproject(win2world);
|
camera.unproject(win2world);
|
||||||
touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight());
|
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;
|
motorButtonsPointers[3] = -1;
|
||||||
motorButtonsTouched[3] = false;
|
motorButtonsTouched[3] = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean touchDragged(int screenX, int screenY, int pointer) {
|
public boolean touchDragged(int screenX, int screenY, int pointer) {
|
||||||
|
if(!Ouya.runningOnOuya){
|
||||||
win2world.set(screenX, screenY, 0.0f);
|
win2world.set(screenX, screenY, 0.0f);
|
||||||
camera.unproject(win2world);
|
camera.unproject(win2world);
|
||||||
touchPointWorldCoords.set(win2world.x * Gdx.graphics.getWidth(), win2world.y * Gdx.graphics.getHeight());
|
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)){
|
if(pointer == motorButtonsPointers[0] && !motorA.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Motor A button released");
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Motor A button released");
|
||||||
motorButtonsPointers[0] = -1;
|
motorButtonsPointers[0] = -1;
|
||||||
@@ -376,12 +393,13 @@ public class NxtARCore implements ApplicationListener, NetworkConnectionListener
|
|||||||
motorButtonsPointers[3] = -1;
|
motorButtonsPointers[3] = -1;
|
||||||
motorButtonsTouched[3] = false;
|
motorButtonsTouched[3] = false;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean mouseMoved(int screenX, int screenY) {
|
public boolean mouseMoved(int screenX, int screenY) {
|
||||||
// TODO Auto-generated method stub
|
Gdx.app.error(TAG, "MOUSE MOVED!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user