Added comments.
This commit is contained in:
@@ -16,7 +16,7 @@
|
|||||||
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.CVProcessor;
|
||||||
import ve.ucv.ciens.ccg.nxtar.interfaces.NetworkConnectionListener;
|
import ve.ucv.ciens.ccg.nxtar.interfaces.ApplicationEventsListener;
|
||||||
import ve.ucv.ciens.ccg.nxtar.interfaces.OSFunctionalityProvider;
|
import ve.ucv.ciens.ccg.nxtar.interfaces.OSFunctionalityProvider;
|
||||||
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;
|
||||||
@@ -57,10 +57,16 @@ import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
|||||||
* <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();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -96,30 +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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>The OpenCV wrapper.</p>
|
||||||
|
*/
|
||||||
public CVProcessor cvProc;
|
public CVProcessor cvProc;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <p>Wrapper around the Operating System methods.</p>
|
||||||
|
*/
|
||||||
private OSFunctionalityProvider osFunction;
|
private OSFunctionalityProvider 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -127,7 +201,10 @@ 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.osFunction = (OSFunctionalityProvider)concreteApp;
|
this.osFunction = (OSFunctionalityProvider)concreteApp;
|
||||||
}catch(ClassCastException cc){
|
}catch(ClassCastException cc){
|
||||||
@@ -143,6 +220,14 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
; 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[game_states_t.getNumStates()];
|
states = new BaseState[game_states_t.getNumStates()];
|
||||||
@@ -154,6 +239,7 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
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);
|
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);
|
||||||
}
|
}
|
||||||
@@ -169,8 +255,8 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
|
|
||||||
// Set up the overlay font.
|
// Set up the overlay font.
|
||||||
if(ProjectConstants.DEBUG){
|
if(ProjectConstants.DEBUG){
|
||||||
fontX = -((Gdx.graphics.getWidth() * ProjectConstants.OVERSCAN) / 2) + 10;
|
overlayX = -((Gdx.graphics.getWidth() * ProjectConstants.OVERSCAN) / 2) + 10;
|
||||||
fontY = ((Gdx.graphics.getHeight() * ProjectConstants.OVERSCAN) / 2) - 10;
|
overlayY = ((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);
|
||||||
@@ -190,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();
|
||||||
@@ -208,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();
|
||||||
@@ -233,6 +320,10 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <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();
|
||||||
|
|
||||||
@@ -241,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);
|
||||||
@@ -264,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();{
|
||||||
@@ -283,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();
|
||||||
@@ -323,9 +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: Disable start game button until camera has been sucessfully calibrated.
|
||||||
// TODO: Add calibration listener callback.
|
// 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.");
|
||||||
@@ -340,6 +463,16 @@ public class NxtARCore extends Game implements NetworkConnectionListener{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*;;;;;;;;;;;;;;;;;;
|
||||||
|
; 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(osFunction != null){
|
if(osFunction != null){
|
||||||
if(longToast) osFunction.showLongToast(msg);
|
if(longToast) osFunction.showLongToast(msg);
|
||||||
|
|||||||
110
src/ve/ucv/ciens/ccg/nxtar/graphics/LightSource.java
Normal file
110
src/ve/ucv/ciens/ccg/nxtar/graphics/LightSource.java
Normal file
@@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
* 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 point or directional light source.</p>
|
||||||
|
*/
|
||||||
|
public class LightSource{
|
||||||
|
private Vector3 position;
|
||||||
|
private Color ambientColor;
|
||||||
|
private Color diffuseColor;
|
||||||
|
private Color specularColor;
|
||||||
|
private float shinyness;
|
||||||
|
|
||||||
|
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);
|
||||||
|
ambientColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
shinyness = 10.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LightSource(Vector3 position){
|
||||||
|
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);
|
||||||
|
ambientColor = new Color(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
shinyness = 10.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LightSource(Vector3 position, Color ambientColor, Color diffuseColor, Color specularColor, float shinyness){
|
||||||
|
this.position.set(position);
|
||||||
|
this.ambientColor.set(ambientColor);
|
||||||
|
this.diffuseColor.set(diffuseColor);
|
||||||
|
this.specularColor.set(specularColor);
|
||||||
|
this.shinyness = 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){
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
}
|
}
|
||||||
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -26,40 +26,48 @@ import com.badlogic.gdx.graphics.OrthographicCamera;
|
|||||||
import com.badlogic.gdx.math.Vector2;
|
import com.badlogic.gdx.math.Vector2;
|
||||||
import com.badlogic.gdx.math.Vector3;
|
import com.badlogic.gdx.math.Vector3;
|
||||||
|
|
||||||
public abstract class BaseState implements Screen, ControllerListener, InputProcessor {
|
public abstract class BaseState implements Screen, ControllerListener, InputProcessor{
|
||||||
protected NxtARCore core;
|
protected NxtARCore core;
|
||||||
protected boolean stateActive;
|
protected boolean stateActive;
|
||||||
protected OrthographicCamera pixelPerfectCamera;
|
protected OrthographicCamera pixelPerfectCamera;
|
||||||
protected Vector3 win2world;
|
protected Vector3 win2world;
|
||||||
protected Vector2 touchPointWorldCoords;
|
protected Vector2 touchPointWorldCoords;
|
||||||
|
|
||||||
/* STATE METHODS */
|
/*;;;;;;;;;;;;;;;;;
|
||||||
|
; STATE METHODS ;
|
||||||
|
;;;;;;;;;;;;;;;;;*/
|
||||||
|
|
||||||
public abstract void onStateSet();
|
public abstract void onStateSet();
|
||||||
public abstract void onStateUnset();
|
public abstract void onStateUnset();
|
||||||
|
|
||||||
/* SCREEN METHODS*/
|
/*;;;;;;;;;;;;;;;;;;
|
||||||
|
; SCREEN METHODS ;
|
||||||
|
;;;;;;;;;;;;;;;;;;*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract void render(float delta);
|
public abstract void render(float delta);
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract void resize(int width, int height);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract void show();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract void hide();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract void pause();
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public abstract void resume();
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract void dispose();
|
public abstract void dispose();
|
||||||
|
|
||||||
/* HELPER METHODS */
|
@Override
|
||||||
|
public void resize(int width, int height){ }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void show(){ }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void hide(){ }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void pause(){ }
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void resume(){ }
|
||||||
|
|
||||||
|
/*;;;;;;;;;;;;;;;;;;
|
||||||
|
; HELPER METHODS ;
|
||||||
|
;;;;;;;;;;;;;;;;;;*/
|
||||||
|
|
||||||
protected final void unprojectTouch(int screenX, int screenY){
|
protected final void unprojectTouch(int screenX, int screenY){
|
||||||
win2world.set(screenX, screenY, 0.0f);
|
win2world.set(screenX, screenY, 0.0f);
|
||||||
@@ -67,7 +75,10 @@ public abstract class BaseState implements Screen, ControllerListener, InputProc
|
|||||||
touchPointWorldCoords.set(win2world.x, win2world.y);
|
touchPointWorldCoords.set(win2world.x, win2world.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* INPUT PROCESSOR METHODS. */
|
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
; INPUT PROCESSOR METHODS ;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean keyDown(int keycode){
|
public boolean keyDown(int keycode){
|
||||||
return false;
|
return false;
|
||||||
@@ -108,7 +119,10 @@ public abstract class BaseState implements Screen, ControllerListener, InputProc
|
|||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* CONTROLLER LISTENER METHODS. */
|
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
; CONTROLLER LISTENER METHODS ;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connected(Controller controller){ };
|
public void connected(Controller controller){ };
|
||||||
|
|
||||||
|
|||||||
@@ -54,8 +54,6 @@ public class InGameState extends BaseState{
|
|||||||
private static final String CLASS_NAME = InGameState.class.getSimpleName();
|
private static final String CLASS_NAME = InGameState.class.getSimpleName();
|
||||||
private static final String BACKGROUND_SHADER_PATH = "shaders/bckg/bckg";
|
private static final String BACKGROUND_SHADER_PATH = "shaders/bckg/bckg";
|
||||||
|
|
||||||
private NxtARCore core;
|
|
||||||
|
|
||||||
// Background related fields.
|
// Background related fields.
|
||||||
private float uScaling[];
|
private float uScaling[];
|
||||||
protected Sprite background;
|
protected Sprite background;
|
||||||
@@ -188,8 +186,13 @@ public class InGameState extends BaseState{
|
|||||||
// Set up Artemis.
|
// Set up Artemis.
|
||||||
gameWorld = new World();
|
gameWorld = new World();
|
||||||
// TODO: Create entities and systems.
|
// TODO: Create entities and systems.
|
||||||
|
gameWorld.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*;;;;;;;;;;;;;;;;;;;;;;
|
||||||
|
; BASE STATE METHODS ;
|
||||||
|
;;;;;;;;;;;;;;;;;;;;;;*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void render(float delta){
|
public void render(float delta){
|
||||||
int w, h;
|
int w, h;
|
||||||
@@ -341,21 +344,6 @@ public class InGameState extends BaseState{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@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
|
@Override
|
||||||
public void dispose(){
|
public void dispose(){
|
||||||
if(videoFrameTexture != null)
|
if(videoFrameTexture != null)
|
||||||
@@ -441,9 +429,9 @@ public class InGameState extends BaseState{
|
|||||||
headC.setPosition(-(headC.getWidth() / 2), headA.getY() - headA.getHeight() - 10);
|
headC.setPosition(-(headC.getWidth() / 2), headA.getY() - headA.getHeight() - 10);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
; BEGIN INPUT PROCESSOR METHODS ;
|
; INPUT PROCESSOR METHODS ;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean touchDown(int screenX, int screenY, int pointer, int button){
|
public boolean touchDown(int screenX, int screenY, int pointer, int button){
|
||||||
@@ -774,9 +762,9 @@ public class InGameState extends BaseState{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
; BEGIN CONTROLLER LISTENER METHODS ;
|
; CONTROLLER LISTENER METHODS ;
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean buttonDown(Controller controller, int buttonCode){
|
public boolean buttonDown(Controller controller, int buttonCode){
|
||||||
|
|||||||
Reference in New Issue
Block a user