Compare commits
32 Commits
Author | SHA1 | Date | |
---|---|---|---|
fa6950d5c9 | |||
5e66273396 | |||
686f263b0d | |||
5ef7928706 | |||
169d0e7c43 | |||
9a67df8f8a | |||
76a6d8485b | |||
653adc91a7 | |||
a1891f53d2 | |||
a942b0ebd1 | |||
e6085e7a79 | |||
3c65f52e9e | |||
0df8b37ddd | |||
87295031dc | |||
a9fa76cb68 | |||
fbb25ead08 | |||
82e95ed0f7 | |||
b7367427f6 | |||
e6ea6ab4a1 | |||
167b5d644b | |||
e82d49f1f1 | |||
6b54b1364f | |||
de64cd972b | |||
90427419e0 | |||
271b7d003a | |||
1146a260b6 | |||
d8922182e0 | |||
e976a17de0 | |||
11ebf2b96e | |||
139bb62067 | |||
e93d227b62 | |||
06d74a6474 |
Binary file not shown.
BIN
libs/gdx.jar
BIN
libs/gdx.jar
Binary file not shown.
@@ -15,15 +15,15 @@
|
|||||||
*/
|
*/
|
||||||
package ve.ucv.ciens.ccg.nxtar;
|
package ve.ucv.ciens.ccg.nxtar;
|
||||||
|
|
||||||
import ve.ucv.ciens.ccg.nxtar.interfaces.CVProcessor;
|
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor;
|
||||||
import ve.ucv.ciens.ccg.nxtar.interfaces.MulticastEnabler;
|
import ve.ucv.ciens.ccg.nxtar.interfaces.ApplicationEventsListener;
|
||||||
import ve.ucv.ciens.ccg.nxtar.interfaces.NetworkConnectionListener;
|
import ve.ucv.ciens.ccg.nxtar.interfaces.ActionResolver;
|
||||||
import ve.ucv.ciens.ccg.nxtar.interfaces.Toaster;
|
|
||||||
import ve.ucv.ciens.ccg.nxtar.network.RobotControlThread;
|
import ve.ucv.ciens.ccg.nxtar.network.RobotControlThread;
|
||||||
import ve.ucv.ciens.ccg.nxtar.network.SensorReportThread;
|
import ve.ucv.ciens.ccg.nxtar.network.SensorReportThread;
|
||||||
import ve.ucv.ciens.ccg.nxtar.network.ServiceDiscoveryThread;
|
import ve.ucv.ciens.ccg.nxtar.network.ServiceDiscoveryThread;
|
||||||
import ve.ucv.ciens.ccg.nxtar.network.VideoStreamingThread;
|
import ve.ucv.ciens.ccg.nxtar.network.VideoStreamingThread;
|
||||||
import ve.ucv.ciens.ccg.nxtar.states.BaseState;
|
import ve.ucv.ciens.ccg.nxtar.states.BaseState;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.states.CameraCalibrationState;
|
||||||
import ve.ucv.ciens.ccg.nxtar.states.InGameState;
|
import ve.ucv.ciens.ccg.nxtar.states.InGameState;
|
||||||
import ve.ucv.ciens.ccg.nxtar.states.MainMenuStateBase;
|
import ve.ucv.ciens.ccg.nxtar.states.MainMenuStateBase;
|
||||||
import ve.ucv.ciens.ccg.nxtar.states.OuyaMainMenuState;
|
import ve.ucv.ciens.ccg.nxtar.states.OuyaMainMenuState;
|
||||||
@@ -39,12 +39,14 @@ import com.badlogic.gdx.Game;
|
|||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.controllers.Controllers;
|
import com.badlogic.gdx.controllers.Controllers;
|
||||||
import com.badlogic.gdx.controllers.mappings.Ouya;
|
import com.badlogic.gdx.controllers.mappings.Ouya;
|
||||||
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
import com.badlogic.gdx.graphics.Pixmap;
|
import com.badlogic.gdx.graphics.Pixmap;
|
||||||
import com.badlogic.gdx.graphics.Pixmap.Format;
|
import com.badlogic.gdx.graphics.Pixmap.Format;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
|
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Core of the application.</p>
|
* <p>Core of the application.</p>
|
||||||
@@ -55,17 +57,23 @@ import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
|||||||
* <li> Starting and destroying the networking threads.</li>
|
* <li> Starting and destroying the networking threads.</li>
|
||||||
* <li> Rendering debug information.</li>
|
* <li> Rendering debug information.</li>
|
||||||
* </ul>
|
* </ul>
|
||||||
* @author Miguel Angel Astor Romero
|
|
||||||
*/
|
*/
|
||||||
public class NxtARCore extends Game implements NetworkConnectionListener{
|
public class NxtARCore extends Game implements ApplicationEventsListener{
|
||||||
|
/**
|
||||||
|
* Tag used for logging.
|
||||||
|
*/
|
||||||
private static final String TAG = "NXTAR_CORE_MAIN";
|
private static final String TAG = "NXTAR_CORE_MAIN";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class name used for logging.
|
||||||
|
*/
|
||||||
private static final String CLASS_NAME = NxtARCore.class.getSimpleName();
|
private static final String CLASS_NAME = NxtARCore.class.getSimpleName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Valid game states.
|
* Valid game states.
|
||||||
*/
|
*/
|
||||||
public enum game_states_t {
|
public enum game_states_t {
|
||||||
MAIN_MENU(0), IN_GAME(1), PAUSED(2);
|
MAIN_MENU(0), IN_GAME(1), PAUSED(2), CALIBRATION(3);
|
||||||
|
|
||||||
private int value;
|
private int value;
|
||||||
|
|
||||||
@@ -76,6 +84,10 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
public int getValue(){
|
public int getValue(){
|
||||||
return this.value;
|
return this.value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getNumStates(){
|
||||||
|
return 4;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -90,31 +102,98 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
public game_states_t nextState;
|
public game_states_t nextState;
|
||||||
|
|
||||||
// Screens.
|
// Screens.
|
||||||
|
/**
|
||||||
|
* <p>The application states.</p>
|
||||||
|
*/
|
||||||
private BaseState[] states;
|
private BaseState[] states;
|
||||||
|
|
||||||
// Assorted fields.
|
// Assorted fields.
|
||||||
|
/**
|
||||||
|
* <p>Global sprite batch used for rendering trough the application.</p>
|
||||||
|
*/
|
||||||
public SpriteBatch batch;
|
public SpriteBatch batch;
|
||||||
public CVProcessor cvProc;
|
|
||||||
private Toaster toaster;
|
/**
|
||||||
|
* <p>The OpenCV wrapper.</p>
|
||||||
|
*/
|
||||||
|
public ImageProcessor cvProc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Wrapper around the Operating System methods.</p>
|
||||||
|
*/
|
||||||
|
private ActionResolver osFunction;
|
||||||
|
|
||||||
// Networking related fields.
|
// Networking related fields.
|
||||||
|
/**
|
||||||
|
* <p>The number of connections successfully established with the NxtAR-cam application.</p>
|
||||||
|
*/
|
||||||
private int connections;
|
private int connections;
|
||||||
private MulticastEnabler mcastEnabler;
|
|
||||||
|
/**
|
||||||
|
* <p>Worker thread used to broadcast this server over the network.</p>
|
||||||
|
*/
|
||||||
private ServiceDiscoveryThread serviceDiscoveryThread;
|
private ServiceDiscoveryThread serviceDiscoveryThread;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Worker thread used to receive video frames over UDP.<p>
|
||||||
|
*/
|
||||||
private VideoStreamingThread videoThread;
|
private VideoStreamingThread videoThread;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Worker thread used to send control commands to the NxtAR-cam application.
|
||||||
|
*/
|
||||||
private RobotControlThread robotThread;
|
private RobotControlThread robotThread;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Worker thread used to receive sensor data from the NxtAR-cam application.</p>
|
||||||
|
*/
|
||||||
private SensorReportThread sensorThread;
|
private SensorReportThread sensorThread;
|
||||||
|
|
||||||
// Overlays.
|
// Overlays.
|
||||||
|
/**
|
||||||
|
* <p>Camera used to render the debugging overlay.</p>
|
||||||
|
*/
|
||||||
private OrthographicCamera pixelPerfectCamera;
|
private OrthographicCamera pixelPerfectCamera;
|
||||||
private float fontX;
|
|
||||||
private float fontY;
|
/**
|
||||||
|
* <p>The base x coordinate for rendering the debugging overlay.</p>
|
||||||
|
*/
|
||||||
|
private float overlayX;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>The base y coordinate for rendering the debugging overlay.</p>
|
||||||
|
*/
|
||||||
|
private float overlayY;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>The font used to render the debugging overlay.</p>
|
||||||
|
*/
|
||||||
private BitmapFont font;
|
private BitmapFont font;
|
||||||
|
|
||||||
|
// Fade in/out effect fields.
|
||||||
|
/**
|
||||||
|
* <p>The graphic used to render the fading effect.</p>
|
||||||
|
*/
|
||||||
private Texture fadeTexture;
|
private Texture fadeTexture;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>The interpolation value for the fading effect.</p>
|
||||||
|
*/
|
||||||
private MutableFloat alpha;
|
private MutableFloat alpha;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>The fade out interpolator.</p>
|
||||||
|
*/
|
||||||
private Tween fadeOut;
|
private Tween fadeOut;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>The fade in interpolator.</p>
|
||||||
|
*/
|
||||||
private Tween fadeIn;
|
private Tween fadeIn;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Flag used to indicate if a fading effect is active.</p>
|
||||||
|
*/
|
||||||
private boolean fading;
|
private boolean fading;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -122,52 +201,62 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
*/
|
*/
|
||||||
public NxtARCore(Application concreteApp){
|
public NxtARCore(Application concreteApp){
|
||||||
super();
|
super();
|
||||||
|
|
||||||
connections = 0;
|
connections = 0;
|
||||||
|
|
||||||
|
// Check if the concrete application implements all required interfaces.
|
||||||
try{
|
try{
|
||||||
this.toaster = (Toaster)concreteApp;
|
this.osFunction = (ActionResolver)concreteApp;
|
||||||
}catch(ClassCastException cc){
|
}catch(ClassCastException cc){
|
||||||
Gdx.app.debug(TAG, CLASS_NAME + ".Main() :: concreteApp does not implement the Toaster interface. Toasting disabled.");
|
Gdx.app.debug(TAG, CLASS_NAME + ".Main() :: concreteApp does not implement the Toaster interface. Toasting disabled.");
|
||||||
this.toaster = null;
|
this.osFunction = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
try{
|
try{
|
||||||
this.mcastEnabler = (MulticastEnabler)concreteApp;
|
this.cvProc = (ImageProcessor)concreteApp;
|
||||||
}catch(ClassCastException cc){
|
|
||||||
Gdx.app.error(TAG, CLASS_NAME + ".Main() :: concreteApp does not implement MulticastEnabler. Quitting.");
|
|
||||||
Gdx.app.exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
try{
|
|
||||||
this.cvProc = (CVProcessor)concreteApp;
|
|
||||||
}catch(ClassCastException cc){
|
}catch(ClassCastException cc){
|
||||||
Gdx.app.error(TAG, CLASS_NAME + ".Main() :: concreteApp does not implement the CVProcessor interface. Quitting.");
|
Gdx.app.error(TAG, CLASS_NAME + ".Main() :: concreteApp does not implement the CVProcessor interface. Quitting.");
|
||||||
Gdx.app.exit();
|
Gdx.app.exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
; GAME SUPERCLASS METHODS ;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Initialize the member fields and launch the networking threads. Also creates and
|
||||||
|
* sets the application states.</p>
|
||||||
|
*/
|
||||||
public void create(){
|
public void create(){
|
||||||
// Create the state objects.
|
// Create the state objects.
|
||||||
states = new BaseState[3];
|
states = new BaseState[game_states_t.getNumStates()];
|
||||||
if(Ouya.runningOnOuya)
|
if(Ouya.runningOnOuya)
|
||||||
states[game_states_t.MAIN_MENU.getValue()] = new OuyaMainMenuState(this);
|
states[game_states_t.MAIN_MENU.getValue()] = new OuyaMainMenuState(this);
|
||||||
else
|
else
|
||||||
states[game_states_t.MAIN_MENU.getValue()] = new TabletMainMenuState(this);
|
states[game_states_t.MAIN_MENU.getValue()] = new TabletMainMenuState(this);
|
||||||
states[game_states_t.IN_GAME.getValue()] = new InGameState(this);
|
states[game_states_t.IN_GAME.getValue()] = new InGameState(this);
|
||||||
states[game_states_t.PAUSED.getValue()] = new PauseState(this);
|
states[game_states_t.PAUSED.getValue()] = new PauseState(this);
|
||||||
|
states[game_states_t.CALIBRATION.getValue()] = new CameraCalibrationState(this);
|
||||||
|
|
||||||
|
// Register controller listeners.
|
||||||
for(BaseState state : states){
|
for(BaseState state : states){
|
||||||
Controllers.addListener(state);
|
Controllers.addListener(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up fields.
|
// Set up rendering fields and settings.
|
||||||
batch = new SpriteBatch();
|
batch = new SpriteBatch();
|
||||||
|
batch.enableBlending();
|
||||||
|
batch.setBlendFunction(GL20.GL_SRC_ALPHA, GL20.GL_ONE_MINUS_SRC_ALPHA);
|
||||||
|
|
||||||
pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
|
|
||||||
|
ShaderProgram.pedantic = false;
|
||||||
|
|
||||||
|
// Set up the overlay font.
|
||||||
if(ProjectConstants.DEBUG){
|
if(ProjectConstants.DEBUG){
|
||||||
// Set up the overlay font.
|
overlayX = -((Gdx.graphics.getWidth() * ProjectConstants.OVERSCAN) / 2) + 10;
|
||||||
fontX = -((Gdx.graphics.getWidth() * ProjectConstants.OVERSCAN) / 2) + 10;
|
overlayY = ((Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN) / 2) - 10;
|
||||||
fontY = ((Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN) / 2) - 10;
|
|
||||||
|
|
||||||
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);
|
||||||
@@ -179,7 +268,7 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Start networking.
|
// Start networking.
|
||||||
mcastEnabler.enableMulticast();
|
osFunction.enableMulticast();
|
||||||
|
|
||||||
Gdx.app.debug(TAG, CLASS_NAME + ".create() :: Creating network threads");
|
Gdx.app.debug(TAG, CLASS_NAME + ".create() :: Creating network threads");
|
||||||
serviceDiscoveryThread = ServiceDiscoveryThread.getInstance();
|
serviceDiscoveryThread = ServiceDiscoveryThread.getInstance();
|
||||||
@@ -187,6 +276,7 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
robotThread = RobotControlThread.getInstance();
|
robotThread = RobotControlThread.getInstance();
|
||||||
sensorThread = SensorReportThread.getInstance();
|
sensorThread = SensorReportThread.getInstance();
|
||||||
|
|
||||||
|
// Launch networking threads.
|
||||||
serviceDiscoveryThread.start();
|
serviceDiscoveryThread.start();
|
||||||
|
|
||||||
videoThread.start();
|
videoThread.start();
|
||||||
@@ -205,7 +295,7 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
this.setScreen(states[currState.getValue()]);
|
this.setScreen(states[currState.getValue()]);
|
||||||
states[currState.getValue()].onStateSet();
|
states[currState.getValue()].onStateSet();
|
||||||
|
|
||||||
// Prepare the fadeToBlack sprite;
|
// Prepare the fading effect.
|
||||||
Pixmap pixmap = new Pixmap(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), Format.RGBA4444);
|
Pixmap pixmap = new Pixmap(Gdx.graphics.getWidth(), Gdx.graphics.getHeight(), Format.RGBA4444);
|
||||||
pixmap.setColor(0, 0, 0, 1);
|
pixmap.setColor(0, 0, 0, 1);
|
||||||
pixmap.fill();
|
pixmap.fill();
|
||||||
@@ -222,12 +312,18 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
Gdx.input.setInputProcessor(states[currState.getValue()]);
|
Gdx.input.setInputProcessor(states[currState.getValue()]);
|
||||||
Controllers.addListener(states[currState.getValue()]);
|
Controllers.addListener(states[currState.getValue()]);
|
||||||
|
|
||||||
// Anything else.
|
// Set log level
|
||||||
//Gdx.app.setLogLevel(Application.LOG_INFO);
|
if(ProjectConstants.DEBUG){
|
||||||
//Gdx.app.setLogLevel(Application.LOG_DEBUG);
|
Gdx.app.setLogLevel(Application.LOG_DEBUG);
|
||||||
Gdx.app.setLogLevel(Application.LOG_NONE);
|
}else{
|
||||||
|
Gdx.app.setLogLevel(Application.LOG_NONE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Update and render the currently enabled application state. This method
|
||||||
|
* also handles state switching, rendering state transitions and global overlays.</p>
|
||||||
|
*/
|
||||||
public void render(){
|
public void render(){
|
||||||
super.render();
|
super.render();
|
||||||
|
|
||||||
@@ -236,21 +332,23 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
states[currState.getValue()].onStateUnset();
|
states[currState.getValue()].onStateUnset();
|
||||||
|
|
||||||
if(!fadeOut.isStarted()){
|
if(!fadeOut.isStarted()){
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".onRender() :: Starting fade out.");
|
// Start the fade out effect.
|
||||||
fadeOut.start();
|
fadeOut.start();
|
||||||
fading = true;
|
fading = true;
|
||||||
}else{
|
}else{
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".onRender() :: Updating fade out.");
|
// Update the fade out effect.
|
||||||
fadeOut.update(Gdx.graphics.getDeltaTime());
|
fadeOut.update(Gdx.graphics.getDeltaTime());
|
||||||
|
|
||||||
|
// When the fade out effect finishes, change to the requested state
|
||||||
|
// and launh the fade in effect.
|
||||||
if(fadeOut.isFinished()){
|
if(fadeOut.isFinished()){
|
||||||
|
// Change to the requested state.
|
||||||
currState = nextState;
|
currState = nextState;
|
||||||
nextState = null;
|
nextState = null;
|
||||||
|
|
||||||
states[currState.getValue()].onStateSet();
|
states[currState.getValue()].onStateSet();
|
||||||
|
|
||||||
setScreen(states[currState.getValue()]);
|
setScreen(states[currState.getValue()]);
|
||||||
|
|
||||||
|
// Reset the fade out effect and launch the fade in.
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".onRender() :: Freeing fade out.");
|
Gdx.app.log(TAG, CLASS_NAME + ".onRender() :: Freeing fade out.");
|
||||||
fadeOut.free();
|
fadeOut.free();
|
||||||
fadeOut = Tween.to(alpha, 0, 0.5f).target(1.0f).ease(TweenEquations.easeInQuint);
|
fadeOut = Tween.to(alpha, 0, 0.5f).target(1.0f).ease(TweenEquations.easeInQuint);
|
||||||
@@ -259,16 +357,20 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If there is a fade in effect in progress.
|
||||||
if(fadeIn.isStarted()){
|
if(fadeIn.isStarted()){
|
||||||
if(!fadeIn.isFinished()){
|
if(!fadeIn.isFinished()){
|
||||||
|
// Update it until finished.
|
||||||
fadeIn.update(Gdx.graphics.getDeltaTime());
|
fadeIn.update(Gdx.graphics.getDeltaTime());
|
||||||
}else{
|
}else{
|
||||||
|
// Stop and reset it when done.
|
||||||
fading = false;
|
fading = false;
|
||||||
fadeIn.free();
|
fadeIn.free();
|
||||||
fadeIn = Tween.to(alpha, 0, 0.5f).target(0.0f).ease(TweenEquations.easeInQuint);
|
fadeIn = Tween.to(alpha, 0, 0.5f).target(0.0f).ease(TweenEquations.easeInQuint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Render the fading sprite with alpha blending.
|
||||||
if(fading){
|
if(fading){
|
||||||
batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
||||||
batch.begin();{
|
batch.begin();{
|
||||||
@@ -278,28 +380,44 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
}batch.end();
|
}batch.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Render the debug overlay.
|
||||||
if(ProjectConstants.DEBUG){
|
if(ProjectConstants.DEBUG){
|
||||||
batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
||||||
batch.begin();{
|
batch.begin();{
|
||||||
// Draw the FPS overlay.
|
// Draw the FPS overlay.
|
||||||
font.draw(batch, String.format("Render FPS: %d", Gdx.graphics.getFramesPerSecond()), fontX, fontY);
|
font.draw(batch, String.format("Render FPS: %d", Gdx.graphics.getFramesPerSecond()), overlayX, overlayY);
|
||||||
font.draw(batch, String.format("Total stream FPS: %d", videoThread.getFps()), fontX, fontY - font.getCapHeight() - 5);
|
font.draw(batch, String.format("Total stream FPS: %d", videoThread.getFps()), overlayX, overlayY - font.getCapHeight() - 5);
|
||||||
font.draw(batch, String.format("Lost stream FPS: %d", videoThread.getLostFrames()), fontX, fontY - (2 * font.getCapHeight()) - 10);
|
font.draw(batch, String.format("Lost stream FPS: %d", videoThread.getLostFrames()), overlayX, overlayY - (2 * font.getCapHeight()) - 10);
|
||||||
font.draw(batch, String.format("Light sensor data: %d", sensorThread.getLightSensorReading()), fontX, fontY - (3 * font.getCapHeight()) - 15);
|
font.draw(batch, String.format("Light sensor data: %d", sensorThread.getLightSensorReading()), overlayX, overlayY - (3 * font.getCapHeight()) - 15);
|
||||||
}batch.end();
|
}batch.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Pause a currently running thread. Pausing an already paused thread is a
|
||||||
|
* no op.</p>
|
||||||
|
*/
|
||||||
public void pause(){
|
public void pause(){
|
||||||
if(videoThread != null)
|
if(videoThread != null)
|
||||||
videoThread.pause();
|
videoThread.pause();
|
||||||
|
// TODO: Ignore pausing paused threads.
|
||||||
|
// TODO: Pause the other threads.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Resume a currently paused thread. Resuming an already resumed thread is a
|
||||||
|
* no op.</p>
|
||||||
|
*/
|
||||||
public void resume(){
|
public void resume(){
|
||||||
if(videoThread != null)
|
if(videoThread != null)
|
||||||
videoThread.play();
|
videoThread.play();
|
||||||
|
// TODO: Ignore resuming resumed threads.
|
||||||
|
// TODO: Resume the other threads.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Clear graphic resources</p>
|
||||||
|
*/
|
||||||
public void dispose(){
|
public void dispose(){
|
||||||
// Finish network threads.
|
// Finish network threads.
|
||||||
videoThread.finish();
|
videoThread.finish();
|
||||||
@@ -318,6 +436,19 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
; APPLICATION EVENTS LISTENER INTERFACE METHODS ;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
||||||
|
|
||||||
|
// TODO: Disable start game button until camera has been sucessfully calibrated.
|
||||||
|
// TODO: Add calibration listener callback.
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Callback used by the networking threads to notify sucessfull connections
|
||||||
|
* to the application</p>
|
||||||
|
*
|
||||||
|
* @param streamName The name of the thread notifying a connection.
|
||||||
|
*/
|
||||||
@Override
|
@Override
|
||||||
public synchronized void networkStreamConnected(String streamName){
|
public synchronized void networkStreamConnected(String streamName){
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".networkStreamConnected() :: Stream " + streamName + " connected.");
|
Gdx.app.log(TAG, CLASS_NAME + ".networkStreamConnected() :: Stream " + streamName + " connected.");
|
||||||
@@ -326,16 +457,26 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
if(connections >= 3){
|
if(connections >= 3){
|
||||||
Gdx.app.debug(TAG, CLASS_NAME + ".networkStreamConnected() :: Stopping service broadcast.");
|
Gdx.app.debug(TAG, CLASS_NAME + ".networkStreamConnected() :: Stopping service broadcast.");
|
||||||
serviceDiscoveryThread.finish();
|
serviceDiscoveryThread.finish();
|
||||||
mcastEnabler.disableMulticast();
|
osFunction.disableMulticast();
|
||||||
toaster.showShortToast("Client connected");
|
osFunction.showShortToast("Client connected");
|
||||||
((MainMenuStateBase)states[game_states_t.MAIN_MENU.getValue()]).onClientConnected();
|
((MainMenuStateBase)states[game_states_t.MAIN_MENU.getValue()]).onClientConnected();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*;;;;;;;;;;;;;;;;;;
|
||||||
|
; HELPER METHODS ;
|
||||||
|
;;;;;;;;;;;;;;;;;;*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Show a toast message on screen using the O.S. functionality
|
||||||
|
* provider.</p>
|
||||||
|
* @param msg The message to show.
|
||||||
|
* @param longToast True for a lasting toast. False for a short toast.
|
||||||
|
*/
|
||||||
public void toast(String msg, boolean longToast){
|
public void toast(String msg, boolean longToast){
|
||||||
if(toaster != null){
|
if(osFunction != null){
|
||||||
if(longToast) toaster.showLongToast(msg);
|
if(longToast) osFunction.showLongToast(msg);
|
||||||
else toaster.showShortToast(msg);
|
else osFunction.showShortToast(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.components;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.artemis.Component;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.ModelInstance;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.utils.AnimationController;
|
||||||
|
|
||||||
|
public class AnimationComponent extends Component {
|
||||||
|
public AnimationController controller;
|
||||||
|
public List<String> animationsIds;
|
||||||
|
public int current;
|
||||||
|
public int next;
|
||||||
|
public boolean loop;
|
||||||
|
|
||||||
|
public AnimationComponent(ModelInstance instance) throws IllegalArgumentException{
|
||||||
|
this(instance, -1, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AnimationComponent(ModelInstance instance, int next) throws IllegalArgumentException{
|
||||||
|
this(instance, next, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public AnimationComponent(ModelInstance instance, int next, boolean loop) throws IllegalArgumentException{
|
||||||
|
if(instance == null)
|
||||||
|
throw new IllegalArgumentException("Instance is null.");
|
||||||
|
else if(next < 0)
|
||||||
|
throw new IllegalArgumentException("Next is less than 0.");
|
||||||
|
else if(next > instance.animations.size)
|
||||||
|
throw new IllegalArgumentException("Next is greater than the number of animations for this model.");
|
||||||
|
|
||||||
|
controller = new AnimationController(instance);
|
||||||
|
animationsIds = new LinkedList<String>();
|
||||||
|
current = -1;
|
||||||
|
this.next = next;
|
||||||
|
this.loop = loop;
|
||||||
|
|
||||||
|
for(int i = 0; i < instance.animations.size; i++){
|
||||||
|
animationsIds.add(instance.animations.get(i).id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.components;
|
||||||
|
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.CustomShaderBase;
|
||||||
|
|
||||||
|
import com.artemis.Component;
|
||||||
|
|
||||||
|
public class CustomShaderComponent extends Component {
|
||||||
|
public CustomShaderBase shader;
|
||||||
|
|
||||||
|
public CustomShaderComponent(CustomShaderBase shader) throws IllegalArgumentException{
|
||||||
|
if(shader == null)
|
||||||
|
throw new IllegalArgumentException("Shader cannot be null.");
|
||||||
|
|
||||||
|
this.shader = shader;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.components;
|
||||||
|
|
||||||
|
import com.artemis.Component;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.Environment;
|
||||||
|
|
||||||
|
public class EnvironmentComponent extends Component {
|
||||||
|
public Environment environment;
|
||||||
|
|
||||||
|
public EnvironmentComponent(Environment environment) throws IllegalArgumentException{
|
||||||
|
if(environment == null)
|
||||||
|
throw new IllegalArgumentException("Environment is null.");
|
||||||
|
|
||||||
|
this.environment = environment;
|
||||||
|
}
|
||||||
|
}
|
38
src/ve/ucv/ciens/ccg/nxtar/components/GeometryComponent.java
Normal file
38
src/ve/ucv/ciens/ccg/nxtar/components/GeometryComponent.java
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.components;
|
||||||
|
|
||||||
|
import com.artemis.Component;
|
||||||
|
import com.badlogic.gdx.math.Matrix3;
|
||||||
|
import com.badlogic.gdx.math.Vector3;
|
||||||
|
|
||||||
|
public class GeometryComponent extends Component {
|
||||||
|
public Vector3 position;
|
||||||
|
public Matrix3 rotation;
|
||||||
|
public Vector3 scaling;
|
||||||
|
|
||||||
|
public GeometryComponent(){
|
||||||
|
this.position = new Vector3();
|
||||||
|
this.rotation = new Matrix3();
|
||||||
|
this.scaling = new Vector3(1.0f, 1.0f, 1.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GeometryComponent(Vector3 position, Matrix3 rotation, Vector3 scaling){
|
||||||
|
this.position = new Vector3(position);
|
||||||
|
this.rotation = new Matrix3(rotation);
|
||||||
|
this.scaling = new Vector3(scaling);
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.components;
|
||||||
|
|
||||||
|
import com.artemis.Component;
|
||||||
|
|
||||||
|
public class MarkerCodeComponent extends Component {
|
||||||
|
public int code;
|
||||||
|
|
||||||
|
public MarkerCodeComponent(int code) throws IllegalArgumentException{
|
||||||
|
if(code < 0 || code > 1024)
|
||||||
|
throw new IllegalArgumentException("Marker code must be between [0, 1024].");
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
}
|
@@ -13,14 +13,15 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package ve.ucv.ciens.ccg.nxtar.interfaces;
|
package ve.ucv.ciens.ccg.nxtar.components;
|
||||||
|
|
||||||
public interface CVProcessor {
|
import com.artemis.Component;
|
||||||
public class CVData{
|
import com.badlogic.gdx.graphics.Mesh;
|
||||||
public byte[] outFrame;
|
|
||||||
public int[] markerCodes;
|
public class MeshComponent extends Component {
|
||||||
// TODO: Add marker location data.
|
public Mesh model;
|
||||||
|
|
||||||
|
public MeshComponent(Mesh model){
|
||||||
|
this.model = model;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CVData processFrame(byte[] frame, int w, int h);
|
|
||||||
}
|
}
|
31
src/ve/ucv/ciens/ccg/nxtar/components/ModelComponent.java
Normal file
31
src/ve/ucv/ciens/ccg/nxtar/components/ModelComponent.java
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.components;
|
||||||
|
|
||||||
|
import com.artemis.Component;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.Model;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.ModelInstance;
|
||||||
|
|
||||||
|
public class ModelComponent extends Component {
|
||||||
|
public ModelInstance instance;
|
||||||
|
|
||||||
|
public ModelComponent(Model model) throws IllegalArgumentException{
|
||||||
|
if(model == null)
|
||||||
|
throw new IllegalArgumentException("Model is null.");
|
||||||
|
|
||||||
|
this.instance = new ModelInstance(model);
|
||||||
|
}
|
||||||
|
}
|
30
src/ve/ucv/ciens/ccg/nxtar/components/ShaderComponent.java
Normal file
30
src/ve/ucv/ciens/ccg/nxtar/components/ShaderComponent.java
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.components;
|
||||||
|
|
||||||
|
import com.artemis.Component;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.Shader;
|
||||||
|
|
||||||
|
public class ShaderComponent extends Component{
|
||||||
|
public Shader shader;
|
||||||
|
|
||||||
|
public ShaderComponent(Shader shader) throws IllegalArgumentException{
|
||||||
|
if(shader == null)
|
||||||
|
throw new IllegalArgumentException("Shader is null.");
|
||||||
|
|
||||||
|
this.shader = shader;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.entities;
|
||||||
|
|
||||||
|
public class BombGameEntityCreator extends EntityCreatorBase {
|
||||||
|
public BombGameEntityCreator(){
|
||||||
|
// TODO: Empty constructor.
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createAllEntities() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
}
|
||||||
|
}
|
33
src/ve/ucv/ciens/ccg/nxtar/entities/EntityCreatorBase.java
Normal file
33
src/ve/ucv/ciens/ccg/nxtar/entities/EntityCreatorBase.java
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.entities;
|
||||||
|
|
||||||
|
import com.artemis.World;
|
||||||
|
|
||||||
|
public abstract class EntityCreatorBase {
|
||||||
|
protected World world;
|
||||||
|
|
||||||
|
public void setWorld(World world) throws IllegalArgumentException{
|
||||||
|
if(world == null)
|
||||||
|
throw new IllegalArgumentException("World cannot be null.");
|
||||||
|
|
||||||
|
this.world = world;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract void createAllEntities();
|
||||||
|
|
||||||
|
public abstract void dispose();
|
||||||
|
}
|
127
src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java
Normal file
127
src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java
Normal file
@@ -0,0 +1,127 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.entities;
|
||||||
|
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.ModelComponent;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.SingleLightPerPixelShader;
|
||||||
|
|
||||||
|
import com.artemis.Entity;
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
import com.badlogic.gdx.graphics.VertexAttribute;
|
||||||
|
import com.badlogic.gdx.graphics.VertexAttributes;
|
||||||
|
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.Environment;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.Material;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.Model;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.environment.DirectionalLight;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
|
||||||
|
import com.badlogic.gdx.math.Matrix3;
|
||||||
|
import com.badlogic.gdx.math.Vector3;
|
||||||
|
import com.badlogic.gdx.utils.JsonReader;
|
||||||
|
|
||||||
|
public class MarkerTestEntityCreator extends EntityCreatorBase {
|
||||||
|
private static final String TAG = "MARKER_TEST_ENTITY_CREATOR";
|
||||||
|
private static final String CLASS_NAME = MarkerTestEntityCreator.class.getSimpleName();
|
||||||
|
|
||||||
|
private Model bombModel;
|
||||||
|
private Model animatedModel;
|
||||||
|
private Model boxModel;
|
||||||
|
private SingleLightPerPixelShader ppShader;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createAllEntities() {
|
||||||
|
ModelBuilder builder;
|
||||||
|
Entity bomb, box, anim;
|
||||||
|
G3dModelLoader loader;
|
||||||
|
Environment environment;
|
||||||
|
Material material;
|
||||||
|
|
||||||
|
// Create mesh.
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the meshes.");
|
||||||
|
|
||||||
|
loader = new G3dModelLoader(new JsonReader());
|
||||||
|
|
||||||
|
bombModel = loader.loadModel(Gdx.files.internal("models/Bomb_test_2.g3dj"));
|
||||||
|
animatedModel = loader.loadModel(Gdx.files.internal("models/cube.g3dj"));
|
||||||
|
|
||||||
|
material = new Material(new FloatAttribute(FloatAttribute.Shininess, 50.0f), new ColorAttribute(ColorAttribute.Diffuse, 1.0f, 1.0f, 1.0f, 1.0f), new ColorAttribute(ColorAttribute.Specular, 1.0f, 1.0f, 1.0f, 1.0f));
|
||||||
|
|
||||||
|
builder = new ModelBuilder();
|
||||||
|
boxModel = builder.createBox(0.5f, 0.5f, 6.0f, material, new VertexAttributes(new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.Normal, 3, "a_normal"), new VertexAttribute(Usage.Color, 4, "a_color")).getMask());
|
||||||
|
|
||||||
|
// Load the shader.
|
||||||
|
ppShader = new SingleLightPerPixelShader();
|
||||||
|
ppShader.init();
|
||||||
|
|
||||||
|
environment = new Environment();
|
||||||
|
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.0f));
|
||||||
|
environment.add(new DirectionalLight().set(new Color(1, 1, 1, 1), new Vector3(1, 0, 0.5f)));
|
||||||
|
|
||||||
|
// Create the entities.
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the enitites.");
|
||||||
|
bomb = world.createEntity();
|
||||||
|
bomb.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.0f), new Matrix3().idt(), new Vector3(1.0f, 1.0f, 1.0f)));
|
||||||
|
bomb.addComponent(new ModelComponent(bombModel));
|
||||||
|
bomb.addComponent(new EnvironmentComponent(environment));
|
||||||
|
bomb.addComponent(new ShaderComponent(ppShader));
|
||||||
|
bomb.addComponent(new MarkerCodeComponent(1023));
|
||||||
|
|
||||||
|
anim = world.createEntity();
|
||||||
|
anim.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.0f), new Matrix3().idt(), new Vector3(0.25f, 0.25f, -0.25f)));
|
||||||
|
anim.addComponent(new ModelComponent(animatedModel));
|
||||||
|
anim.addComponent(new AnimationComponent(anim.getComponent(ModelComponent.class).instance, 0, true));
|
||||||
|
anim.addComponent(new EnvironmentComponent(environment));
|
||||||
|
anim.addComponent(new MarkerCodeComponent(89));
|
||||||
|
anim.addComponent(new ShaderComponent(ppShader));
|
||||||
|
|
||||||
|
box = world.createEntity();
|
||||||
|
box.addComponent(new GeometryComponent(new Vector3(-1.0f, 0.0f, 0.0f), new Matrix3().idt(), new Vector3(1.0f, 1.0f, 1.0f)));
|
||||||
|
box.addComponent(new ModelComponent(boxModel));
|
||||||
|
box.addComponent(new ShaderComponent(ppShader));
|
||||||
|
box.addComponent(new EnvironmentComponent(environment));
|
||||||
|
|
||||||
|
// Add the entities to the world.
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Adding entities to the world.");
|
||||||
|
//sphere.addToWorld();
|
||||||
|
bomb.addToWorld();
|
||||||
|
anim.addToWorld();
|
||||||
|
box.addToWorld();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
if(boxModel != null)
|
||||||
|
boxModel.dispose();
|
||||||
|
|
||||||
|
if(animatedModel != null)
|
||||||
|
animatedModel.dispose();
|
||||||
|
|
||||||
|
if(bombModel != null)
|
||||||
|
bombModel.dispose();
|
||||||
|
|
||||||
|
if(ppShader != null)
|
||||||
|
ppShader.dispose();
|
||||||
|
}
|
||||||
|
}
|
134
src/ve/ucv/ciens/ccg/nxtar/entities/TestGameEntityCreator.java
Normal file
134
src/ve/ucv/ciens/ccg/nxtar/entities/TestGameEntityCreator.java
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.entities;
|
||||||
|
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.MeshComponent;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.CustomShaderComponent;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.exceptions.ShaderFailedToLoadException;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.CustomShaderBase;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.SingleLightPhongShader;
|
||||||
|
|
||||||
|
import com.artemis.Entity;
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
|
import com.badlogic.gdx.graphics.Mesh;
|
||||||
|
import com.badlogic.gdx.graphics.VertexAttribute;
|
||||||
|
import com.badlogic.gdx.graphics.VertexAttributes;
|
||||||
|
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.utils.MeshBuilder;
|
||||||
|
import com.badlogic.gdx.math.Matrix3;
|
||||||
|
import com.badlogic.gdx.math.Vector3;
|
||||||
|
|
||||||
|
public class TestGameEntityCreator extends EntityCreatorBase {
|
||||||
|
private static final String TAG = "TEST_ENTITY_CREATOR";
|
||||||
|
private static final String CLASS_NAME = TestGameEntityCreator.class.getSimpleName();
|
||||||
|
|
||||||
|
private MeshBuilder builder;
|
||||||
|
private Mesh sphereMesh;
|
||||||
|
private Mesh cubeMesh;
|
||||||
|
private Mesh capsuleMesh;
|
||||||
|
private CustomShaderBase singleLightPhongShader;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void createAllEntities() {
|
||||||
|
Matrix3 identity = new Matrix3();
|
||||||
|
Entity sphere;
|
||||||
|
Entity cube;
|
||||||
|
Entity capsule1;
|
||||||
|
Entity capsule2;
|
||||||
|
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Started.");
|
||||||
|
|
||||||
|
identity.idt();
|
||||||
|
|
||||||
|
// Create the sphere.
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the meshes.");
|
||||||
|
builder = new MeshBuilder();
|
||||||
|
builder.begin(new VertexAttributes(new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.Normal, 3, "a_normal"), new VertexAttribute(Usage.Color, 4, "a_color")), GL20.GL_TRIANGLES);{
|
||||||
|
builder.setColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
builder.sphere(1.0f, 1.0f, 1.0f, 10, 10);
|
||||||
|
}sphereMesh = builder.end();
|
||||||
|
|
||||||
|
// Create the cube.
|
||||||
|
builder.begin(new VertexAttributes(new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.Normal, 3, "a_normal"), new VertexAttribute(Usage.Color, 4, "a_color")), GL20.GL_TRIANGLES);{
|
||||||
|
builder.setColor(0.2f, 0.5f, 1.0f, 1.0f);
|
||||||
|
builder.box(0.5f, 0.5f, 0.5f);
|
||||||
|
}cubeMesh = builder.end();
|
||||||
|
|
||||||
|
// Create the capsule.
|
||||||
|
builder.begin(new VertexAttributes(new VertexAttribute(Usage.Position, 3, "a_position"), new VertexAttribute(Usage.Normal, 3, "a_normal"), new VertexAttribute(Usage.Color, 4, "a_color")), GL20.GL_TRIANGLES);{
|
||||||
|
builder.setColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
builder.capsule(0.25f, 0.5f, 10);
|
||||||
|
}capsuleMesh = builder.end();
|
||||||
|
|
||||||
|
// Load the phong shader.
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Loading the phong shader.");
|
||||||
|
try{
|
||||||
|
singleLightPhongShader = new SingleLightPhongShader().loadShader();
|
||||||
|
}catch(ShaderFailedToLoadException se){
|
||||||
|
Gdx.app.error(TAG, CLASS_NAME + ".InGameState(): " + se.getMessage());
|
||||||
|
Gdx.app.exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the entities.
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the enitites.");
|
||||||
|
sphere = world.createEntity();
|
||||||
|
sphere.addComponent(new GeometryComponent(new Vector3(0.5f, 0.5f, 0.0f), identity, new Vector3(1.0f, 1.0f, 1.0f)));
|
||||||
|
sphere.addComponent(new MeshComponent(sphereMesh));
|
||||||
|
sphere.addComponent(new CustomShaderComponent(singleLightPhongShader));
|
||||||
|
|
||||||
|
cube = world.createEntity();
|
||||||
|
cube.addComponent(new GeometryComponent(new Vector3(-0.5f, -0.5f, 0.0f), identity, new Vector3(1.0f, 1.0f, 1.0f)));
|
||||||
|
cube.addComponent(new MeshComponent(cubeMesh));
|
||||||
|
cube.addComponent(new CustomShaderComponent(singleLightPhongShader));
|
||||||
|
|
||||||
|
capsule1 = world.createEntity();
|
||||||
|
capsule1.addComponent(new GeometryComponent(new Vector3(-0.5f, 0.5f, 0.0f), identity, new Vector3(1.5f, 1.0f, 1.0f)));
|
||||||
|
capsule1.addComponent(new MeshComponent(capsuleMesh));
|
||||||
|
capsule1.addComponent(new CustomShaderComponent(singleLightPhongShader));
|
||||||
|
|
||||||
|
capsule2 = world.createEntity();
|
||||||
|
capsule2.addComponent(new GeometryComponent(new Vector3(0.5f, -0.5f, 0.0f), identity, new Vector3(1.0f, 1.5f, 1.0f)));
|
||||||
|
capsule2.addComponent(new MeshComponent(capsuleMesh));
|
||||||
|
capsule2.addComponent(new CustomShaderComponent(singleLightPhongShader));
|
||||||
|
|
||||||
|
// Add the entities to the world.
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Adding entities to the world.");
|
||||||
|
sphere.addToWorld();
|
||||||
|
cube.addToWorld();
|
||||||
|
capsule1.addToWorld();
|
||||||
|
capsule2.addToWorld();
|
||||||
|
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Finished.");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose() {
|
||||||
|
if(singleLightPhongShader != null && singleLightPhongShader.getShaderProgram() != null)
|
||||||
|
singleLightPhongShader.getShaderProgram().dispose();
|
||||||
|
|
||||||
|
if(sphereMesh != null)
|
||||||
|
sphereMesh.dispose();
|
||||||
|
|
||||||
|
if(cubeMesh != null)
|
||||||
|
cubeMesh.dispose();
|
||||||
|
|
||||||
|
if(capsuleMesh != null)
|
||||||
|
capsuleMesh.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2013 Miguel Angel Astor Romero
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
@@ -13,9 +13,12 @@
|
|||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package ve.ucv.ciens.ccg.nxtar.interfaces;
|
package ve.ucv.ciens.ccg.nxtar.exceptions;
|
||||||
|
|
||||||
public interface MulticastEnabler {
|
public class ShaderFailedToLoadException extends Exception {
|
||||||
public void enableMulticast();
|
private static final long serialVersionUID = 9989L;
|
||||||
public void disableMulticast();
|
|
||||||
|
public ShaderFailedToLoadException(String msg){
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
}
|
}
|
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.graphics;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.PerspectiveCamera;
|
||||||
|
import com.badlogic.gdx.math.Matrix4;
|
||||||
|
import com.badlogic.gdx.math.Vector3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Extension of the standard LibGDX perspective camera that allows setting an
|
||||||
|
* arbitrary projection matrix when updating.</p>
|
||||||
|
*/
|
||||||
|
public class CustomPerspectiveCamera extends PerspectiveCamera{
|
||||||
|
private final Vector3 tmp = new Vector3();
|
||||||
|
|
||||||
|
public CustomPerspectiveCamera(float fieldOfView, float viewportWidth, float viewportHeight){
|
||||||
|
this.fieldOfView = fieldOfView;
|
||||||
|
this.viewportWidth = viewportWidth;
|
||||||
|
this.viewportHeight = viewportHeight;
|
||||||
|
update();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void update(Matrix4 customProjection, boolean updateFrustum){
|
||||||
|
projection.set(customProjection);
|
||||||
|
view.setToLookAt(position, tmp.set(position).add(direction), up);
|
||||||
|
combined.set(projection);
|
||||||
|
Matrix4.mul(combined.val, view.val);
|
||||||
|
|
||||||
|
if(updateFrustum){
|
||||||
|
invProjectionView.set(combined);
|
||||||
|
Matrix4.inv(invProjectionView.val);
|
||||||
|
frustum.update(invProjectionView);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
162
src/ve/ucv/ciens/ccg/nxtar/graphics/LightSource.java
Normal file
162
src/ve/ucv/ciens/ccg/nxtar/graphics/LightSource.java
Normal file
@@ -0,0 +1,162 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.graphics;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
import com.badlogic.gdx.math.Vector3;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>A 3D light source.</p>
|
||||||
|
*/
|
||||||
|
public class LightSource{
|
||||||
|
private Vector3 position;
|
||||||
|
private Color ambientColor;
|
||||||
|
private Color diffuseColor;
|
||||||
|
private Color specularColor;
|
||||||
|
private float shinyness;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Creates a default white light source positioned at (0,0,0).</p>
|
||||||
|
*/
|
||||||
|
public LightSource(){
|
||||||
|
position = new Vector3(0.0f, 0.0f, 0.0f);
|
||||||
|
ambientColor = new Color(0.15f, 0.15f, 0.15f, 1.0f);
|
||||||
|
diffuseColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
specularColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
ambientColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
shinyness = 10.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Creates a white light source at the specified position.</p>
|
||||||
|
*
|
||||||
|
* @param position The location of the light source.
|
||||||
|
*/
|
||||||
|
public LightSource(Vector3 position){
|
||||||
|
this.position = new Vector3();
|
||||||
|
|
||||||
|
this.position.set(position);
|
||||||
|
ambientColor = new Color(0.15f, 0.15f, 0.15f, 1.0f);
|
||||||
|
diffuseColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
specularColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
ambientColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
shinyness = 10.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Creates a custom light source.</p>
|
||||||
|
*
|
||||||
|
* @param position The location of the light source.
|
||||||
|
* @param ambientColor
|
||||||
|
* @param diffuseColor
|
||||||
|
* @param specularColor
|
||||||
|
* @param shinyness The shinyness component. Must be between (0.0, 128.0].
|
||||||
|
* @throws IllegalArgumentException When shinyness is outside the valid range.
|
||||||
|
*/
|
||||||
|
public LightSource(Vector3 position, Color ambientColor, Color diffuseColor, Color specularColor, float shinyness) throws IllegalArgumentException {
|
||||||
|
if(shinyness <= 0.0 || shinyness > 128.0)
|
||||||
|
throw new IllegalArgumentException("Shinyness must be between (0.0, 128.0].");
|
||||||
|
|
||||||
|
this.position = new Vector3();
|
||||||
|
this.ambientColor = new Color();
|
||||||
|
this.diffuseColor = new Color();
|
||||||
|
this.ambientColor = new Color();
|
||||||
|
this.specularColor = new Color();
|
||||||
|
|
||||||
|
this.position.set(position);
|
||||||
|
this.ambientColor.set(ambientColor);
|
||||||
|
this.diffuseColor.set(diffuseColor);
|
||||||
|
this.specularColor.set(specularColor);
|
||||||
|
this.shinyness = shinyness;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LightSource(LightSource light){
|
||||||
|
this.position = new Vector3();
|
||||||
|
this.ambientColor = new Color();
|
||||||
|
this.diffuseColor = new Color();
|
||||||
|
this.ambientColor = new Color();
|
||||||
|
this.specularColor = new Color();
|
||||||
|
|
||||||
|
set(light);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(LightSource light){
|
||||||
|
this.position.set(light.getPosition());
|
||||||
|
this.ambientColor.set(light.getAmbientColor());
|
||||||
|
this.diffuseColor.set(light.getDiffuseColor());
|
||||||
|
this.specularColor.set(light.getSpecularColor());
|
||||||
|
this.shinyness = light.shinyness;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPosition(float x, float y, float z){
|
||||||
|
position.set(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPosition(Vector3 position){
|
||||||
|
this.position.set(position);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAmbientColor(float r, float g, float b, float a){
|
||||||
|
ambientColor.set(r, g, b, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAmbientColor(Color ambientColor){
|
||||||
|
this.ambientColor.set(ambientColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDiffuseColor(float r, float g, float b, float a){
|
||||||
|
diffuseColor.set(r, g, b, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setdiffuseColor(Color diffuseColor){
|
||||||
|
this.diffuseColor.set(diffuseColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpecularColor(float r, float g, float b, float a){
|
||||||
|
specularColor.set(r, g, b, a);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSpecularColor(Color specularColor){
|
||||||
|
this.specularColor.set(specularColor);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShinyness(float shinyness) throws IllegalArgumentException {
|
||||||
|
if(shinyness <= 0.0 || shinyness > 128.0)
|
||||||
|
throw new IllegalArgumentException("Shinyness must be between (0.0, 128.0].");
|
||||||
|
|
||||||
|
this.shinyness = shinyness;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Vector3 getPosition(){
|
||||||
|
return position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color getAmbientColor(){
|
||||||
|
return ambientColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color getDiffuseColor(){
|
||||||
|
return diffuseColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Color getSpecularColor(){
|
||||||
|
return specularColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getShinyness(){
|
||||||
|
return shinyness;
|
||||||
|
}
|
||||||
|
}
|
75
src/ve/ucv/ciens/ccg/nxtar/graphics/RenderParameters.java
Normal file
75
src/ve/ucv/ciens/ccg/nxtar/graphics/RenderParameters.java
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.graphics;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.math.Matrix4;
|
||||||
|
import com.badlogic.gdx.math.Vector3;
|
||||||
|
|
||||||
|
public abstract class RenderParameters {
|
||||||
|
private static Matrix4 modelViewProjection;
|
||||||
|
private static Matrix4 geometricTransformation;
|
||||||
|
private static Vector3 eyePosition;
|
||||||
|
private static LightSource lightSource1;
|
||||||
|
private static LightSource lightSource2;
|
||||||
|
|
||||||
|
static{
|
||||||
|
modelViewProjection = new Matrix4();
|
||||||
|
geometricTransformation = new Matrix4();
|
||||||
|
eyePosition = new Vector3(0.0f, 0.0f, 1.4142f);
|
||||||
|
lightSource1 = new LightSource();
|
||||||
|
lightSource2 = new LightSource();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized void setModelViewProjectionMatrix(Matrix4 modelViewMatrix){
|
||||||
|
modelViewProjection.set(modelViewMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized void setTransformationMatrix(Matrix4 transformationMatrix){
|
||||||
|
geometricTransformation.set(transformationMatrix);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized void setEyePosition(Vector3 newEyePostition){
|
||||||
|
eyePosition.set(newEyePostition);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized void setLightSource1(LightSource newLightSource1){
|
||||||
|
lightSource1.set(newLightSource1);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized void setLightSource2(LightSource newLightSource2){
|
||||||
|
lightSource2.set(newLightSource2);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized Matrix4 getModelViewProjectionMatrix(){
|
||||||
|
return modelViewProjection;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized Matrix4 getTransformationMatrix(){
|
||||||
|
return geometricTransformation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized Vector3 getEyePosition(){
|
||||||
|
return eyePosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized LightSource getLightSource1(){
|
||||||
|
return lightSource1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static synchronized LightSource getLightSource2(){
|
||||||
|
return lightSource2;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.graphics.shaders;
|
||||||
|
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.exceptions.ShaderFailedToLoadException;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
||||||
|
|
||||||
|
public abstract class CustomShaderBase{
|
||||||
|
protected ShaderProgram shaderProgram;
|
||||||
|
|
||||||
|
public abstract CustomShaderBase loadShader() throws ShaderFailedToLoadException;
|
||||||
|
|
||||||
|
public abstract void setUniforms();
|
||||||
|
|
||||||
|
public ShaderProgram getShaderProgram(){
|
||||||
|
return this.shaderProgram;
|
||||||
|
}
|
||||||
|
}
|
@@ -0,0 +1,230 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.graphics.shaders;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.graphics.Camera;
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
|
import com.badlogic.gdx.graphics.VertexAttributes;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.Renderable;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.Shader;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.utils.RenderContext;
|
||||||
|
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
||||||
|
import com.badlogic.gdx.math.Matrix4;
|
||||||
|
import com.badlogic.gdx.math.Vector3;
|
||||||
|
import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||||
|
|
||||||
|
public class SingleLightPerPixelShader implements Shader{
|
||||||
|
private static final int MAX_NUM_BONES = 4;
|
||||||
|
private static final Matrix4 IDENTITY = new Matrix4();
|
||||||
|
private static final String VERTEX_SHADER_PATH = "shaders/directionalPerPixelSingleLight/directionalPerPixel_vert.glsl";
|
||||||
|
private static final String FRAGMENT_SHADER_PATH = "shaders/directionalPerPixelSingleLight/directionalPerPixel_frag.glsl";
|
||||||
|
private static final String INCLUDE_SKINNING = "#define SKINNING\n";
|
||||||
|
|
||||||
|
private ShaderProgram skinningProgram;
|
||||||
|
private ShaderProgram baseProgram;
|
||||||
|
private Camera camera;
|
||||||
|
private RenderContext context;
|
||||||
|
private Matrix4 normalMatrix;
|
||||||
|
|
||||||
|
// Uniform locations.
|
||||||
|
private int[] u_geomTrans;
|
||||||
|
private int[] u_projTrans;
|
||||||
|
private int[] u_lightPos;
|
||||||
|
private int[] u_lightDiffuse;
|
||||||
|
private int[] u_specular;
|
||||||
|
private int[] u_ambient;
|
||||||
|
private int[] u_shiny;
|
||||||
|
private int[] u_cameraPos;
|
||||||
|
private int[] u_materialDiffuse;
|
||||||
|
private int[] u_normalMatrix;
|
||||||
|
private int[] u_bones;
|
||||||
|
|
||||||
|
public SingleLightPerPixelShader(){
|
||||||
|
skinningProgram = null;
|
||||||
|
baseProgram = null;
|
||||||
|
camera = null;
|
||||||
|
context = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() throws GdxRuntimeException{
|
||||||
|
normalMatrix = new Matrix4().idt();
|
||||||
|
u_bones = new int[MAX_NUM_BONES];
|
||||||
|
|
||||||
|
// Compile the shader.
|
||||||
|
String vertexCode = Gdx.files.internal(VERTEX_SHADER_PATH).readString();
|
||||||
|
String fragmentCode = Gdx.files.internal(FRAGMENT_SHADER_PATH).readString();
|
||||||
|
|
||||||
|
skinningProgram = new ShaderProgram(INCLUDE_SKINNING + vertexCode, fragmentCode);
|
||||||
|
baseProgram = new ShaderProgram(vertexCode, fragmentCode);
|
||||||
|
|
||||||
|
if(!skinningProgram.isCompiled())
|
||||||
|
throw new GdxRuntimeException(skinningProgram.getLog());
|
||||||
|
|
||||||
|
if(!baseProgram.isCompiled())
|
||||||
|
throw new GdxRuntimeException(skinningProgram.getLog());
|
||||||
|
|
||||||
|
// Create uniform locations.
|
||||||
|
u_projTrans = new int[2];
|
||||||
|
u_geomTrans = new int[2];
|
||||||
|
u_lightPos = new int[2];
|
||||||
|
u_lightDiffuse = new int[2];
|
||||||
|
u_specular = new int[2];
|
||||||
|
u_ambient = new int[2];
|
||||||
|
u_shiny = new int[2];
|
||||||
|
u_cameraPos = new int[2];
|
||||||
|
u_materialDiffuse = new int[2];
|
||||||
|
u_normalMatrix = new int[2];
|
||||||
|
|
||||||
|
// Cache uniform locations.
|
||||||
|
u_projTrans [0] = skinningProgram.getUniformLocation("u_projTrans");
|
||||||
|
u_geomTrans [0] = skinningProgram.getUniformLocation("u_geomTrans");
|
||||||
|
u_lightPos [0] = skinningProgram.getUniformLocation("u_lightPos");
|
||||||
|
u_lightDiffuse [0] = skinningProgram.getUniformLocation("u_lightDiffuse");
|
||||||
|
u_specular [0] = skinningProgram.getUniformLocation("u_specular");
|
||||||
|
u_ambient [0] = skinningProgram.getUniformLocation("u_ambient");
|
||||||
|
u_shiny [0] = skinningProgram.getUniformLocation("u_shiny");
|
||||||
|
u_cameraPos [0] = skinningProgram.getUniformLocation("u_cameraPos");
|
||||||
|
u_materialDiffuse [0] = skinningProgram.getUniformLocation("u_materialDiffuse");
|
||||||
|
u_normalMatrix [0] = skinningProgram.getUniformLocation("u_normalMatrix");
|
||||||
|
|
||||||
|
u_projTrans [1] = baseProgram.getUniformLocation("u_projTrans");
|
||||||
|
u_geomTrans [1] = baseProgram.getUniformLocation("u_geomTrans");
|
||||||
|
u_lightPos [1] = baseProgram.getUniformLocation("u_lightPos");
|
||||||
|
u_lightDiffuse [1] = baseProgram.getUniformLocation("u_lightDiffuse");
|
||||||
|
u_specular [1] = baseProgram.getUniformLocation("u_specular");
|
||||||
|
u_ambient [1] = baseProgram.getUniformLocation("u_ambient");
|
||||||
|
u_shiny [1] = baseProgram.getUniformLocation("u_shiny");
|
||||||
|
u_cameraPos [1] = baseProgram.getUniformLocation("u_cameraPos");
|
||||||
|
u_materialDiffuse [1] = baseProgram.getUniformLocation("u_materialDiffuse");
|
||||||
|
u_normalMatrix [1] = baseProgram.getUniformLocation("u_normalMatrix");
|
||||||
|
|
||||||
|
for(int i = 0; i < MAX_NUM_BONES; i++){
|
||||||
|
u_bones[i] = skinningProgram.getUniformLocation("u_bone" + Integer.toString(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose(){
|
||||||
|
if(skinningProgram != null) skinningProgram.dispose();
|
||||||
|
if(baseProgram != null) baseProgram.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(Shader other){
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean canRender(Renderable renderable){
|
||||||
|
// Check for all needed lighting and material attributes.
|
||||||
|
if(renderable.environment.directionalLights.size < 1)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(!renderable.environment.has(ColorAttribute.AmbientLight))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(!renderable.material.has(ColorAttribute.Diffuse))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(!renderable.material.has(ColorAttribute.Specular))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if(!renderable.material.has(FloatAttribute.Shininess))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void begin(Camera camera, RenderContext context) throws GdxRuntimeException{
|
||||||
|
if(this.camera != null || this.context != null)
|
||||||
|
throw new GdxRuntimeException("Called begin twice before calling end.");
|
||||||
|
|
||||||
|
this.camera = camera;
|
||||||
|
this.context = context;
|
||||||
|
|
||||||
|
// Set render context.
|
||||||
|
this.context.setDepthTest(GL20.GL_LEQUAL);
|
||||||
|
this.context.setDepthMask(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(Renderable renderable){
|
||||||
|
ShaderProgram program;
|
||||||
|
int index;
|
||||||
|
boolean bonesEnabled;
|
||||||
|
|
||||||
|
// Get material colors.
|
||||||
|
Vector3 lightPosition = renderable.environment.directionalLights.get(0).direction;
|
||||||
|
Color diffuseLightColor = renderable.environment.directionalLights.get(0).color;
|
||||||
|
Color diffuseColor = ((ColorAttribute)renderable.material.get(ColorAttribute.Diffuse)).color;
|
||||||
|
Color specularColor = ((ColorAttribute)renderable.material.get(ColorAttribute.Specular)).color;
|
||||||
|
Color ambientColor = ((ColorAttribute)renderable.environment.get(ColorAttribute.AmbientLight)).color;
|
||||||
|
float shininess = ((FloatAttribute)renderable.material.get(FloatAttribute.Shininess)).value;
|
||||||
|
|
||||||
|
if(renderable.mesh.getVertexAttribute(VertexAttributes.Usage.BoneWeight) != null){
|
||||||
|
program = skinningProgram;
|
||||||
|
index = 0;
|
||||||
|
bonesEnabled = true;
|
||||||
|
}else{
|
||||||
|
program = baseProgram;
|
||||||
|
index = 1;
|
||||||
|
bonesEnabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
program.begin();
|
||||||
|
|
||||||
|
// Set camera dependant uniforms.
|
||||||
|
program.setUniformMatrix(u_projTrans[index], this.camera.combined);
|
||||||
|
program.setUniformf(u_cameraPos[index], this.camera.position);
|
||||||
|
|
||||||
|
// Set model dependant uniforms.
|
||||||
|
program.setUniformMatrix(u_geomTrans[index], renderable.worldTransform);
|
||||||
|
program.setUniformMatrix(u_normalMatrix[index], normalMatrix.idt().mul(renderable.worldTransform).inv().tra());
|
||||||
|
program.setUniformf(u_lightPos[index], lightPosition);
|
||||||
|
program.setUniformf(u_lightDiffuse[index], diffuseLightColor);
|
||||||
|
program.setUniformf(u_materialDiffuse[index], diffuseColor);
|
||||||
|
program.setUniformf(u_specular[index], specularColor);
|
||||||
|
program.setUniformf(u_ambient[index], ambientColor);
|
||||||
|
program.setUniformf(u_shiny[index], shininess);
|
||||||
|
|
||||||
|
// Set the bones uniforms.
|
||||||
|
if(bonesEnabled){
|
||||||
|
for(int i = 0; i < MAX_NUM_BONES; i++){
|
||||||
|
if(renderable.bones != null && i < renderable.bones.length && renderable.bones[i] != null)
|
||||||
|
skinningProgram.setUniformMatrix(u_bones[i], renderable.bones[i]);
|
||||||
|
else
|
||||||
|
skinningProgram.setUniformMatrix(u_bones[i], IDENTITY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
renderable.mesh.render(program, renderable.primitiveType, renderable.meshPartOffset, renderable.meshPartSize);
|
||||||
|
|
||||||
|
program.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void end(){
|
||||||
|
this.camera = null;
|
||||||
|
this.context = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.graphics.shaders;
|
||||||
|
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.exceptions.ShaderFailedToLoadException;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.graphics.LightSource;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.graphics.RenderParameters;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
||||||
|
|
||||||
|
public class SingleLightPhongShader extends CustomShaderBase{
|
||||||
|
private static String VERTEX_SHADER_PATH = "shaders/singleDiffuseLight/singleDiffuseLight_vert.glsl";
|
||||||
|
private static String FRAGMENT_SHADER_PATH = "shaders/singleDiffuseLight/singleDiffuseLight_frag.glsl";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SingleLightPhongShader loadShader() throws ShaderFailedToLoadException{
|
||||||
|
shaderProgram = new ShaderProgram(Gdx.files.internal(VERTEX_SHADER_PATH), Gdx.files.internal(FRAGMENT_SHADER_PATH));
|
||||||
|
|
||||||
|
if(!shaderProgram.isCompiled()){
|
||||||
|
throw new ShaderFailedToLoadException("SingleLightPerPixelPhongShader failed to load.\n" + shaderProgram.getLog());
|
||||||
|
}
|
||||||
|
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setUniforms(){
|
||||||
|
LightSource light = RenderParameters.getLightSource1();
|
||||||
|
float[] diffuseColor = {light.getDiffuseColor().r, light.getDiffuseColor().g, light.getDiffuseColor().b, light.getDiffuseColor().a};
|
||||||
|
float[] ambientColor = {light.getAmbientColor().r, light.getAmbientColor().g, light.getAmbientColor().b, light.getAmbientColor().a};
|
||||||
|
float[] specularColor = {light.getSpecularColor().r, light.getSpecularColor().g, light.getSpecularColor().b, light.getSpecularColor().a};
|
||||||
|
float[] position = {light.getPosition().x, light.getPosition().y, light.getPosition().z, 0.0f};
|
||||||
|
float[] shinyness = {light.getShinyness()};
|
||||||
|
|
||||||
|
shaderProgram.setUniformMatrix("u_projTrans", RenderParameters.getModelViewProjectionMatrix());
|
||||||
|
shaderProgram.setUniformMatrix("u_geomTrans", RenderParameters.getTransformationMatrix());
|
||||||
|
shaderProgram.setUniform4fv("u_lightPos", position, 0, 4);
|
||||||
|
shaderProgram.setUniform4fv("u_lightDiffuse", diffuseColor, 0, 4);
|
||||||
|
shaderProgram.setUniform4fv("u_specular", specularColor, 0, 4);
|
||||||
|
shaderProgram.setUniform4fv("u_ambient", ambientColor, 0, 4);
|
||||||
|
shaderProgram.setUniform1fv("u_shiny", shinyness, 0, 1);
|
||||||
|
shaderProgram.setUniformf("u_cameraPos", RenderParameters.getEyePosition());
|
||||||
|
}
|
||||||
|
}
|
@@ -15,7 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
package ve.ucv.ciens.ccg.nxtar.interfaces;
|
package ve.ucv.ciens.ccg.nxtar.interfaces;
|
||||||
|
|
||||||
public interface Toaster {
|
public interface ActionResolver{
|
||||||
public void showShortToast(String msg);
|
public void showShortToast(String msg);
|
||||||
public void showLongToast(String msg);
|
public void showLongToast(String msg);
|
||||||
|
public void enableMulticast();
|
||||||
|
public void disableMulticast();
|
||||||
}
|
}
|
@@ -15,6 +15,6 @@
|
|||||||
*/
|
*/
|
||||||
package ve.ucv.ciens.ccg.nxtar.interfaces;
|
package ve.ucv.ciens.ccg.nxtar.interfaces;
|
||||||
|
|
||||||
public interface NetworkConnectionListener {
|
public interface ApplicationEventsListener {
|
||||||
public void networkStreamConnected(String streamName);
|
public void networkStreamConnected(String streamName);
|
||||||
}
|
}
|
86
src/ve/ucv/ciens/ccg/nxtar/interfaces/ImageProcessor.java
Normal file
86
src/ve/ucv/ciens/ccg/nxtar/interfaces/ImageProcessor.java
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.interfaces;
|
||||||
|
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.math.Matrix3;
|
||||||
|
import com.badlogic.gdx.math.Vector3;
|
||||||
|
|
||||||
|
public interface ImageProcessor{
|
||||||
|
public class MarkerData{
|
||||||
|
public byte[] outFrame;
|
||||||
|
public int[] markerCodes;
|
||||||
|
public Vector3[] translationVectors;
|
||||||
|
public Matrix3[] rotationMatrices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class CalibrationData{
|
||||||
|
public byte[] outFrame;
|
||||||
|
public float[] calibrationPoints;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Finds up to {@link ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS} markers in the input
|
||||||
|
* image and returns their codes and pose estimation in the CVMarkerData structure. The
|
||||||
|
* markers are higlihted in the input image.</p>
|
||||||
|
*
|
||||||
|
* @param frame The JPEG encoded input image.
|
||||||
|
* @return A data structure containing the processed output image, the
|
||||||
|
* detected marker codes and their respective locations.
|
||||||
|
*/
|
||||||
|
public MarkerData findMarkersInFrame(byte[] frame);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Attempts to detect a checkerboard calibration pattern in the input image.
|
||||||
|
* If the pattenr is found the method returns an image with the pattern
|
||||||
|
* highlighted and the spatial location of the calibration points in the
|
||||||
|
* output data structure.</p>
|
||||||
|
*
|
||||||
|
* @param frame The JPEG encoded input image.
|
||||||
|
* @return A data structure containing the processed output image and the
|
||||||
|
* location of the calibration points. If the pattern was not found, the returnd
|
||||||
|
* calibration points array is null.
|
||||||
|
*/
|
||||||
|
public CalibrationData findCalibrationPattern(byte[] frame);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Obtains the intrinsic camera parameters necesary for calibration.</p>
|
||||||
|
*/
|
||||||
|
public void calibrateCamera(float[][] calibrationSamples, byte[] frame);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Removes camera lens distortion from the input image using the
|
||||||
|
* camera parameters obtained by the calibrateCamera method.</p>
|
||||||
|
*
|
||||||
|
* @return A JPEG encoded image that is the input image after distortion correction. If the
|
||||||
|
* camera has not been calibrated or OpenCV failed to load returns null.
|
||||||
|
*/
|
||||||
|
public byte[] undistortFrame(byte[] frame);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Indicates if OpenCV has been sucessfully initialized and used
|
||||||
|
* to obtain the camera parameters for calibration.</p>
|
||||||
|
*
|
||||||
|
* @return True if and only if OpenCV initialized succesfully and calibrateCamera has been called previously.
|
||||||
|
*/
|
||||||
|
public boolean isCameraCalibrated();
|
||||||
|
|
||||||
|
public float getFocalPointX();
|
||||||
|
public float getFocalPointY();
|
||||||
|
public float getCameraCenterX();
|
||||||
|
public float getCameraCenterY();
|
||||||
|
}
|
@@ -24,7 +24,7 @@ import java.net.Socket;
|
|||||||
|
|
||||||
import ve.ucv.ciens.ccg.networkdata.MotorEvent;
|
import ve.ucv.ciens.ccg.networkdata.MotorEvent;
|
||||||
import ve.ucv.ciens.ccg.networkdata.MotorEventACK;
|
import ve.ucv.ciens.ccg.networkdata.MotorEventACK;
|
||||||
import ve.ucv.ciens.ccg.nxtar.interfaces.NetworkConnectionListener;
|
import ve.ucv.ciens.ccg.nxtar.interfaces.ApplicationEventsListener;
|
||||||
import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue;
|
import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue;
|
||||||
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||||
|
|
||||||
@@ -35,7 +35,7 @@ public class RobotControlThread extends Thread {
|
|||||||
private static final String TAG = "NXTAR_CORE_ROBOTTHREAD";
|
private static final String TAG = "NXTAR_CORE_ROBOTTHREAD";
|
||||||
private static final String CLASS_NAME = RobotControlThread.class.getSimpleName();
|
private static final String CLASS_NAME = RobotControlThread.class.getSimpleName();
|
||||||
|
|
||||||
private NetworkConnectionListener netListener;
|
private ApplicationEventsListener netListener;
|
||||||
private ServerSocket server;
|
private ServerSocket server;
|
||||||
private Socket client;
|
private Socket client;
|
||||||
private MotorEventQueue queue;
|
private MotorEventQueue queue;
|
||||||
@@ -69,7 +69,7 @@ public class RobotControlThread extends Thread {
|
|||||||
return SingletonHolder.INSTANCE;
|
return SingletonHolder.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addNetworkConnectionListener(NetworkConnectionListener listener){
|
public void addNetworkConnectionListener(ApplicationEventsListener listener){
|
||||||
netListener = listener;
|
netListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -20,7 +20,7 @@ import java.io.InputStream;
|
|||||||
import java.net.ServerSocket;
|
import java.net.ServerSocket;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
|
||||||
import ve.ucv.ciens.ccg.nxtar.interfaces.NetworkConnectionListener;
|
import ve.ucv.ciens.ccg.nxtar.interfaces.ApplicationEventsListener;
|
||||||
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
@@ -30,7 +30,7 @@ public class SensorReportThread extends Thread {
|
|||||||
private static final String TAG = "NXTAR_CORE_ROBOTTHREAD";
|
private static final String TAG = "NXTAR_CORE_ROBOTTHREAD";
|
||||||
private static final String CLASS_NAME = SensorReportThread.class.getSimpleName();
|
private static final String CLASS_NAME = SensorReportThread.class.getSimpleName();
|
||||||
|
|
||||||
private NetworkConnectionListener netListener;
|
private ApplicationEventsListener netListener;
|
||||||
private ServerSocket server;
|
private ServerSocket server;
|
||||||
private Socket client;
|
private Socket client;
|
||||||
private Object pauseMonitor;
|
private Object pauseMonitor;
|
||||||
@@ -63,7 +63,7 @@ public class SensorReportThread extends Thread {
|
|||||||
return SingletonHolder.INSTANCE;
|
return SingletonHolder.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addNetworkConnectionListener(NetworkConnectionListener listener){
|
public void addNetworkConnectionListener(ApplicationEventsListener listener){
|
||||||
netListener = listener;
|
netListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -23,7 +23,7 @@ import java.net.DatagramSocket;
|
|||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
|
||||||
import ve.ucv.ciens.ccg.networkdata.VideoFrameDataMessage;
|
import ve.ucv.ciens.ccg.networkdata.VideoFrameDataMessage;
|
||||||
import ve.ucv.ciens.ccg.nxtar.interfaces.NetworkConnectionListener;
|
import ve.ucv.ciens.ccg.nxtar.interfaces.ApplicationEventsListener;
|
||||||
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
|
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
|
||||||
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ public class VideoStreamingThread extends Thread{
|
|||||||
private static final String TAG = "NXTAR_CORE_VIDEOTHREAD";
|
private static final String TAG = "NXTAR_CORE_VIDEOTHREAD";
|
||||||
private static final String CLASS_NAME = VideoStreamingThread.class.getSimpleName();
|
private static final String CLASS_NAME = VideoStreamingThread.class.getSimpleName();
|
||||||
|
|
||||||
private NetworkConnectionListener netListener;
|
private ApplicationEventsListener netListener;
|
||||||
private DatagramSocket socket;
|
private DatagramSocket socket;
|
||||||
private boolean protocolStarted;
|
private boolean protocolStarted;
|
||||||
private boolean done;
|
private boolean done;
|
||||||
@@ -79,7 +79,7 @@ public class VideoStreamingThread extends Thread{
|
|||||||
return SingletonHolder.INSTANCE;
|
return SingletonHolder.INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addNetworkConnectionListener(NetworkConnectionListener listener){
|
public void addNetworkConnectionListener(ApplicationEventsListener listener){
|
||||||
netListener = listener;
|
netListener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ public class VideoStreamingThread extends Thread{
|
|||||||
VideoFrameDataMessage dataMessage;
|
VideoFrameDataMessage dataMessage;
|
||||||
Object tmpMessage;
|
Object tmpMessage;
|
||||||
|
|
||||||
Gdx.app.debug(TAG, CLASS_NAME + ".receiveUdp() :: Reading message size from socket.");
|
//Gdx.app.debug(TAG, CLASS_NAME + ".receiveUdp() :: Reading message size from socket.");
|
||||||
try{
|
try{
|
||||||
packet = new DatagramPacket(size, size.length);
|
packet = new DatagramPacket(size, size.length);
|
||||||
socket.receive(packet);
|
socket.receive(packet);
|
||||||
@@ -148,11 +148,11 @@ public class VideoStreamingThread extends Thread{
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Gdx.app.debug(TAG, CLASS_NAME + ".receiveUdp() :: Creating buffers.");
|
//Gdx.app.debug(TAG, CLASS_NAME + ".receiveUdp() :: Creating buffers.");
|
||||||
intSize = byteArray2Int(size);
|
intSize = byteArray2Int(size);
|
||||||
data = new byte[intSize];
|
data = new byte[intSize];
|
||||||
|
|
||||||
Gdx.app.debug(TAG, CLASS_NAME + ".receiveUdp() :: Reading message from socket.");
|
//Gdx.app.debug(TAG, CLASS_NAME + ".receiveUdp() :: Reading message from socket.");
|
||||||
try{
|
try{
|
||||||
packet = new DatagramPacket(data, data.length);
|
packet = new DatagramPacket(data, data.length);
|
||||||
socket.receive(packet);
|
socket.receive(packet);
|
||||||
@@ -164,17 +164,16 @@ public class VideoStreamingThread extends Thread{
|
|||||||
|
|
||||||
ByteArrayInputStream bais = new ByteArrayInputStream(data);
|
ByteArrayInputStream bais = new ByteArrayInputStream(data);
|
||||||
|
|
||||||
Gdx.app.debug(TAG, CLASS_NAME + ".receiveUdp() :: Saving message in monitor.");
|
//Gdx.app.debug(TAG, CLASS_NAME + ".receiveUdp() :: Saving message in monitor.");
|
||||||
try{
|
try{
|
||||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
ObjectInputStream ois = new ObjectInputStream(bais);
|
||||||
tmpMessage = ois.readObject();
|
tmpMessage = ois.readObject();
|
||||||
|
|
||||||
if(tmpMessage instanceof VideoFrameDataMessage){
|
if(tmpMessage instanceof VideoFrameDataMessage){
|
||||||
Gdx.app.debug(TAG, CLASS_NAME + ".receiveUdp() :: Received a data message.");
|
//Gdx.app.debug(TAG, CLASS_NAME + ".receiveUdp() :: Received a data message.");
|
||||||
dataMessage = (VideoFrameDataMessage) tmpMessage;
|
dataMessage = (VideoFrameDataMessage) tmpMessage;
|
||||||
|
|
||||||
Gdx.app.debug(TAG, CLASS_NAME + ".receiveUdp() :: Received frame dimensions are: " +
|
//Gdx.app.debug(TAG, CLASS_NAME + ".receiveUdp() :: Received frame dimensions are: " + Integer.toString(dataMessage.imageWidth) + "x" + Integer.toString(dataMessage.imageHeight));
|
||||||
Integer.toString(dataMessage.imageWidth) + "x" + Integer.toString(dataMessage.imageHeight));
|
|
||||||
frameMonitor.setFrameDimensions(dataMessage.imageWidth, dataMessage.imageHeight);
|
frameMonitor.setFrameDimensions(dataMessage.imageWidth, dataMessage.imageHeight);
|
||||||
frameMonitor.setNewFrame(dataMessage.data);
|
frameMonitor.setNewFrame(dataMessage.data);
|
||||||
|
|
||||||
@@ -218,7 +217,7 @@ public class VideoStreamingThread extends Thread{
|
|||||||
try{ pauseMonitor.wait(); }catch(InterruptedException ie){ }
|
try{ pauseMonitor.wait(); }catch(InterruptedException ie){ }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Gdx.app.debug(TAG, CLASS_NAME + ".run() :: Receiving.");
|
//Gdx.app.debug(TAG, CLASS_NAME + ".run() :: Receiving.");
|
||||||
if(netListener != null && !coreNotified && frameMonitor.getCurrentFrame() != null){
|
if(netListener != null && !coreNotified && frameMonitor.getCurrentFrame() != null){
|
||||||
coreNotified = true;
|
coreNotified = true;
|
||||||
netListener.networkStreamConnected(THREAD_NAME);
|
netListener.networkStreamConnected(THREAD_NAME);
|
||||||
|
@@ -1,88 +1,165 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2014 Miguel Angel Astor Romero
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package ve.ucv.ciens.ccg.nxtar.states;
|
package ve.ucv.ciens.ccg.nxtar.states;
|
||||||
|
|
||||||
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
|
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
|
||||||
|
|
||||||
import com.badlogic.gdx.InputProcessor;
|
import com.badlogic.gdx.InputProcessor;
|
||||||
import com.badlogic.gdx.Screen;
|
import com.badlogic.gdx.Screen;
|
||||||
import com.badlogic.gdx.controllers.Controller;
|
import com.badlogic.gdx.controllers.Controller;
|
||||||
import com.badlogic.gdx.controllers.ControllerListener;
|
import com.badlogic.gdx.controllers.ControllerListener;
|
||||||
import com.badlogic.gdx.controllers.PovDirection;
|
import com.badlogic.gdx.controllers.PovDirection;
|
||||||
import com.badlogic.gdx.math.Vector3;
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
public abstract class BaseState implements Screen, ControllerListener, InputProcessor {
|
import com.badlogic.gdx.math.Vector3;
|
||||||
protected NxtARCore core;
|
|
||||||
protected boolean stateActive;
|
public abstract class BaseState implements Screen, ControllerListener, InputProcessor{
|
||||||
|
protected NxtARCore core;
|
||||||
/* STATE METHODS */
|
protected boolean stateActive;
|
||||||
public abstract void onStateSet();
|
protected OrthographicCamera pixelPerfectCamera;
|
||||||
public abstract void onStateUnset();
|
protected Vector3 win2world;
|
||||||
|
protected Vector2 touchPointWorldCoords;
|
||||||
/* SCREEN METHODS*/
|
|
||||||
@Override
|
/*;;;;;;;;;;;;;;;;;
|
||||||
public abstract void render(float delta);
|
; STATE METHODS ;
|
||||||
@Override
|
;;;;;;;;;;;;;;;;;*/
|
||||||
public abstract void resize(int width, int height);
|
|
||||||
@Override
|
public abstract void onStateSet();
|
||||||
public abstract void show();
|
public abstract void onStateUnset();
|
||||||
@Override
|
|
||||||
public abstract void hide();
|
/*;;;;;;;;;;;;;;;;;;
|
||||||
@Override
|
; SCREEN METHODS ;
|
||||||
public abstract void pause();
|
;;;;;;;;;;;;;;;;;;*/
|
||||||
@Override
|
|
||||||
public abstract void resume();
|
@Override
|
||||||
@Override
|
public abstract void render(float delta);
|
||||||
public abstract void dispose();
|
|
||||||
|
@Override
|
||||||
/* INPUT PROCESSOR METHODS. */
|
public abstract void dispose();
|
||||||
@Override
|
|
||||||
public abstract boolean keyDown(int keycode);
|
@Override
|
||||||
@Override
|
public void resize(int width, int height){ }
|
||||||
public abstract boolean keyUp(int keycode);
|
|
||||||
@Override
|
@Override
|
||||||
public abstract boolean keyTyped(char character);
|
public void show(){ }
|
||||||
@Override
|
|
||||||
public abstract boolean touchDown(int screenX, int screenY, int pointer, int button);
|
@Override
|
||||||
@Override
|
public void hide(){ }
|
||||||
public abstract boolean touchUp(int screenX, int screenY, int pointer, int button);
|
|
||||||
@Override
|
@Override
|
||||||
public abstract boolean touchDragged(int screenX, int screenY, int pointer);
|
public void pause(){ }
|
||||||
@Override
|
|
||||||
public abstract boolean mouseMoved(int screenX, int screenY);
|
@Override
|
||||||
@Override
|
public void resume(){ }
|
||||||
public abstract boolean scrolled(int amount);
|
|
||||||
|
/*;;;;;;;;;;;;;;;;;;
|
||||||
/* CONTROLLER LISTENER METHODS. */
|
; HELPER METHODS ;
|
||||||
@Override
|
;;;;;;;;;;;;;;;;;;*/
|
||||||
public abstract void connected(Controller controller);
|
|
||||||
@Override
|
protected final void unprojectTouch(int screenX, int screenY){
|
||||||
public abstract void disconnected(Controller controller);
|
win2world.set(screenX, screenY, 0.0f);
|
||||||
@Override
|
pixelPerfectCamera.unproject(win2world);
|
||||||
public abstract boolean buttonDown(Controller controller, int buttonCode);
|
touchPointWorldCoords.set(win2world.x, win2world.y);
|
||||||
@Override
|
}
|
||||||
public abstract boolean buttonUp(Controller controller, int buttonCode);
|
|
||||||
@Override
|
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
public abstract boolean axisMoved(Controller controller, int axisCode, float value);
|
; INPUT PROCESSOR METHODS ;
|
||||||
@Override
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
||||||
public abstract boolean povMoved(Controller controller, int povCode, PovDirection value);
|
|
||||||
@Override
|
@Override
|
||||||
public abstract boolean xSliderMoved(Controller controller, int sliderCode, boolean value);
|
public boolean keyDown(int keycode){
|
||||||
@Override
|
return false;
|
||||||
public abstract boolean ySliderMoved(Controller controller, int sliderCode, boolean value);
|
};
|
||||||
@Override
|
|
||||||
public abstract boolean accelerometerMoved(Controller controller, int accelerometerCode, Vector3 value);
|
@Override
|
||||||
}
|
public boolean keyUp(int keycode){
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyTyped(char character){
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchDown(int screenX, int screenY, int pointer, int button){
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchUp(int screenX, int screenY, int pointer, int button){
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchDragged(int screenX, int screenY, int pointer){
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean mouseMoved(int screenX, int screenY){
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean scrolled(int amount){
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
; CONTROLLER LISTENER METHODS ;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void connected(Controller controller){ };
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void disconnected(Controller controller){ };
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean buttonDown(Controller controller, int buttonCode){
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean buttonUp(Controller controller, int buttonCode){
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
@Override
|
||||||
|
public boolean axisMoved(Controller controller, int axisCode, float value){
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean povMoved(Controller controller, int povCode, PovDirection value){
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean xSliderMoved(Controller controller, int sliderCode, boolean value){
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean ySliderMoved(Controller controller, int sliderCode, boolean value){
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean accelerometerMoved(Controller controller, int accelerometerCode, Vector3 value){
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
420
src/ve/ucv/ciens/ccg/nxtar/states/CameraCalibrationState.java
Normal file
420
src/ve/ucv/ciens/ccg/nxtar/states/CameraCalibrationState.java
Normal file
@@ -0,0 +1,420 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.states;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.CalibrationData;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.utils.Size;
|
||||||
|
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.Input;
|
||||||
|
import com.badlogic.gdx.controllers.Controller;
|
||||||
|
import com.badlogic.gdx.controllers.mappings.Ouya;
|
||||||
|
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.Texture.TextureFilter;
|
||||||
|
import com.badlogic.gdx.graphics.Texture.TextureWrap;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.NinePatch;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
|
||||||
|
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
|
||||||
|
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
||||||
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
|
import com.badlogic.gdx.math.Vector2;
|
||||||
|
import com.badlogic.gdx.math.Vector3;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
|
||||||
|
import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;
|
||||||
|
|
||||||
|
public class CameraCalibrationState extends BaseState{
|
||||||
|
private static final String TAG = "CAMERA_CALIBRATION_STATE";
|
||||||
|
private static final String CLASS_NAME = CameraCalibrationState.class.getSimpleName();
|
||||||
|
private static final String SHADER_PATH = "shaders/bckg/bckg";
|
||||||
|
|
||||||
|
private NxtARCore core;
|
||||||
|
|
||||||
|
private float u_scaling[];
|
||||||
|
protected Sprite background;
|
||||||
|
private Texture backgroundTexture;
|
||||||
|
private ShaderProgram backgroundShader;
|
||||||
|
|
||||||
|
// Cameras.
|
||||||
|
private OrthographicCamera camera;
|
||||||
|
|
||||||
|
// Video stream graphics.
|
||||||
|
private Texture videoFrameTexture;
|
||||||
|
private Sprite renderableVideoFrame;
|
||||||
|
private Pixmap videoFrame;
|
||||||
|
|
||||||
|
// Gui components.
|
||||||
|
private TextButton takeSampleButton;
|
||||||
|
private Rectangle takeSampleButtonBBox;
|
||||||
|
private Texture buttonEnabledTexture;
|
||||||
|
private Texture buttonDisabledTexture;
|
||||||
|
private Texture buttonPressedTexture;
|
||||||
|
private NinePatch buttonEnabled9p;
|
||||||
|
private NinePatch buttonDisabled9p;
|
||||||
|
private NinePatch buttonPressed9p;
|
||||||
|
private BitmapFont font;
|
||||||
|
|
||||||
|
// Button touch helper fields.
|
||||||
|
private boolean takeSampleButtonTouched;
|
||||||
|
private int takeSampleButtonPointer;
|
||||||
|
|
||||||
|
// Monitors.
|
||||||
|
private VideoFrameMonitor frameMonitor;
|
||||||
|
|
||||||
|
private float[][] calibrationSamples;
|
||||||
|
private boolean takeSample;
|
||||||
|
private int lastSampleTaken;
|
||||||
|
|
||||||
|
public CameraCalibrationState(final NxtARCore core){
|
||||||
|
TextButtonStyle tbs;
|
||||||
|
FreeTypeFontGenerator generator;
|
||||||
|
FreeTypeFontParameter param;
|
||||||
|
|
||||||
|
this.core = core;
|
||||||
|
frameMonitor = VideoFrameMonitor.getInstance();
|
||||||
|
|
||||||
|
// Set up the cameras.
|
||||||
|
pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
|
camera = new OrthographicCamera(1.0f, Gdx.graphics.getHeight() / Gdx.graphics.getWidth());
|
||||||
|
|
||||||
|
// Set up the background.
|
||||||
|
backgroundTexture = new Texture(Gdx.files.internal("data/gfx/textures/tile_aqua.png"));
|
||||||
|
backgroundTexture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
|
||||||
|
backgroundTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
|
||||||
|
background = new Sprite(backgroundTexture);
|
||||||
|
background.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
|
background.setPosition(-(Gdx.graphics.getWidth() / 2), -(Gdx.graphics.getHeight() / 2));
|
||||||
|
|
||||||
|
// Load the background shader.
|
||||||
|
backgroundShader = new ShaderProgram(Gdx.files.internal(SHADER_PATH + "_vert.glsl"), Gdx.files.internal(SHADER_PATH + "_frag.glsl"));
|
||||||
|
if(!backgroundShader.isCompiled()){
|
||||||
|
Gdx.app.error(TAG, CLASS_NAME + ".CameraCalibrationState() :: Failed to compile the background shader.");
|
||||||
|
Gdx.app.error(TAG, CLASS_NAME + backgroundShader.getLog());
|
||||||
|
backgroundShader = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set up the background scaling.
|
||||||
|
u_scaling = new float[2];
|
||||||
|
u_scaling[0] = Gdx.graphics.getWidth() > Gdx.graphics.getHeight() ? 16.0f : 9.0f;
|
||||||
|
u_scaling[1] = Gdx.graphics.getHeight() > Gdx.graphics.getWidth() ? 16.0f : 9.0f;
|
||||||
|
|
||||||
|
// Set up the sampling button.
|
||||||
|
// Create the font.
|
||||||
|
param = new FreeTypeFontParameter();
|
||||||
|
param.characters = ProjectConstants.FONT_CHARS;
|
||||||
|
param.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
|
||||||
|
param.flip = false;
|
||||||
|
generator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
|
||||||
|
font = generator.generateFont(param);
|
||||||
|
generator.dispose();
|
||||||
|
|
||||||
|
// Load the textures.
|
||||||
|
buttonEnabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Yellow.png"));
|
||||||
|
buttonEnabled9p = new NinePatch(new TextureRegion(buttonEnabledTexture, 0, 0, buttonEnabledTexture.getWidth(), buttonEnabledTexture.getHeight()), 49, 49, 45, 45);
|
||||||
|
buttonDisabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Cyan.png"));
|
||||||
|
buttonDisabled9p = new NinePatch(new TextureRegion(buttonDisabledTexture, 0, 0, buttonDisabledTexture.getWidth(), buttonDisabledTexture.getHeight()), 49, 49, 45, 45);
|
||||||
|
buttonPressedTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Blue.png"));
|
||||||
|
buttonPressed9p = new NinePatch(new TextureRegion(buttonPressedTexture, 0, 0, buttonPressedTexture.getWidth(), buttonPressedTexture.getHeight()), 49, 49, 45, 45);
|
||||||
|
|
||||||
|
// Create the button style.
|
||||||
|
tbs = new TextButtonStyle();
|
||||||
|
tbs.font = font;
|
||||||
|
tbs.up = new NinePatchDrawable(buttonEnabled9p);
|
||||||
|
tbs.checked = new NinePatchDrawable(buttonPressed9p);
|
||||||
|
tbs.disabled = new NinePatchDrawable(buttonDisabled9p);
|
||||||
|
tbs.disabledFontColor = new Color(0, 0, 0, 1);
|
||||||
|
|
||||||
|
// Create the button itself.
|
||||||
|
takeSampleButton = new TextButton("Take calibration sample", tbs);
|
||||||
|
takeSampleButton.setText("Take calibration sample");
|
||||||
|
takeSampleButton.setDisabled(true);
|
||||||
|
takeSampleButtonBBox = new Rectangle(0, 0, takeSampleButton.getWidth(), takeSampleButton.getHeight());
|
||||||
|
takeSampleButton.setPosition(-(takeSampleButton.getWidth() / 2), -(Gdx.graphics.getHeight()/2) - 1 + (takeSampleButton.getHeight() / 2));
|
||||||
|
takeSampleButtonBBox.setPosition(takeSampleButton.getX(), takeSampleButton.getY());
|
||||||
|
|
||||||
|
// Set up the touch collision detection variables.
|
||||||
|
win2world = new Vector3(0.0f, 0.0f, 0.0f);
|
||||||
|
touchPointWorldCoords = new Vector2();
|
||||||
|
takeSampleButtonTouched = false;
|
||||||
|
takeSampleButtonPointer = -1;
|
||||||
|
|
||||||
|
// Initialize the calibration samples vector.
|
||||||
|
calibrationSamples = new float[ProjectConstants.CALIBRATION_SAMPLES][];
|
||||||
|
for(int i = 0; i < calibrationSamples.length; i++){
|
||||||
|
calibrationSamples[i] = new float[ProjectConstants.CALIBRATION_PATTERN_POINTS * 2];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStateSet(){
|
||||||
|
Gdx.input.setInputProcessor(this);
|
||||||
|
Gdx.input.setCatchBackKey(true);
|
||||||
|
Gdx.input.setCatchMenuKey(true);
|
||||||
|
|
||||||
|
takeSample = false;
|
||||||
|
lastSampleTaken = 0;
|
||||||
|
|
||||||
|
for(int i = 0; i < calibrationSamples.length; i++){
|
||||||
|
for(int j = 0; j < calibrationSamples[i].length; j++){
|
||||||
|
calibrationSamples[i][j] = 0.0f;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onStateUnset(){ }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(float delta){
|
||||||
|
String msg;
|
||||||
|
byte[] frame;
|
||||||
|
byte[] prevFrame = null;
|
||||||
|
Size dimensions = null;
|
||||||
|
|
||||||
|
// Clear the screen.
|
||||||
|
Gdx.gl.glClearColor(1, 1, 1, 1);
|
||||||
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
|
// Render the background.
|
||||||
|
core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
||||||
|
core.batch.begin();{
|
||||||
|
if(backgroundShader != null){
|
||||||
|
core.batch.setShader(backgroundShader);
|
||||||
|
backgroundShader.setUniform2fv("u_scaling", u_scaling, 0, 2);
|
||||||
|
}
|
||||||
|
background.draw(core.batch);
|
||||||
|
if(backgroundShader != null) core.batch.setShader(null);
|
||||||
|
}core.batch.end();
|
||||||
|
|
||||||
|
// Fetch the current video frame.
|
||||||
|
frame = frameMonitor.getCurrentFrame();
|
||||||
|
|
||||||
|
// Apply the undistortion method if the camera has been calibrated already.
|
||||||
|
/*if(core.cvProc.isCameraCalibrated()){
|
||||||
|
frame = core.cvProc.undistortFrame(frame);
|
||||||
|
}*/
|
||||||
|
|
||||||
|
// Find the calibration points in the video frame.
|
||||||
|
CalibrationData data = core.cvProc.findCalibrationPattern(frame);
|
||||||
|
|
||||||
|
// Disable the sampling button if the calibration pattern was not found.
|
||||||
|
if(data.calibrationPoints != null && !core.cvProc.isCameraCalibrated()){
|
||||||
|
takeSampleButton.setDisabled(false);
|
||||||
|
}else{
|
||||||
|
takeSampleButton.setDisabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the user requested a sample be taken.
|
||||||
|
if(takeSample && !core.cvProc.isCameraCalibrated() && data.calibrationPoints != null){
|
||||||
|
// Disable sample taking.
|
||||||
|
takeSample = false;
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".render(): Sample taken.");
|
||||||
|
|
||||||
|
// Save the calibration points to the samples array.
|
||||||
|
for(int i = 0; i < data.calibrationPoints.length; i += 2){
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".render(): Value " + Integer.toString(i) + " = (" + Float.toString(data.calibrationPoints[i]) + ", " + Float.toString(data.calibrationPoints[i + 1]) + ")");
|
||||||
|
calibrationSamples[lastSampleTaken][i] = data.calibrationPoints[i];
|
||||||
|
calibrationSamples[lastSampleTaken][i + 1] = data.calibrationPoints[i + 1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Move to the next sample.
|
||||||
|
lastSampleTaken++;
|
||||||
|
|
||||||
|
msg = Integer.toString(lastSampleTaken) + " samples taken. ";
|
||||||
|
msg += Integer.toString(ProjectConstants.CALIBRATION_SAMPLES - lastSampleTaken) + " samples left.";
|
||||||
|
core.toast(msg, false);
|
||||||
|
|
||||||
|
// If enough samples has been taken then calibrate the camera.
|
||||||
|
if(lastSampleTaken == ProjectConstants.CALIBRATION_SAMPLES){
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + "render(): Last sample taken.");
|
||||||
|
|
||||||
|
core.cvProc.calibrateCamera(calibrationSamples, frame);
|
||||||
|
msg = "Camera successfully calibrated";
|
||||||
|
core.toast(msg, true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(frame != null && data != null && data.outFrame != null && !Arrays.equals(frame, prevFrame)){
|
||||||
|
// If the received frame is valid and is different from the previous frame.
|
||||||
|
// Make a texture from the frame.
|
||||||
|
dimensions = frameMonitor.getFrameDimensions();
|
||||||
|
videoFrame = new Pixmap(data.outFrame, 0, dimensions.getWidth() * dimensions.getHeight());
|
||||||
|
videoFrameTexture = new Texture(videoFrame);
|
||||||
|
videoFrameTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
|
||||||
|
videoFrame.dispose();
|
||||||
|
|
||||||
|
// Set up the frame texture as a rendereable sprite.
|
||||||
|
TextureRegion region = new TextureRegion(videoFrameTexture, 0, 0, dimensions.getWidth(), dimensions.getHeight());
|
||||||
|
renderableVideoFrame = new Sprite(region);
|
||||||
|
renderableVideoFrame.setOrigin(renderableVideoFrame.getWidth() / 2, renderableVideoFrame.getHeight() / 2);
|
||||||
|
if(!Ouya.runningOnOuya){
|
||||||
|
renderableVideoFrame.setSize(1.0f, renderableVideoFrame.getHeight() / renderableVideoFrame.getWidth() );
|
||||||
|
renderableVideoFrame.rotate90(true);
|
||||||
|
renderableVideoFrame.translate(-renderableVideoFrame.getWidth() / 2, 0.5f - renderableVideoFrame.getHeight());
|
||||||
|
}else{
|
||||||
|
float xSize = Gdx.graphics.getHeight() * (dimensions.getWidth() / dimensions.getHeight());
|
||||||
|
renderableVideoFrame.setSize(xSize * ProjectConstants.OVERSCAN, Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN);
|
||||||
|
renderableVideoFrame.rotate90(true);
|
||||||
|
renderableVideoFrame.translate(-renderableVideoFrame.getWidth() / 2, -renderableVideoFrame.getHeight() / 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render the frame.
|
||||||
|
if(!Ouya.runningOnOuya){
|
||||||
|
core.batch.setProjectionMatrix(camera.combined);
|
||||||
|
}else{
|
||||||
|
core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
||||||
|
}
|
||||||
|
core.batch.begin();{
|
||||||
|
renderableVideoFrame.draw(core.batch);
|
||||||
|
}core.batch.end();
|
||||||
|
|
||||||
|
// Clear texture memory.
|
||||||
|
videoFrameTexture.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render the user interface.
|
||||||
|
if(!Ouya.runningOnOuya){
|
||||||
|
core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
||||||
|
core.batch.begin();{
|
||||||
|
takeSampleButton.draw(core.batch, 1.0f);
|
||||||
|
}core.batch.end();
|
||||||
|
}else{
|
||||||
|
// TODO: Render OUYA gui.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save this frame as previous to avoid processing the same frame twice when network latency is high.
|
||||||
|
prevFrame = frame;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resize(int width, int height){ }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void show(){ }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void hide(){ }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pause(){ }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resume(){ }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void dispose(){
|
||||||
|
if(videoFrameTexture != null)
|
||||||
|
videoFrameTexture.dispose();
|
||||||
|
backgroundTexture.dispose();
|
||||||
|
if(backgroundShader != null) backgroundShader.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
/*;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
; INPUT LISTENER METHODS ;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean keyDown(int keycode){
|
||||||
|
if(keycode == Input.Keys.BACK){
|
||||||
|
core.nextState = game_states_t.MAIN_MENU;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchDown(int screenX, int screenY, int pointer, int button){
|
||||||
|
unprojectTouch(screenX, screenY);
|
||||||
|
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown(%d, %d, %d, %d)", screenX, screenY, pointer, button));
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
|
||||||
|
|
||||||
|
if(!takeSampleButton.isDisabled() && takeSampleButtonBBox.contains(touchPointWorldCoords) && !takeSampleButtonTouched){
|
||||||
|
takeSampleButton.setChecked(true);
|
||||||
|
takeSampleButtonTouched = true;
|
||||||
|
takeSampleButtonPointer = pointer;
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Sample button pressed.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchUp(int screenX, int screenY, int pointer, int button){
|
||||||
|
unprojectTouch(screenX, screenY);
|
||||||
|
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp(%d, %d, %d, %d)", screenX, screenY, pointer, button));
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
|
||||||
|
|
||||||
|
if(!takeSampleButton.isDisabled() && takeSampleButtonBBox.contains(touchPointWorldCoords) && takeSampleButtonTouched){
|
||||||
|
takeSampleButton.setChecked(false);
|
||||||
|
takeSampleButtonTouched = false;
|
||||||
|
takeSampleButtonPointer = -1;
|
||||||
|
takeSample = true;
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Sample button released.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean touchDragged(int screenX, int screenY, int pointer){
|
||||||
|
unprojectTouch(screenX, screenY);
|
||||||
|
|
||||||
|
if(!takeSampleButton.isDisabled() && takeSampleButtonTouched && pointer == takeSampleButtonPointer && !takeSampleButtonBBox.contains(touchPointWorldCoords)){
|
||||||
|
takeSampleButtonPointer = -1;
|
||||||
|
takeSampleButtonTouched = false;
|
||||||
|
takeSampleButton.setChecked(false);
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Sample button released.");
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean buttonDown(Controller controller, int buttonCode){
|
||||||
|
// TODO: Handle OUYA controls.
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean buttonUp(Controller controller, int buttonCode){
|
||||||
|
// TODO: Handle OUYA controls.
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean axisMoved(Controller controller, int axisCode, float value){
|
||||||
|
// TODO: Handle OUYA controls.
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
@@ -1,351 +1,324 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2014 Miguel Angel Astor Romero
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
* you may not use this file except in compliance with the License.
|
* you may not use this file except in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
package ve.ucv.ciens.ccg.nxtar.states;
|
package ve.ucv.ciens.ccg.nxtar.states;
|
||||||
|
|
||||||
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
|
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
|
||||||
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.Input;
|
import com.badlogic.gdx.Input;
|
||||||
import com.badlogic.gdx.controllers.Controller;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.controllers.PovDirection;
|
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||||
import com.badlogic.gdx.controllers.mappings.Ouya;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Texture.TextureFilter;
|
||||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
import com.badlogic.gdx.graphics.Texture.TextureWrap;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||||
import com.badlogic.gdx.graphics.Texture.TextureFilter;
|
import com.badlogic.gdx.graphics.g2d.NinePatch;
|
||||||
import com.badlogic.gdx.graphics.Texture.TextureWrap;
|
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||||
import com.badlogic.gdx.graphics.g2d.NinePatch;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
|
||||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator.FreeTypeFontParameter;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
||||||
import com.badlogic.gdx.graphics.g2d.freetype.FreeTypeFontGenerator;
|
import com.badlogic.gdx.math.Rectangle;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.math.Rectangle;
|
import com.badlogic.gdx.math.Vector3;
|
||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
||||||
import com.badlogic.gdx.math.Vector3;
|
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton;
|
import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;
|
||||||
import com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle;
|
|
||||||
import com.badlogic.gdx.scenes.scene2d.utils.NinePatchDrawable;
|
public abstract class MainMenuStateBase extends BaseState{
|
||||||
|
protected static final String TAG = "MAIN_MENU";
|
||||||
|
private static final String CLASS_NAME = MainMenuStateBase.class.getSimpleName();
|
||||||
public abstract class MainMenuStateBase extends BaseState{
|
private static final String SHADER_PATH = "shaders/bckg/bckg";
|
||||||
protected static final String TAG = "MAIN_MENU";
|
|
||||||
private static final String CLASS_NAME = MainMenuStateBase.class.getSimpleName();
|
protected final int NUM_MENU_BUTTONS = 2;
|
||||||
|
|
||||||
private static final String SHADER_PATH = "shaders/bckg/bckg";
|
// Helper fields.
|
||||||
|
protected boolean clientConnected;
|
||||||
// Helper fields.
|
private float u_scaling[];
|
||||||
protected boolean clientConnected;
|
|
||||||
private float u_scaling[];
|
// Buttons and other gui components.
|
||||||
protected OrthographicCamera pixelPerfectCamera;
|
protected TextButton startButton;
|
||||||
|
protected Rectangle startButtonBBox;
|
||||||
// Buttons and other gui components.
|
protected Sprite clientConnectedLedOn;
|
||||||
protected TextButton startButton;
|
protected Sprite clientConnectedLedOff;
|
||||||
protected Rectangle startButtonBBox;
|
|
||||||
protected Sprite clientConnectedLedOn;
|
protected TextButton calibrationButton;
|
||||||
protected Sprite clientConnectedLedOff;
|
protected Rectangle calibrationButtonBBox;
|
||||||
protected Sprite background;
|
protected Sprite cameraCalibratedLedOn;
|
||||||
|
protected Sprite cameraCalibratedLedOff;
|
||||||
// Graphic data for the start button.
|
|
||||||
private Texture startButtonEnabledTexture;
|
protected Sprite background;
|
||||||
private Texture startButtonDisabledTexture;
|
|
||||||
private Texture startButtonPressedTexture;
|
// Graphic data for the start button.
|
||||||
private NinePatch startButtonEnabled9p;
|
private Texture menuButtonEnabledTexture;
|
||||||
private NinePatch startButtonDisabled9p;
|
private Texture menuButtonDisabledTexture;
|
||||||
private NinePatch startButtonPressed9p;
|
private Texture menuButtonPressedTexture;
|
||||||
private BitmapFont font;
|
private NinePatch menuButtonEnabled9p;
|
||||||
|
private NinePatch menuButtonDisabled9p;
|
||||||
// Other graphics.
|
private NinePatch menuButtonPressed9p;
|
||||||
private Texture clientConnectedLedOffTexture;
|
private BitmapFont font;
|
||||||
private Texture clientConnectedLedOnTexture;
|
|
||||||
private Texture backgroundTexture;
|
// Other graphics.
|
||||||
private ShaderProgram backgroundShader;
|
private Texture cameraCalibratedLedOffTexture;
|
||||||
|
private Texture cameraCalibratedLedOnTexture;
|
||||||
// Button touch helper fields.
|
private Texture clientConnectedLedOffTexture;
|
||||||
private Vector3 win2world;
|
private Texture clientConnectedLedOnTexture;
|
||||||
protected Vector2 touchPointWorldCoords;
|
private Texture backgroundTexture;
|
||||||
protected boolean startButtonTouched;
|
private ShaderProgram backgroundShader;
|
||||||
protected int startButtonTouchPointer;
|
|
||||||
|
// Button touch helper fields.
|
||||||
public MainMenuStateBase(){
|
protected boolean startButtonTouched;
|
||||||
TextureRegion region;
|
protected int startButtonTouchPointer;
|
||||||
|
protected boolean calibrationButtonTouched;
|
||||||
this.pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
protected int calibrationButtonTouchPointer;
|
||||||
|
|
||||||
// Create the start button background.
|
public MainMenuStateBase(){
|
||||||
startButtonEnabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Yellow.png"));
|
TextureRegion region;
|
||||||
startButtonEnabled9p = new NinePatch(new TextureRegion(startButtonEnabledTexture, 0, 0, startButtonEnabledTexture.getWidth(), startButtonEnabledTexture.getHeight()), 49, 49, 45, 45);
|
TextButtonStyle tbs;
|
||||||
|
FreeTypeFontGenerator generator;
|
||||||
startButtonDisabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Cyan.png"));
|
FreeTypeFontParameter param;
|
||||||
startButtonDisabled9p = new NinePatch(new TextureRegion(startButtonDisabledTexture, 0, 0, startButtonDisabledTexture.getWidth(), startButtonDisabledTexture.getHeight()), 49, 49, 45, 45);
|
|
||||||
|
this.pixelPerfectCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
startButtonPressedTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Blue.png"));
|
|
||||||
startButtonPressed9p = new NinePatch(new TextureRegion(startButtonPressedTexture, 0, 0, startButtonPressedTexture.getWidth(), startButtonPressedTexture.getHeight()), 49, 49, 45, 45);
|
// Create the start button background.
|
||||||
|
menuButtonEnabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Yellow.png"));
|
||||||
// Create the start button font.
|
menuButtonEnabled9p = new NinePatch(new TextureRegion(menuButtonEnabledTexture, 0, 0, menuButtonEnabledTexture.getWidth(), menuButtonEnabledTexture.getHeight()), 49, 49, 45, 45);
|
||||||
FreeTypeFontGenerator generator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
|
|
||||||
font = generator.generateFont(Ouya.runningOnOuya ? 60 : 40, ProjectConstants.FONT_CHARS, false);
|
menuButtonDisabledTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Cyan.png"));
|
||||||
generator.dispose();
|
menuButtonDisabled9p = new NinePatch(new TextureRegion(menuButtonDisabledTexture, 0, 0, menuButtonDisabledTexture.getWidth(), menuButtonDisabledTexture.getHeight()), 49, 49, 45, 45);
|
||||||
|
|
||||||
// Create the start button itself.
|
menuButtonPressedTexture = new Texture(Gdx.files.internal("data/gfx/gui/Anonymous_Pill_Button_Blue.png"));
|
||||||
TextButtonStyle tbs = new TextButtonStyle();
|
menuButtonPressed9p = new NinePatch(new TextureRegion(menuButtonPressedTexture, 0, 0, menuButtonPressedTexture.getWidth(), menuButtonPressedTexture.getHeight()), 49, 49, 45, 45);
|
||||||
tbs.font = font;
|
|
||||||
tbs.up = new NinePatchDrawable(startButtonEnabled9p);
|
// Create the start button font.
|
||||||
tbs.checked = new NinePatchDrawable(startButtonPressed9p);
|
param = new FreeTypeFontParameter();
|
||||||
tbs.disabled = new NinePatchDrawable(startButtonDisabled9p);
|
param.characters = ProjectConstants.FONT_CHARS;
|
||||||
tbs.disabledFontColor = new Color(0, 0, 0, 1);
|
param.size = ProjectConstants.MENU_BUTTON_FONT_SIZE;
|
||||||
startButton = new TextButton("Start server", tbs);
|
param.flip = false;
|
||||||
startButton.setText("Start game");
|
generator = new FreeTypeFontGenerator(Gdx.files.internal("data/fonts/d-puntillas-B-to-tiptoe.ttf"));
|
||||||
startButton.setDisabled(true);
|
font = generator.generateFont(param);
|
||||||
startButtonBBox = new Rectangle(0, 0, startButton.getWidth(), startButton.getHeight());
|
generator.dispose();
|
||||||
|
|
||||||
// Create the connection leds.
|
// Create the start button.
|
||||||
clientConnectedLedOnTexture = new Texture("data/gfx/gui/Anonymous_Button_Green.png");
|
tbs = new TextButtonStyle();
|
||||||
region = new TextureRegion(clientConnectedLedOnTexture);
|
tbs.font = font;
|
||||||
clientConnectedLedOn = new Sprite(region);
|
tbs.up = new NinePatchDrawable(menuButtonEnabled9p);
|
||||||
|
tbs.checked = new NinePatchDrawable(menuButtonPressed9p);
|
||||||
clientConnectedLedOffTexture = new Texture("data/gfx/gui/Anonymous_Button_Red.png");
|
tbs.disabled = new NinePatchDrawable(menuButtonDisabled9p);
|
||||||
region = new TextureRegion(clientConnectedLedOffTexture);
|
tbs.disabledFontColor = new Color(0, 0, 0, 1);
|
||||||
clientConnectedLedOff = new Sprite(region);
|
|
||||||
|
startButton = new TextButton("Start server", tbs);
|
||||||
// Set up the background.
|
startButton.setText("Start game");
|
||||||
backgroundTexture = new Texture(Gdx.files.internal("data/gfx/textures/tile_aqua.png"));
|
startButton.setDisabled(true);
|
||||||
backgroundTexture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
|
startButtonBBox = new Rectangle(0, 0, startButton.getWidth(), startButton.getHeight());
|
||||||
backgroundTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
|
|
||||||
region = new TextureRegion(backgroundTexture);
|
// Create the calibration button.
|
||||||
background = new Sprite(backgroundTexture);
|
calibrationButton = new TextButton("Calibrate camera", tbs);
|
||||||
background.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
calibrationButton.setText("Calibrate camera");
|
||||||
background.setPosition(-(Gdx.graphics.getWidth() / 2), -(Gdx.graphics.getHeight() / 2));
|
calibrationButton.setDisabled(true);
|
||||||
|
calibrationButtonBBox = new Rectangle(0, 0, calibrationButton.getWidth(), calibrationButton.getHeight());
|
||||||
backgroundShader = new ShaderProgram(Gdx.files.internal(SHADER_PATH + ".vert"), Gdx.files.internal(SHADER_PATH + ".frag"));
|
|
||||||
if(!backgroundShader.isCompiled()){
|
// Create the connection leds.
|
||||||
Gdx.app.error(TAG, CLASS_NAME + ".MainMenuStateBase() :: Failed to compile the background shader.");
|
clientConnectedLedOnTexture = new Texture("data/gfx/gui/Anonymous_Button_Green.png");
|
||||||
Gdx.app.error(TAG, CLASS_NAME + backgroundShader.getLog());
|
region = new TextureRegion(clientConnectedLedOnTexture);
|
||||||
backgroundShader = null;
|
clientConnectedLedOn = new Sprite(region);
|
||||||
}
|
|
||||||
|
clientConnectedLedOffTexture = new Texture("data/gfx/gui/Anonymous_Button_Red.png");
|
||||||
u_scaling = new float[2];
|
region = new TextureRegion(clientConnectedLedOffTexture);
|
||||||
u_scaling[0] = Gdx.graphics.getWidth() > Gdx.graphics.getHeight() ? 16.0f : 9.0f;
|
clientConnectedLedOff = new Sprite(region);
|
||||||
u_scaling[1] = Gdx.graphics.getHeight() > Gdx.graphics.getWidth() ? 16.0f : 9.0f;
|
|
||||||
|
cameraCalibratedLedOnTexture = new Texture("data/gfx/gui/Anonymous_Button_Green.png");
|
||||||
|
region = new TextureRegion(cameraCalibratedLedOnTexture);
|
||||||
win2world = new Vector3(0.0f, 0.0f, 0.0f);
|
cameraCalibratedLedOn = new Sprite(region);
|
||||||
touchPointWorldCoords = new Vector2();
|
|
||||||
startButtonTouched = false;
|
cameraCalibratedLedOffTexture = new Texture("data/gfx/gui/Anonymous_Button_Red.png");
|
||||||
startButtonTouchPointer = -1;
|
region = new TextureRegion(cameraCalibratedLedOffTexture);
|
||||||
|
cameraCalibratedLedOff = new Sprite(region);
|
||||||
clientConnected = false;
|
|
||||||
stateActive = false;
|
// Set up the background.
|
||||||
}
|
backgroundTexture = new Texture(Gdx.files.internal("data/gfx/textures/tile_aqua.png"));
|
||||||
|
backgroundTexture.setWrap(TextureWrap.Repeat, TextureWrap.Repeat);
|
||||||
@Override
|
backgroundTexture.setFilter(TextureFilter.Linear, TextureFilter.Linear);
|
||||||
public abstract void render(float delta);
|
region = new TextureRegion(backgroundTexture);
|
||||||
|
background = new Sprite(backgroundTexture);
|
||||||
@Override
|
background.setSize(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
|
||||||
public void resize(int width, int height){ }
|
background.setPosition(-(Gdx.graphics.getWidth() / 2), -(Gdx.graphics.getHeight() / 2));
|
||||||
|
|
||||||
@Override
|
backgroundShader = new ShaderProgram(Gdx.files.internal(SHADER_PATH + "_vert.glsl"), Gdx.files.internal(SHADER_PATH + "_frag.glsl"));
|
||||||
public void show(){ }
|
if(!backgroundShader.isCompiled()){
|
||||||
@Override
|
Gdx.app.error(TAG, CLASS_NAME + ".MainMenuStateBase() :: Failed to compile the background shader.");
|
||||||
public void hide(){ }
|
Gdx.app.error(TAG, CLASS_NAME + backgroundShader.getLog());
|
||||||
|
backgroundShader = null;
|
||||||
@Override
|
}
|
||||||
public void pause(){ }
|
|
||||||
|
u_scaling = new float[2];
|
||||||
@Override
|
u_scaling[0] = Gdx.graphics.getWidth() > Gdx.graphics.getHeight() ? 16.0f : 9.0f;
|
||||||
public void resume(){ }
|
u_scaling[1] = Gdx.graphics.getHeight() > Gdx.graphics.getWidth() ? 16.0f : 9.0f;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void dispose(){
|
win2world = new Vector3(0.0f, 0.0f, 0.0f);
|
||||||
startButtonEnabledTexture.dispose();
|
touchPointWorldCoords = new Vector2();
|
||||||
startButtonDisabledTexture.dispose();
|
startButtonTouched = false;
|
||||||
startButtonPressedTexture.dispose();
|
startButtonTouchPointer = -1;
|
||||||
clientConnectedLedOnTexture.dispose();
|
calibrationButtonTouched = false;
|
||||||
clientConnectedLedOffTexture.dispose();
|
calibrationButtonTouchPointer = -1;
|
||||||
backgroundTexture.dispose();
|
|
||||||
if(backgroundShader != null) backgroundShader.dispose();
|
clientConnected = false;
|
||||||
font.dispose();
|
stateActive = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void drawBackground(SpriteBatch batch){
|
@Override
|
||||||
if(backgroundShader != null){
|
public abstract void render(float delta);
|
||||||
batch.setShader(backgroundShader);
|
|
||||||
backgroundShader.setUniform2fv("u_scaling", u_scaling, 0, 2);
|
@Override
|
||||||
}
|
public void resize(int width, int height){ }
|
||||||
background.draw(batch);
|
|
||||||
if(backgroundShader != null) batch.setShader(null);
|
@Override
|
||||||
}
|
public void show(){ }
|
||||||
|
@Override
|
||||||
@Override
|
public void hide(){ }
|
||||||
public void onStateSet(){
|
|
||||||
stateActive = true;
|
@Override
|
||||||
Gdx.input.setInputProcessor(this);
|
public void pause(){ }
|
||||||
Gdx.input.setCatchBackKey(true);
|
|
||||||
Gdx.input.setCatchMenuKey(true);
|
@Override
|
||||||
}
|
public void resume(){ }
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStateUnset(){
|
public void dispose(){
|
||||||
stateActive = false;
|
menuButtonEnabledTexture.dispose();
|
||||||
Gdx.input.setInputProcessor(null);
|
menuButtonDisabledTexture.dispose();
|
||||||
Gdx.input.setCatchBackKey(false);
|
menuButtonPressedTexture.dispose();
|
||||||
Gdx.input.setCatchMenuKey(false);
|
clientConnectedLedOnTexture.dispose();
|
||||||
}
|
clientConnectedLedOffTexture.dispose();
|
||||||
|
cameraCalibratedLedOnTexture.dispose();
|
||||||
public void onClientConnected(){
|
cameraCalibratedLedOffTexture.dispose();
|
||||||
clientConnected = true;
|
backgroundTexture.dispose();
|
||||||
startButton.setDisabled(false);
|
if(backgroundShader != null) backgroundShader.dispose();
|
||||||
}
|
font.dispose();
|
||||||
|
}
|
||||||
/*;;;;;;;;;;;;;;;;;;
|
|
||||||
; HELPER METHODS ;
|
protected void drawBackground(SpriteBatch batch){
|
||||||
;;;;;;;;;;;;;;;;;;*/
|
if(backgroundShader != null){
|
||||||
|
batch.setShader(backgroundShader);
|
||||||
protected void unprojectTouch(int screenX, int screenY){
|
backgroundShader.setUniform2fv("u_scaling", u_scaling, 0, 2);
|
||||||
win2world.set(screenX, screenY, 0.0f);
|
}
|
||||||
pixelPerfectCamera.unproject(win2world);
|
background.draw(batch);
|
||||||
touchPointWorldCoords.set(win2world.x, win2world.y);
|
if(backgroundShader != null) batch.setShader(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*;;;;;;;;;;;;;;;;;;;;;;;;;;
|
@Override
|
||||||
; INPUT LISTENER METHODS ;
|
public void onStateSet(){
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
stateActive = true;
|
||||||
|
Gdx.input.setInputProcessor(this);
|
||||||
@Override
|
Gdx.input.setCatchBackKey(true);
|
||||||
public boolean touchDown(int screenX, int screenY, int pointer, int button){
|
Gdx.input.setCatchMenuKey(true);
|
||||||
unprojectTouch(screenX, screenY);
|
}
|
||||||
|
|
||||||
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown(%d, %d, %d, %d)", screenX, screenY, pointer, button));
|
@Override
|
||||||
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
|
public void onStateUnset(){
|
||||||
|
stateActive = false;
|
||||||
if(!startButton.isDisabled() && startButtonBBox.contains(touchPointWorldCoords)){
|
Gdx.input.setInputProcessor(null);
|
||||||
startButton.setChecked(true);
|
Gdx.input.setCatchBackKey(false);
|
||||||
startButtonTouched = true;
|
Gdx.input.setCatchMenuKey(false);
|
||||||
startButtonTouchPointer = pointer;
|
}
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button pressed.");
|
|
||||||
}
|
public void onClientConnected(){
|
||||||
|
clientConnected = true;
|
||||||
return true;
|
startButton.setDisabled(false);
|
||||||
}
|
calibrationButton.setDisabled(false);
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public boolean touchUp(int screenX, int screenY, int pointer, int button){
|
/*;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
unprojectTouch(screenX, screenY);
|
; INPUT LISTENER METHODS ;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
||||||
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp(%d, %d, %d, %d)", screenX, screenY, pointer, button));
|
|
||||||
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
|
@Override
|
||||||
|
public boolean touchDown(int screenX, int screenY, int pointer, int button){
|
||||||
if(!startButton.isDisabled() && startButtonBBox.contains(touchPointWorldCoords)){
|
unprojectTouch(screenX, screenY);
|
||||||
startButton.setChecked(false);
|
|
||||||
startButtonTouched = false;
|
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown(%d, %d, %d, %d)", screenX, screenY, pointer, button));
|
||||||
startButtonTouchPointer = -1;
|
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchDown() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
|
||||||
core.nextState = game_states_t.IN_GAME;
|
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button released.");
|
if(!startButton.isDisabled() && startButtonBBox.contains(touchPointWorldCoords) && !calibrationButtonTouched){
|
||||||
}
|
startButton.setChecked(true);
|
||||||
|
startButtonTouched = true;
|
||||||
return true;
|
startButtonTouchPointer = pointer;
|
||||||
}
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button pressed.");
|
||||||
|
}else if(!calibrationButton.isDisabled() && calibrationButtonBBox.contains(touchPointWorldCoords) && !startButtonTouched){
|
||||||
@Override
|
calibrationButton.setChecked(true);
|
||||||
public boolean touchDragged(int screenX, int screenY, int pointer){
|
calibrationButtonTouched = true;
|
||||||
unprojectTouch(screenX, screenY);
|
calibrationButtonTouchPointer = pointer;
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Calibration button pressed.");
|
||||||
if(!startButton.isDisabled() && startButtonTouched && pointer == startButtonTouchPointer && !startButtonBBox.contains(touchPointWorldCoords)){
|
}
|
||||||
startButtonTouchPointer = -1;
|
|
||||||
startButtonTouched = false;
|
return true;
|
||||||
startButton.setChecked(false);
|
}
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Start button released.");
|
|
||||||
}
|
@Override
|
||||||
|
public boolean touchUp(int screenX, int screenY, int pointer, int button){
|
||||||
return true;
|
unprojectTouch(screenX, screenY);
|
||||||
}
|
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp(%d, %d, %d, %d)", screenX, screenY, pointer, button));
|
||||||
@Override
|
Gdx.app.log(TAG, CLASS_NAME + String.format(".touchUp() :: Unprojected touch point: (%f, %f)", touchPointWorldCoords.x, touchPointWorldCoords.y));
|
||||||
public boolean keyDown(int keycode){
|
|
||||||
if(keycode == Input.Keys.BACK){
|
if(!startButton.isDisabled() && startButtonBBox.contains(touchPointWorldCoords) && startButtonTouched){
|
||||||
// Ignore.
|
startButton.setChecked(false);
|
||||||
return true;
|
startButtonTouched = false;
|
||||||
}
|
startButtonTouchPointer = -1;
|
||||||
return false;
|
core.nextState = game_states_t.IN_GAME;
|
||||||
}
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button released.");
|
||||||
|
}else if(!calibrationButton.isDisabled() && calibrationButtonBBox.contains(touchPointWorldCoords) && calibrationButtonTouched){
|
||||||
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
calibrationButton.setChecked(false);
|
||||||
; INPUT LISTENER METHOD STUBS ;
|
calibrationButtonTouched = false;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
calibrationButtonTouchPointer = -1;
|
||||||
|
core.nextState = game_states_t.CALIBRATION;
|
||||||
@Override
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Calibration button released.");
|
||||||
public boolean keyUp(int keycode){
|
}
|
||||||
return false;
|
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
@Override
|
|
||||||
public boolean keyTyped(char character){
|
@Override
|
||||||
return false;
|
public boolean touchDragged(int screenX, int screenY, int pointer){
|
||||||
}
|
unprojectTouch(screenX, screenY);
|
||||||
|
|
||||||
@Override
|
if(!startButton.isDisabled() && startButtonTouched && pointer == startButtonTouchPointer && !startButtonBBox.contains(touchPointWorldCoords)){
|
||||||
public boolean mouseMoved(int screenX, int screenY){
|
startButtonTouchPointer = -1;
|
||||||
return false;
|
startButtonTouched = false;
|
||||||
}
|
startButton.setChecked(false);
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Start button released.");
|
||||||
@Override
|
}else if(!calibrationButton.isDisabled() && calibrationButtonTouched && pointer == calibrationButtonTouchPointer && !calibrationButtonBBox.contains(touchPointWorldCoords)){
|
||||||
public boolean scrolled(int amount){
|
calibrationButtonTouchPointer = -1;
|
||||||
return false;
|
calibrationButtonTouched = false;
|
||||||
}
|
calibrationButton.setChecked(false);
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".touchDragged() :: Start button released.");
|
||||||
@Override
|
}
|
||||||
public void connected(Controller controller){ }
|
|
||||||
|
return true;
|
||||||
@Override
|
}
|
||||||
public void disconnected(Controller controller){ }
|
|
||||||
|
@Override
|
||||||
@Override
|
public boolean keyDown(int keycode){
|
||||||
public boolean buttonDown(Controller controller, int buttonCode){
|
if(keycode == Input.Keys.BACK){
|
||||||
return false;
|
// Ignore.
|
||||||
}
|
return true;
|
||||||
|
}
|
||||||
@Override
|
return false;
|
||||||
public boolean buttonUp(Controller controller, int buttonCode){
|
}
|
||||||
return false;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean axisMoved(Controller controller, int axisCode, float value){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean povMoved(Controller controller, int povCode, PovDirection value){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean xSliderMoved(Controller controller, int sliderCode, boolean value){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean ySliderMoved(Controller controller, int sliderCode, boolean value){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean accelerometerMoved(Controller controller, int accelerometerCode, Vector3 value){
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@@ -21,7 +21,7 @@ import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
|
|||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.controllers.Controller;
|
import com.badlogic.gdx.controllers.Controller;
|
||||||
import com.badlogic.gdx.controllers.mappings.Ouya;
|
import com.badlogic.gdx.controllers.mappings.Ouya;
|
||||||
import com.badlogic.gdx.graphics.GL10;
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
import com.badlogic.gdx.graphics.Texture;
|
import com.badlogic.gdx.graphics.Texture;
|
||||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||||
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
import com.badlogic.gdx.graphics.g2d.TextureRegion;
|
||||||
@@ -32,46 +32,66 @@ public class OuyaMainMenuState extends MainMenuStateBase{
|
|||||||
private Texture ouyaOButtonTexture;
|
private Texture ouyaOButtonTexture;
|
||||||
private Sprite ouyaOButton;
|
private Sprite ouyaOButton;
|
||||||
private boolean oButtonPressed;
|
private boolean oButtonPressed;
|
||||||
|
private int oButtonSelection;
|
||||||
|
|
||||||
public OuyaMainMenuState(final NxtARCore core){
|
public OuyaMainMenuState(final NxtARCore core){
|
||||||
|
super();
|
||||||
|
|
||||||
this.core = core;
|
this.core = core;
|
||||||
|
|
||||||
startButton.setPosition(-(startButton.getWidth() / 2), -(startButton.getHeight() / 2));
|
startButton.setPosition(-(startButton.getWidth() / 2), -(startButton.getHeight() / 2));
|
||||||
startButtonBBox.setPosition(startButton.getX(), startButton.getY());
|
startButtonBBox.setPosition(startButton.getX(), startButton.getY());
|
||||||
|
|
||||||
float ledYPos = (-(Gdx.graphics.getHeight() / 2) * 0.5f) + (startButton.getY() * 0.5f);
|
calibrationButton.setPosition(-(calibrationButton.getWidth() / 2), (startButton.getY() + startButton.getHeight()) + 10);
|
||||||
|
calibrationButtonBBox.setPosition(calibrationButton.getX(), calibrationButton.getY());
|
||||||
|
|
||||||
|
float ledYPos = (-(Gdx.graphics.getHeight() / 2) * 0.5f) + (calibrationButton.getY() * 0.5f);
|
||||||
clientConnectedLedOn.setSize(clientConnectedLedOn.getWidth() * 0.5f, clientConnectedLedOn.getHeight() * 0.5f);
|
clientConnectedLedOn.setSize(clientConnectedLedOn.getWidth() * 0.5f, clientConnectedLedOn.getHeight() * 0.5f);
|
||||||
clientConnectedLedOn.setPosition(-(clientConnectedLedOn.getWidth() / 2), ledYPos);
|
clientConnectedLedOn.setPosition(-(clientConnectedLedOn.getWidth() / 2), ledYPos);
|
||||||
|
|
||||||
clientConnectedLedOff.setSize(clientConnectedLedOff.getWidth() * 0.5f, clientConnectedLedOff.getHeight() * 0.5f);
|
clientConnectedLedOff.setSize(clientConnectedLedOff.getWidth() * 0.5f, clientConnectedLedOff.getHeight() * 0.5f);
|
||||||
clientConnectedLedOff.setPosition(-(clientConnectedLedOff.getWidth() / 2), ledYPos);
|
clientConnectedLedOff.setPosition(-(clientConnectedLedOff.getWidth() / 2), ledYPos);
|
||||||
|
|
||||||
|
// TODO: Set calibration led attributes.
|
||||||
|
|
||||||
ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png");
|
ouyaOButtonTexture = new Texture("data/gfx/gui/OUYA_O.png");
|
||||||
TextureRegion region = new TextureRegion(ouyaOButtonTexture, ouyaOButtonTexture.getWidth(), ouyaOButtonTexture.getHeight());
|
TextureRegion region = new TextureRegion(ouyaOButtonTexture, ouyaOButtonTexture.getWidth(), ouyaOButtonTexture.getHeight());
|
||||||
ouyaOButton = new Sprite(region);
|
ouyaOButton = new Sprite(region);
|
||||||
ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
|
ouyaOButton.setSize(ouyaOButton.getWidth() * 0.6f, ouyaOButton.getHeight() * 0.6f);
|
||||||
ouyaOButton.setPosition(startButton.getX() - ouyaOButton.getWidth() - 20, startButton.getY() + (ouyaOButton.getHeight() / 2));
|
|
||||||
|
|
||||||
|
oButtonSelection = 0;
|
||||||
oButtonPressed = false;
|
oButtonPressed = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(float delta) {
|
public void render(float delta) {
|
||||||
Gdx.gl.glClearColor(1, 1, 1, 1);
|
Gdx.gl.glClearColor(1, 1, 1, 1);
|
||||||
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
||||||
core.batch.begin();{
|
core.batch.begin();{
|
||||||
core.batch.disableBlending();
|
core.batch.disableBlending();
|
||||||
drawBackground(core.batch);
|
drawBackground(core.batch);
|
||||||
core.batch.enableBlending();
|
core.batch.enableBlending();
|
||||||
|
|
||||||
if(clientConnected){
|
if(clientConnected){
|
||||||
clientConnectedLedOn.draw(core.batch);
|
clientConnectedLedOn.draw(core.batch);
|
||||||
}else{
|
}else{
|
||||||
clientConnectedLedOff.draw(core.batch);
|
clientConnectedLedOff.draw(core.batch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Render calibration leds.
|
||||||
|
|
||||||
startButton.draw(core.batch, 1.0f);
|
startButton.draw(core.batch, 1.0f);
|
||||||
|
calibrationButton.draw(core.batch, 1.0f);
|
||||||
|
|
||||||
|
if(oButtonSelection == 0){
|
||||||
|
ouyaOButton.setPosition(startButton.getX() - ouyaOButton.getWidth() - 20, startButton.getY() + (ouyaOButton.getHeight() / 2));
|
||||||
|
}else if(oButtonSelection == 1){
|
||||||
|
ouyaOButton.setPosition(calibrationButton.getX() - ouyaOButton.getWidth() - 20, calibrationButton.getY() + (ouyaOButton.getHeight() / 2));
|
||||||
|
}
|
||||||
ouyaOButton.draw(core.batch);
|
ouyaOButton.draw(core.batch);
|
||||||
|
|
||||||
}core.batch.end();
|
}core.batch.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,38 +106,64 @@ public class OuyaMainMenuState extends MainMenuStateBase{
|
|||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean buttonDown(Controller controller, int buttonCode) {
|
public boolean buttonDown(Controller controller, int buttonCode){
|
||||||
|
// TODO: Test this.
|
||||||
|
|
||||||
if(stateActive){
|
if(stateActive){
|
||||||
if(buttonCode == Ouya.BUTTON_O){
|
if(buttonCode == Ouya.BUTTON_O){
|
||||||
if(!clientConnected){
|
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): O button pressed.");
|
||||||
core.toast("Can't start the game. No client is connected.", true);
|
|
||||||
}else{
|
if(oButtonSelection == 0){
|
||||||
oButtonPressed = true;
|
if(!clientConnected){
|
||||||
startButton.setChecked(true);
|
core.toast("Can't start the game. No client is connected.", true);
|
||||||
|
}else{
|
||||||
|
oButtonPressed = true;
|
||||||
|
startButton.setChecked(true);
|
||||||
|
}
|
||||||
|
}else if(oButtonSelection == 1){
|
||||||
|
if(!clientConnected){
|
||||||
|
core.toast("Can't calibrate the camera. No client is connected.", true);
|
||||||
|
}else{
|
||||||
|
oButtonPressed = true;
|
||||||
|
calibrationButton.setChecked(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
}else if(buttonCode == Ouya.BUTTON_DPAD_UP){
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad up button pressed.");
|
||||||
|
oButtonSelection = oButtonSelection - 1 < 0 ? NUM_MENU_BUTTONS - 1 : oButtonSelection - 1;
|
||||||
|
}else if(buttonCode == Ouya.BUTTON_DPAD_DOWN){
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): Dpad down button pressed.");
|
||||||
|
oButtonSelection = (oButtonSelection + 1) % NUM_MENU_BUTTONS;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean buttonUp(Controller controller, int buttonCode) {
|
public boolean buttonUp(Controller controller, int buttonCode){
|
||||||
|
// TODO: Test this.
|
||||||
|
|
||||||
if(stateActive){
|
if(stateActive){
|
||||||
if(buttonCode == Ouya.BUTTON_O){
|
if(buttonCode == Ouya.BUTTON_O){
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".buttonDown(): O button released.");
|
||||||
|
|
||||||
if(oButtonPressed){
|
if(oButtonPressed){
|
||||||
oButtonPressed = false;
|
oButtonPressed = false;
|
||||||
startButton.setChecked(false);
|
|
||||||
core.nextState = game_states_t.IN_GAME;
|
if(oButtonSelection == 0){
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".touchDown() :: Start button released.");
|
startButton.setChecked(false);
|
||||||
|
core.nextState = game_states_t.IN_GAME;
|
||||||
|
}else if(oButtonSelection == 1){
|
||||||
|
calibrationButton.setChecked(false);
|
||||||
|
core.nextState = game_states_t.IN_GAME;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}else{
|
}else{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -18,29 +18,39 @@ package ve.ucv.ciens.ccg.nxtar.states;
|
|||||||
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
|
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
|
||||||
|
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.GL10;
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
|
|
||||||
public class TabletMainMenuState extends MainMenuStateBase{
|
public class TabletMainMenuState extends MainMenuStateBase{
|
||||||
|
|
||||||
public TabletMainMenuState(final NxtARCore core){
|
public TabletMainMenuState(final NxtARCore core){
|
||||||
|
super();
|
||||||
|
|
||||||
this.core = core;
|
this.core = core;
|
||||||
|
|
||||||
startButton.setPosition(-(startButton.getWidth() / 2), -(startButton.getHeight() / 2));
|
startButton.setPosition(-(startButton.getWidth() / 2), -(startButton.getHeight() / 2));
|
||||||
startButtonBBox.setPosition(startButton.getX(), startButton.getY());
|
startButtonBBox.setPosition(startButton.getX(), startButton.getY());
|
||||||
|
|
||||||
float ledYPos = (-(Gdx.graphics.getHeight() / 2) * 0.5f) + (startButton.getY() * 0.5f);
|
calibrationButton.setPosition(-(calibrationButton.getWidth() / 2), (startButton.getY() + startButton.getHeight()) + 10);
|
||||||
|
calibrationButtonBBox.setPosition(calibrationButton.getX(), calibrationButton.getY());
|
||||||
|
|
||||||
|
float ledYPos = (-(Gdx.graphics.getHeight() / 2) * 0.5f) + (calibrationButton.getY() * 0.5f);
|
||||||
clientConnectedLedOn.setSize(clientConnectedLedOn.getWidth() * 0.5f, clientConnectedLedOn.getHeight() * 0.5f);
|
clientConnectedLedOn.setSize(clientConnectedLedOn.getWidth() * 0.5f, clientConnectedLedOn.getHeight() * 0.5f);
|
||||||
clientConnectedLedOn.setPosition(-(clientConnectedLedOn.getWidth() / 2), ledYPos);
|
clientConnectedLedOn.setPosition(-(clientConnectedLedOn.getWidth() / 2), ledYPos);
|
||||||
|
|
||||||
clientConnectedLedOff.setSize(clientConnectedLedOff.getWidth() * 0.5f, clientConnectedLedOff.getHeight() * 0.5f);
|
clientConnectedLedOff.setSize(clientConnectedLedOff.getWidth() * 0.5f, clientConnectedLedOff.getHeight() * 0.5f);
|
||||||
clientConnectedLedOff.setPosition(-(clientConnectedLedOff.getWidth() / 2), ledYPos);
|
clientConnectedLedOff.setPosition(-(clientConnectedLedOff.getWidth() / 2), ledYPos);
|
||||||
|
|
||||||
|
// TODO: Set calibration led attributes.
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(float delta){
|
public void render(float delta){
|
||||||
Gdx.gl.glClearColor(1, 1, 1, 1);
|
Gdx.gl.glClearColor(1, 1, 1, 1);
|
||||||
Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
|
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||||
|
|
||||||
core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
core.batch.setProjectionMatrix(pixelPerfectCamera.combined);
|
||||||
core.batch.begin();{
|
core.batch.begin();{
|
||||||
|
|
||||||
core.batch.disableBlending();
|
core.batch.disableBlending();
|
||||||
drawBackground(core.batch);
|
drawBackground(core.batch);
|
||||||
core.batch.enableBlending();
|
core.batch.enableBlending();
|
||||||
@@ -50,7 +60,12 @@ public class TabletMainMenuState extends MainMenuStateBase{
|
|||||||
}else{
|
}else{
|
||||||
clientConnectedLedOff.draw(core.batch);
|
clientConnectedLedOff.draw(core.batch);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Render calibration led.
|
||||||
|
|
||||||
startButton.draw(core.batch, 1.0f);
|
startButton.draw(core.batch, 1.0f);
|
||||||
|
calibrationButton.draw(core.batch, 1.0f);
|
||||||
|
|
||||||
}core.batch.end();
|
}core.batch.end();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
49
src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java
Normal file
49
src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.systems;
|
||||||
|
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent;
|
||||||
|
|
||||||
|
import com.artemis.Aspect;
|
||||||
|
import com.artemis.ComponentMapper;
|
||||||
|
import com.artemis.Entity;
|
||||||
|
import com.artemis.annotations.Mapper;
|
||||||
|
import com.artemis.systems.EntityProcessingSystem;
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
|
||||||
|
public class AnimationSystem extends EntityProcessingSystem {
|
||||||
|
@Mapper ComponentMapper<AnimationComponent> animationMapper;
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public AnimationSystem(){
|
||||||
|
super(Aspect.getAspectForAll(AnimationComponent.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void process(Entity e) {
|
||||||
|
AnimationComponent animation = animationMapper.get(e);
|
||||||
|
|
||||||
|
if(animation.current != animation.next && animation.next >= 0 && animation.next < animation.animationsIds.size()){
|
||||||
|
if(animation.loop)
|
||||||
|
animation.controller.setAnimation(animation.animationsIds.get(animation.next), -1);
|
||||||
|
else
|
||||||
|
animation.controller.setAnimation(animation.animationsIds.get(animation.next));
|
||||||
|
}
|
||||||
|
|
||||||
|
animation.controller.update(Gdx.graphics.getDeltaTime());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.systems;
|
||||||
|
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.ModelComponent;
|
||||||
|
|
||||||
|
import com.artemis.Aspect;
|
||||||
|
import com.artemis.Entity;
|
||||||
|
import com.artemis.systems.EntityProcessingSystem;
|
||||||
|
|
||||||
|
public class CollisionDetectionSystem extends EntityProcessingSystem {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public CollisionDetectionSystem(){
|
||||||
|
super(Aspect.getAspectForAll(ModelComponent.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void process(Entity e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.systems;
|
||||||
|
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||||
|
|
||||||
|
import com.artemis.Aspect;
|
||||||
|
import com.artemis.ComponentMapper;
|
||||||
|
import com.artemis.Entity;
|
||||||
|
import com.artemis.annotations.Mapper;
|
||||||
|
import com.artemis.systems.EntityProcessingSystem;
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
|
||||||
|
public class MarkerPositioningSystem extends EntityProcessingSystem {
|
||||||
|
@Mapper ComponentMapper<MarkerCodeComponent> markerMapper;
|
||||||
|
@Mapper ComponentMapper<GeometryComponent> geometryMapper;
|
||||||
|
|
||||||
|
private static final String TAG = "MARKER_POSITIONING_SYSTEM";
|
||||||
|
private static final String CLASS_NAME = MarkerPositioningSystem.class.getSimpleName();
|
||||||
|
|
||||||
|
private MarkerData markers;
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public MarkerPositioningSystem(){
|
||||||
|
super(Aspect.getAspectForAll(MarkerCodeComponent.class, GeometryComponent.class));
|
||||||
|
|
||||||
|
markers = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMarkerData(MarkerData markers){
|
||||||
|
this.markers = markers;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void process(Entity e) {
|
||||||
|
MarkerCodeComponent marker;
|
||||||
|
GeometryComponent geometry;
|
||||||
|
|
||||||
|
if(markers == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".process(): Getting components.");
|
||||||
|
marker = markerMapper.get(e);
|
||||||
|
geometry = geometryMapper.get(e);
|
||||||
|
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".process(): Processing markers.");
|
||||||
|
for(int i = 0; i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){
|
||||||
|
if(markers.markerCodes[i] != 1){
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".process(): Checking marker code: " + Integer.toString(markers.markerCodes[i]));
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".process(): This entity's code is: " + Integer.toString(marker.code));
|
||||||
|
if(markers.markerCodes[i] == marker.code){
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".process(): Processing marker code " + Integer.toString(markers.markerCodes[i]) + ".");
|
||||||
|
geometry.position.set(markers.translationVectors[i]);
|
||||||
|
geometry.rotation.set(markers.rotationMatrices[i]);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".process(): Skipping marker number " + Integer.toString(i) + ".");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
158
src/ve/ucv/ciens/ccg/nxtar/systems/MarkerRenderingSystem.java
Normal file
158
src/ve/ucv/ciens/ccg/nxtar/systems/MarkerRenderingSystem.java
Normal file
@@ -0,0 +1,158 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.systems;
|
||||||
|
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.ModelComponent;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||||
|
|
||||||
|
import com.artemis.Aspect;
|
||||||
|
import com.artemis.ComponentMapper;
|
||||||
|
import com.artemis.Entity;
|
||||||
|
import com.artemis.annotations.Mapper;
|
||||||
|
import com.artemis.systems.EntityProcessingSystem;
|
||||||
|
import com.badlogic.gdx.Gdx;
|
||||||
|
import com.badlogic.gdx.graphics.PerspectiveCamera;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.ModelBatch;
|
||||||
|
import com.badlogic.gdx.math.Matrix4;
|
||||||
|
|
||||||
|
public class MarkerRenderingSystem extends EntityProcessingSystem {
|
||||||
|
@Mapper ComponentMapper<MarkerCodeComponent> markerMapper;
|
||||||
|
@Mapper ComponentMapper<GeometryComponent> geometryMapper;
|
||||||
|
@Mapper ComponentMapper<ModelComponent> modelMapper;
|
||||||
|
@Mapper ComponentMapper<EnvironmentComponent> environmentMapper;
|
||||||
|
@Mapper ComponentMapper<ShaderComponent> shaderMapper;
|
||||||
|
|
||||||
|
private static final String TAG = "MODEL_BATCH_MARKER_RENDERING_SYSTEM";
|
||||||
|
private static final String CLASS_NAME = MarkerRenderingSystem.class.getSimpleName();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>A matrix representing 3D translations.</p>
|
||||||
|
*/
|
||||||
|
private Matrix4 translationMatrix;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>A matrix representing 3D rotations.</p>
|
||||||
|
*/
|
||||||
|
private Matrix4 rotationMatrix;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>A matrix representing 3D scalings.</p>
|
||||||
|
*/
|
||||||
|
private Matrix4 scalingMatrix;
|
||||||
|
|
||||||
|
private MarkerData markers;
|
||||||
|
|
||||||
|
private PerspectiveCamera camera;
|
||||||
|
|
||||||
|
private ModelBatch batch;
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public MarkerRenderingSystem(ModelBatch batch){
|
||||||
|
super(Aspect.getAspectForAll(MarkerCodeComponent.class, GeometryComponent.class, ShaderComponent.class, EnvironmentComponent.class, ModelComponent.class));
|
||||||
|
|
||||||
|
markers = null;
|
||||||
|
camera = null;
|
||||||
|
this.batch = batch;
|
||||||
|
translationMatrix = new Matrix4().setToTranslation(0.0f, 0.0f, 0.0f);
|
||||||
|
rotationMatrix = new Matrix4().idt();
|
||||||
|
scalingMatrix = new Matrix4().setToScaling(0.0f, 0.0f, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void begin(PerspectiveCamera camera, MarkerData markers) throws RuntimeException{
|
||||||
|
if(this.camera != null)
|
||||||
|
throw new RuntimeException("Begin called twice without calling end.");
|
||||||
|
|
||||||
|
if(this.markers != null)
|
||||||
|
throw new RuntimeException("Begin called twice without calling end.");
|
||||||
|
|
||||||
|
this.markers = markers;
|
||||||
|
this.camera = camera;
|
||||||
|
batch.begin(camera);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void end(){
|
||||||
|
batch.end();
|
||||||
|
camera = null;
|
||||||
|
markers = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void process(Entity e) {
|
||||||
|
MarkerCodeComponent marker;
|
||||||
|
GeometryComponent geometry;
|
||||||
|
EnvironmentComponent environment;
|
||||||
|
ModelComponent model;
|
||||||
|
ShaderComponent shader;
|
||||||
|
|
||||||
|
if(markers == null || camera == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".process(): Getting components.");
|
||||||
|
marker = markerMapper.get(e);
|
||||||
|
geometry = geometryMapper.get(e);
|
||||||
|
model = modelMapper.get(e);
|
||||||
|
environment = environmentMapper.get(e);
|
||||||
|
shader = shaderMapper.get(e);
|
||||||
|
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".process(): Processing markers.");
|
||||||
|
for(int i = 0; i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){
|
||||||
|
if(markers.markerCodes[i] != 1){
|
||||||
|
if(markers.markerCodes[i] == marker.code){
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".process(): Rendering marker code " + Integer.toString(markers.markerCodes[i]) + ".");
|
||||||
|
// Set the geometric transformations.
|
||||||
|
translationMatrix.setToTranslation(geometry.position);
|
||||||
|
|
||||||
|
rotationMatrix.val[Matrix4.M00] = geometry.rotation.val[0];
|
||||||
|
rotationMatrix.val[Matrix4.M10] = geometry.rotation.val[1];
|
||||||
|
rotationMatrix.val[Matrix4.M20] = geometry.rotation.val[2];
|
||||||
|
rotationMatrix.val[Matrix4.M30] = 0;
|
||||||
|
|
||||||
|
rotationMatrix.val[Matrix4.M01] = geometry.rotation.val[3];
|
||||||
|
rotationMatrix.val[Matrix4.M11] = geometry.rotation.val[4];
|
||||||
|
rotationMatrix.val[Matrix4.M21] = geometry.rotation.val[5];
|
||||||
|
rotationMatrix.val[Matrix4.M31] = 0;
|
||||||
|
|
||||||
|
rotationMatrix.val[Matrix4.M02] = geometry.rotation.val[6];
|
||||||
|
rotationMatrix.val[Matrix4.M12] = geometry.rotation.val[7];
|
||||||
|
rotationMatrix.val[Matrix4.M22] = geometry.rotation.val[8];
|
||||||
|
rotationMatrix.val[Matrix4.M32] = 0;
|
||||||
|
|
||||||
|
rotationMatrix.val[Matrix4.M03] = 0;
|
||||||
|
rotationMatrix.val[Matrix4.M13] = 0;
|
||||||
|
rotationMatrix.val[Matrix4.M23] = 0;
|
||||||
|
rotationMatrix.val[Matrix4.M33] = 1;
|
||||||
|
|
||||||
|
scalingMatrix.setToScaling(geometry.scaling);
|
||||||
|
|
||||||
|
// Apply the geometric transformations to the model.
|
||||||
|
model.instance.transform.idt().mul(translationMatrix).mul(rotationMatrix).mul(scalingMatrix);
|
||||||
|
model.instance.calculateTransforms();
|
||||||
|
|
||||||
|
// Render the marker;
|
||||||
|
batch.render(model.instance, environment.environment, shader.shader);
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
Gdx.app.log(TAG, CLASS_NAME + ".process(): Skipping marker number " + Integer.toString(i) + ".");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
115
src/ve/ucv/ciens/ccg/nxtar/systems/ObjectRenderingSystem.java
Normal file
115
src/ve/ucv/ciens/ccg/nxtar/systems/ObjectRenderingSystem.java
Normal file
@@ -0,0 +1,115 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (C) 2014 Miguel Angel Astor Romero
|
||||||
|
*
|
||||||
|
* 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 ve.ucv.ciens.ccg.nxtar.systems;
|
||||||
|
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.ModelComponent;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
|
||||||
|
|
||||||
|
import com.artemis.Aspect;
|
||||||
|
import com.artemis.ComponentMapper;
|
||||||
|
import com.artemis.Entity;
|
||||||
|
import com.artemis.annotations.Mapper;
|
||||||
|
import com.artemis.systems.EntityProcessingSystem;
|
||||||
|
import com.badlogic.gdx.graphics.PerspectiveCamera;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.ModelBatch;
|
||||||
|
import com.badlogic.gdx.math.Matrix4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Entity processing system in charge of rendering 3D objects using OpenGL. The
|
||||||
|
* entities to be rendered must have a geometry, shader and mesh component associated.</p>
|
||||||
|
*/
|
||||||
|
public class ObjectRenderingSystem extends EntityProcessingSystem {
|
||||||
|
@Mapper ComponentMapper<GeometryComponent> geometryMapper;
|
||||||
|
@Mapper ComponentMapper<ShaderComponent> shaderMapper;
|
||||||
|
@Mapper ComponentMapper<ModelComponent> modelMapper;
|
||||||
|
@Mapper ComponentMapper<EnvironmentComponent> environmentMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>A matrix representing 3D translations.</p>
|
||||||
|
*/
|
||||||
|
private Matrix4 translationMatrix;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>A matrix representing 3D rotations.</p>
|
||||||
|
*/
|
||||||
|
private Matrix4 rotationMatrix;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>A matrix representing 3D scalings.</p>
|
||||||
|
*/
|
||||||
|
private Matrix4 scalingMatrix;
|
||||||
|
|
||||||
|
private PerspectiveCamera camera;
|
||||||
|
|
||||||
|
private ModelBatch batch;
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public ObjectRenderingSystem(ModelBatch batch) {
|
||||||
|
super(Aspect.getAspectForAll(GeometryComponent.class, ShaderComponent.class, ModelComponent.class, EnvironmentComponent.class).exclude(MarkerCodeComponent.class));
|
||||||
|
|
||||||
|
camera = null;
|
||||||
|
this.batch = batch;
|
||||||
|
translationMatrix = new Matrix4().setToTranslation(0.0f, 0.0f, 0.0f);
|
||||||
|
rotationMatrix = new Matrix4().idt();
|
||||||
|
scalingMatrix = new Matrix4().setToScaling(0.0f, 0.0f, 0.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void begin(PerspectiveCamera camera) throws RuntimeException{
|
||||||
|
if(this.camera != null)
|
||||||
|
throw new RuntimeException("Begin called twice without calling end.");
|
||||||
|
|
||||||
|
this.camera = camera;
|
||||||
|
batch.begin(camera);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void end(){
|
||||||
|
batch.end();
|
||||||
|
camera = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Renders the entity passed by parameter, calculating it's corresponding geometric
|
||||||
|
* transformation and setting and calling it's associated shader program.</p>
|
||||||
|
*
|
||||||
|
* @param e The entity to be processed.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected void process(Entity e) {
|
||||||
|
EnvironmentComponent environment;
|
||||||
|
GeometryComponent geometryComponent;
|
||||||
|
ShaderComponent shaderComponent;
|
||||||
|
ModelComponent modelComponent;
|
||||||
|
|
||||||
|
// Get the necessary components.
|
||||||
|
geometryComponent = geometryMapper.get(e);
|
||||||
|
modelComponent = modelMapper.get(e);
|
||||||
|
shaderComponent = shaderMapper.get(e);
|
||||||
|
environment = environmentMapper.get(e);
|
||||||
|
|
||||||
|
// Calculate the geometric transformation for this entity.
|
||||||
|
translationMatrix.setToTranslation(geometryComponent.position);
|
||||||
|
rotationMatrix.set(geometryComponent.rotation);
|
||||||
|
scalingMatrix.setToScaling(geometryComponent.scaling);
|
||||||
|
modelComponent.instance.transform.idt().mul(translationMatrix).mul(rotationMatrix).mul(scalingMatrix);
|
||||||
|
modelComponent.instance.calculateTransforms();
|
||||||
|
|
||||||
|
// Render this entity.
|
||||||
|
batch.render(modelComponent.instance, environment.environment, shaderComponent.shader);
|
||||||
|
}
|
||||||
|
}
|
@@ -18,26 +18,30 @@ package ve.ucv.ciens.ccg.nxtar.utils;
|
|||||||
import com.badlogic.gdx.controllers.mappings.Ouya;
|
import com.badlogic.gdx.controllers.mappings.Ouya;
|
||||||
|
|
||||||
public abstract class ProjectConstants{
|
public abstract class ProjectConstants{
|
||||||
public static final int SERVICE_DISCOVERY_PORT = 9988;
|
public static final int SERVICE_DISCOVERY_PORT = 9988;
|
||||||
public static final int VIDEO_STREAMING_PORT = 9989;
|
public static final int VIDEO_STREAMING_PORT = 9989;
|
||||||
public static final int MOTOR_CONTROL_PORT = 9990;
|
public static final int MOTOR_CONTROL_PORT = 9990;
|
||||||
public static final int SENSOR_REPORT_PORT = 9991;
|
public static final int SENSOR_REPORT_PORT = 9991;
|
||||||
public static final int APP_CONTROL_PORT = 9992;
|
public static final int APP_CONTROL_PORT = 9992;
|
||||||
|
public static final String MULTICAST_ADDRESS = "230.0.0.1";
|
||||||
|
|
||||||
public static final String MULTICAST_ADDRESS = "230.0.0.1";
|
public static final int EXIT_SUCCESS = 0;
|
||||||
|
public static final int EXIT_FAILURE = 1;
|
||||||
|
|
||||||
public static final int EXIT_SUCCESS = 0;
|
public static final boolean DEBUG = true;
|
||||||
public static final int EXIT_FAILURE = 1;
|
|
||||||
|
|
||||||
public static final boolean DEBUG = true;
|
public static final int[] POWERS_OF_2 = {64, 128, 256, 512, 1024, 2048};
|
||||||
|
|
||||||
public static final int[] POWERS_OF_2 = {64, 128, 256, 512, 1024, 2048};
|
public static final float OVERSCAN;
|
||||||
|
public static final int MENU_BUTTON_FONT_SIZE;
|
||||||
|
public static final String FONT_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
|
||||||
|
|
||||||
public static final float OVERSCAN;
|
public static final int MAXIMUM_NUMBER_OF_MARKERS = 5;
|
||||||
|
public static final int CALIBRATION_PATTERN_POINTS = 54;
|
||||||
public static final String FONT_CHARS = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
|
public static final int CALIBRATION_SAMPLES = 10;
|
||||||
|
|
||||||
static{
|
static{
|
||||||
OVERSCAN = Ouya.runningOnOuya ? 0.9f : 1.0f;
|
OVERSCAN = Ouya.runningOnOuya ? 0.9f : 1.0f;
|
||||||
|
MENU_BUTTON_FONT_SIZE = Ouya.runningOnOuya ? 60 : 40;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user