Refactored rendering to use modelbatch everywhere.
This commit is contained in:
@@ -17,7 +17,7 @@ package ve.ucv.ciens.ccg.nxtar;
|
|||||||
|
|
||||||
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor;
|
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor;
|
||||||
import ve.ucv.ciens.ccg.nxtar.interfaces.ApplicationEventsListener;
|
import ve.ucv.ciens.ccg.nxtar.interfaces.ApplicationEventsListener;
|
||||||
import ve.ucv.ciens.ccg.nxtar.interfaces.AndroidFunctionalityWrapper;
|
import ve.ucv.ciens.ccg.nxtar.interfaces.ActionResolver;
|
||||||
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;
|
||||||
@@ -121,7 +121,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
|
|||||||
/**
|
/**
|
||||||
* <p>Wrapper around the Operating System methods.</p>
|
* <p>Wrapper around the Operating System methods.</p>
|
||||||
*/
|
*/
|
||||||
private AndroidFunctionalityWrapper osFunction;
|
private ActionResolver osFunction;
|
||||||
|
|
||||||
// Networking related fields.
|
// Networking related fields.
|
||||||
/**
|
/**
|
||||||
@@ -206,7 +206,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
|
|||||||
|
|
||||||
// Check if the concrete application implements all required interfaces.
|
// Check if the concrete application implements all required interfaces.
|
||||||
try{
|
try{
|
||||||
this.osFunction = (AndroidFunctionalityWrapper)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.osFunction = null;
|
this.osFunction = null;
|
||||||
|
@@ -15,32 +15,27 @@
|
|||||||
*/
|
*/
|
||||||
package ve.ucv.ciens.ccg.nxtar.entities;
|
package ve.ucv.ciens.ccg.nxtar.entities;
|
||||||
|
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.CustomShaderComponent;
|
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
|
import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
|
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
|
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.MeshComponent;
|
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.ModelComponent;
|
import ve.ucv.ciens.ccg.nxtar.components.ModelComponent;
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
|
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
|
||||||
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.SingleLightPerPixelShader;
|
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.SingleLightPerPixelShader;
|
||||||
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.SingleLightPhongShader;
|
|
||||||
|
|
||||||
import com.artemis.Entity;
|
import com.artemis.Entity;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.Color;
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
|
||||||
import com.badlogic.gdx.graphics.Mesh;
|
|
||||||
import com.badlogic.gdx.graphics.VertexAttribute;
|
import com.badlogic.gdx.graphics.VertexAttribute;
|
||||||
import com.badlogic.gdx.graphics.VertexAttributes;
|
import com.badlogic.gdx.graphics.VertexAttributes;
|
||||||
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
|
import com.badlogic.gdx.graphics.VertexAttributes.Usage;
|
||||||
import com.badlogic.gdx.graphics.g3d.Environment;
|
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.Model;
|
||||||
import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
|
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.environment.DirectionalLight;
|
||||||
import com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader;
|
import com.badlogic.gdx.graphics.g3d.loader.G3dModelLoader;
|
||||||
import com.badlogic.gdx.graphics.g3d.utils.MeshBuilder;
|
import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder;
|
||||||
import com.badlogic.gdx.math.Matrix3;
|
import com.badlogic.gdx.math.Matrix3;
|
||||||
import com.badlogic.gdx.math.Vector3;
|
import com.badlogic.gdx.math.Vector3;
|
||||||
import com.badlogic.gdx.utils.JsonReader;
|
import com.badlogic.gdx.utils.JsonReader;
|
||||||
@@ -49,101 +44,71 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
|
|||||||
private static final String TAG = "MARKER_TEST_ENTITY_CREATOR";
|
private static final String TAG = "MARKER_TEST_ENTITY_CREATOR";
|
||||||
private static final String CLASS_NAME = MarkerTestEntityCreator.class.getSimpleName();
|
private static final String CLASS_NAME = MarkerTestEntityCreator.class.getSimpleName();
|
||||||
|
|
||||||
private Mesh sphereMesh;
|
|
||||||
private Mesh boxMesh;
|
|
||||||
private Model bombModel;
|
private Model bombModel;
|
||||||
private CustomShaderBase phongShader;
|
private Model boxModel;
|
||||||
private SingleLightPerPixelShader ppShader;
|
private SingleLightPerPixelShader ppShader;
|
||||||
private Mesh bombMesh;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createAllEntities() {
|
public void createAllEntities() {
|
||||||
MeshBuilder builder;
|
ModelBuilder builder;
|
||||||
Entity bomb, sphere, box, bombModelBatch;
|
Entity bomb1, box, bomb2;
|
||||||
G3dModelLoader loader;
|
G3dModelLoader loader;
|
||||||
Environment environment;
|
Environment environment;
|
||||||
|
Material material;
|
||||||
|
|
||||||
// Create mesh.
|
// Create mesh.
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the meshes.");
|
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();
|
|
||||||
|
|
||||||
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.box(0.5f, 0.5f, 6.0f);
|
|
||||||
}boxMesh = builder.end();
|
|
||||||
|
|
||||||
loader = new G3dModelLoader(new JsonReader());
|
loader = new G3dModelLoader(new JsonReader());
|
||||||
bombModel = loader.loadModel(Gdx.files.internal("models/Bomb_test_2.g3dj"));
|
bombModel = loader.loadModel(Gdx.files.internal("models/Bomb_test_2.g3dj"));
|
||||||
|
|
||||||
bombMesh = bombModel.meshes.get(0);
|
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));
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): " + bombMesh.getVertexAttributes().toString());
|
|
||||||
|
|
||||||
// Load the phong shader.
|
builder = new ModelBuilder();
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Loading the phong shader.");
|
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());
|
||||||
try{
|
|
||||||
phongShader = new SingleLightPhongShader().loadShader();
|
|
||||||
}catch(ShaderFailedToLoadException se){
|
|
||||||
Gdx.app.error(TAG, CLASS_NAME + ".InGameState(): " + se.getMessage());
|
|
||||||
Gdx.app.exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
// Load the shader.
|
||||||
ppShader = new SingleLightPerPixelShader();
|
ppShader = new SingleLightPerPixelShader();
|
||||||
ppShader.init();
|
ppShader.init();
|
||||||
|
|
||||||
environment = new Environment();
|
environment = new Environment();
|
||||||
environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.0f));
|
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(-2, -2, -2)));
|
environment.add(new DirectionalLight().set(new Color(1, 1, 1, 1), new Vector3(1, 0, 0.5f)));
|
||||||
|
|
||||||
// Create the entities.
|
// Create the entities.
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the enitites.");
|
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the enitites.");
|
||||||
bomb = world.createEntity();
|
bomb1 = 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)));
|
bomb1.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 MeshComponent(bombMesh));
|
bomb1.addComponent(new ModelComponent(bombModel));
|
||||||
bomb.addComponent(new CustomShaderComponent(phongShader));
|
bomb1.addComponent(new EnvironmentComponent(environment));
|
||||||
bomb.addComponent(new MarkerCodeComponent(1023));
|
bomb1.addComponent(new ShaderComponent(ppShader));
|
||||||
|
bomb1.addComponent(new MarkerCodeComponent(1023));
|
||||||
|
|
||||||
bombModelBatch = world.createEntity();
|
bomb2 = world.createEntity();
|
||||||
bombModelBatch.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.0f), new Matrix3().idt(), new Vector3(1.0f, 1.0f, 1.0f)));
|
bomb2.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.0f), new Matrix3().idt(), new Vector3(1.0f, 1.0f, 1.0f)));
|
||||||
bombModelBatch.addComponent(new ModelComponent(bombModel));
|
bomb2.addComponent(new ModelComponent(bombModel));
|
||||||
bombModelBatch.addComponent(new EnvironmentComponent(environment));
|
bomb2.addComponent(new EnvironmentComponent(environment));
|
||||||
bombModelBatch.addComponent(new MarkerCodeComponent(89));
|
bomb2.addComponent(new MarkerCodeComponent(89));
|
||||||
bombModelBatch.addComponent(new ShaderComponent(ppShader));
|
bomb2.addComponent(new ShaderComponent(ppShader));
|
||||||
|
|
||||||
sphere = world.createEntity();
|
|
||||||
sphere.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.0f), new Matrix3().idt(), new Vector3(1.0f, 1.0f, 1.0f)));
|
|
||||||
sphere.addComponent(new MeshComponent(sphereMesh));
|
|
||||||
sphere.addComponent(new CustomShaderComponent(phongShader));
|
|
||||||
sphere.addComponent(new MarkerCodeComponent(10));
|
|
||||||
|
|
||||||
box = world.createEntity();
|
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 GeometryComponent(new Vector3(-1.0f, 0.0f, 0.0f), new Matrix3().idt(), new Vector3(1.0f, 1.0f, 1.0f)));
|
||||||
box.addComponent(new MeshComponent(boxMesh));
|
box.addComponent(new ModelComponent(boxModel));
|
||||||
box.addComponent(new CustomShaderComponent(phongShader));
|
box.addComponent(new ShaderComponent(ppShader));
|
||||||
|
box.addComponent(new EnvironmentComponent(environment));
|
||||||
|
|
||||||
// Add the entities to the world.
|
// Add the entities to the world.
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Adding entities to the world.");
|
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Adding entities to the world.");
|
||||||
//sphere.addToWorld();
|
//sphere.addToWorld();
|
||||||
bomb.addToWorld();
|
bomb1.addToWorld();
|
||||||
bombModelBatch.addToWorld();
|
bomb2.addToWorld();
|
||||||
sphere.addToWorld();
|
|
||||||
box.addToWorld();
|
box.addToWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
if(phongShader != null && phongShader.getShaderProgram() != null)
|
if(boxModel != null)
|
||||||
phongShader.getShaderProgram().dispose();
|
boxModel.dispose();
|
||||||
|
|
||||||
if(sphereMesh != null)
|
|
||||||
sphereMesh.dispose();
|
|
||||||
|
|
||||||
if(boxMesh != null)
|
|
||||||
boxMesh.dispose();
|
|
||||||
|
|
||||||
if(bombModel != null)
|
if(bombModel != null)
|
||||||
bombModel.dispose();
|
bombModel.dispose();
|
||||||
|
@@ -25,18 +25,18 @@ import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute;
|
|||||||
import com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute;
|
import com.badlogic.gdx.graphics.g3d.attributes.FloatAttribute;
|
||||||
import com.badlogic.gdx.graphics.g3d.utils.RenderContext;
|
import com.badlogic.gdx.graphics.g3d.utils.RenderContext;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
||||||
|
import com.badlogic.gdx.math.Matrix4;
|
||||||
import com.badlogic.gdx.math.Vector3;
|
import com.badlogic.gdx.math.Vector3;
|
||||||
import com.badlogic.gdx.utils.GdxRuntimeException;
|
import com.badlogic.gdx.utils.GdxRuntimeException;
|
||||||
|
|
||||||
public class SingleLightPerPixelShader implements Shader{
|
public class SingleLightPerPixelShader implements Shader{
|
||||||
private static final String TAG = "SINGLE_LIGHT_PER_PIXEL_SHADER";
|
|
||||||
private static final String CLASS_NAME = SingleLightPerPixelShader.class.getSimpleName();
|
|
||||||
private static final String VERTEX_SHADER_PATH = "shaders/directionalPerPixelSingleLight/directionalPerPixel_vert.glsl";
|
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 FRAGMENT_SHADER_PATH = "shaders/directionalPerPixelSingleLight/directionalPerPixel_frag.glsl";
|
||||||
|
|
||||||
private ShaderProgram program;
|
private ShaderProgram program;
|
||||||
private Camera camera;
|
private Camera camera;
|
||||||
private RenderContext context;
|
private RenderContext context;
|
||||||
|
private Matrix4 normalMatrix;
|
||||||
|
|
||||||
// Uniform locations.
|
// Uniform locations.
|
||||||
private int u_geomTrans;
|
private int u_geomTrans;
|
||||||
@@ -48,6 +48,7 @@ public class SingleLightPerPixelShader implements Shader{
|
|||||||
private int u_shiny;
|
private int u_shiny;
|
||||||
private int u_cameraPos;
|
private int u_cameraPos;
|
||||||
private int u_materialDiffuse;
|
private int u_materialDiffuse;
|
||||||
|
private int u_normalMatrix;
|
||||||
|
|
||||||
public SingleLightPerPixelShader(){
|
public SingleLightPerPixelShader(){
|
||||||
program = null;
|
program = null;
|
||||||
@@ -57,12 +58,13 @@ public class SingleLightPerPixelShader implements Shader{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void init() throws GdxRuntimeException{
|
public void init() throws GdxRuntimeException{
|
||||||
|
normalMatrix = new Matrix4().idt();
|
||||||
|
|
||||||
// Compile the shader.
|
// Compile the shader.
|
||||||
program = new ShaderProgram(Gdx.files.internal(VERTEX_SHADER_PATH), Gdx.files.internal(FRAGMENT_SHADER_PATH));
|
program = new ShaderProgram(Gdx.files.internal(VERTEX_SHADER_PATH), Gdx.files.internal(FRAGMENT_SHADER_PATH));
|
||||||
if(!program.isCompiled()){
|
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".init(): Shader failed to compile.");
|
if(!program.isCompiled())
|
||||||
throw new GdxRuntimeException(program.getLog());
|
throw new GdxRuntimeException(program.getLog());
|
||||||
}
|
|
||||||
|
|
||||||
// Cache uniform locations.
|
// Cache uniform locations.
|
||||||
u_projTrans = program.getUniformLocation("u_projTrans");
|
u_projTrans = program.getUniformLocation("u_projTrans");
|
||||||
@@ -74,6 +76,7 @@ public class SingleLightPerPixelShader implements Shader{
|
|||||||
u_shiny = program.getUniformLocation("u_shiny");
|
u_shiny = program.getUniformLocation("u_shiny");
|
||||||
u_cameraPos = program.getUniformLocation("u_cameraPos");
|
u_cameraPos = program.getUniformLocation("u_cameraPos");
|
||||||
u_materialDiffuse = program.getUniformLocation("u_materialDiffuse");
|
u_materialDiffuse = program.getUniformLocation("u_materialDiffuse");
|
||||||
|
u_normalMatrix = program.getUniformLocation("u_normalMatrix");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -92,12 +95,16 @@ public class SingleLightPerPixelShader implements Shader{
|
|||||||
// Check for all needed lighting and material attributes.
|
// Check for all needed lighting and material attributes.
|
||||||
if(renderable.environment.directionalLights.size < 1)
|
if(renderable.environment.directionalLights.size < 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(!renderable.environment.has(ColorAttribute.AmbientLight))
|
if(!renderable.environment.has(ColorAttribute.AmbientLight))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(!renderable.material.has(ColorAttribute.Diffuse))
|
if(!renderable.material.has(ColorAttribute.Diffuse))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(!renderable.material.has(ColorAttribute.Specular))
|
if(!renderable.material.has(ColorAttribute.Specular))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if(!renderable.material.has(FloatAttribute.Shininess))
|
if(!renderable.material.has(FloatAttribute.Shininess))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -109,7 +116,7 @@ public class SingleLightPerPixelShader implements Shader{
|
|||||||
if(this.camera != null || this.context != null)
|
if(this.camera != null || this.context != null)
|
||||||
throw new GdxRuntimeException("Called begin twice before calling end.");
|
throw new GdxRuntimeException("Called begin twice before calling end.");
|
||||||
|
|
||||||
this.camera = camera;
|
this.camera = camera;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
program.begin();
|
program.begin();
|
||||||
|
|
||||||
@@ -125,15 +132,16 @@ public class SingleLightPerPixelShader implements Shader{
|
|||||||
@Override
|
@Override
|
||||||
public void render(Renderable renderable){
|
public void render(Renderable renderable){
|
||||||
// Get material colors.
|
// Get material colors.
|
||||||
Vector3 lightPosition = renderable.environment.directionalLights.get(0).direction;
|
Vector3 lightPosition = renderable.environment.directionalLights.get(0).direction;
|
||||||
Color diffuseLightColor = renderable.environment.directionalLights.get(0).color;
|
Color diffuseLightColor = renderable.environment.directionalLights.get(0).color;
|
||||||
Color diffuseColor = ((ColorAttribute)renderable.material.get(ColorAttribute.Diffuse)).color;
|
Color diffuseColor = ((ColorAttribute)renderable.material.get(ColorAttribute.Diffuse)).color;
|
||||||
Color specularColor = ((ColorAttribute)renderable.material.get(ColorAttribute.Specular)).color;
|
Color specularColor = ((ColorAttribute)renderable.material.get(ColorAttribute.Specular)).color;
|
||||||
Color ambientColor = ((ColorAttribute)renderable.environment.get(ColorAttribute.AmbientLight)).color;
|
Color ambientColor = ((ColorAttribute)renderable.environment.get(ColorAttribute.AmbientLight)).color;
|
||||||
float shininess = ((FloatAttribute)renderable.material.get(FloatAttribute.Shininess)).value;
|
float shininess = ((FloatAttribute)renderable.material.get(FloatAttribute.Shininess)).value;
|
||||||
|
|
||||||
// Set model dependant uniforms.
|
// Set model dependant uniforms.
|
||||||
program.setUniformMatrix(u_geomTrans, renderable.worldTransform);
|
program.setUniformMatrix(u_geomTrans, renderable.worldTransform);
|
||||||
|
program.setUniformMatrix(u_normalMatrix, normalMatrix.idt().mul(renderable.worldTransform).inv().tra());
|
||||||
program.setUniformf(u_lightPos, lightPosition);
|
program.setUniformf(u_lightPos, lightPosition);
|
||||||
program.setUniformf(u_lightDiffuse, diffuseLightColor);
|
program.setUniformf(u_lightDiffuse, diffuseLightColor);
|
||||||
program.setUniformf(u_materialDiffuse, diffuseColor);
|
program.setUniformf(u_materialDiffuse, diffuseColor);
|
||||||
@@ -149,7 +157,7 @@ public class SingleLightPerPixelShader implements Shader{
|
|||||||
public void end(){
|
public void end(){
|
||||||
program.end();
|
program.end();
|
||||||
|
|
||||||
this.camera = null;
|
this.camera = null;
|
||||||
this.context = null;
|
this.context = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package ve.ucv.ciens.ccg.nxtar.interfaces;
|
package ve.ucv.ciens.ccg.nxtar.interfaces;
|
||||||
|
|
||||||
public interface AndroidFunctionalityWrapper{
|
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 enableMulticast();
|
@@ -29,7 +29,6 @@ import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue;
|
|||||||
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
|
import ve.ucv.ciens.ccg.nxtar.network.monitors.VideoFrameMonitor;
|
||||||
import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem;
|
import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem;
|
||||||
import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem;
|
import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem;
|
||||||
import ve.ucv.ciens.ccg.nxtar.systems.ModelBatchMarkerRenderingSystem;
|
|
||||||
import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem;
|
import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem;
|
||||||
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||||
|
|
||||||
@@ -48,6 +47,7 @@ import com.badlogic.gdx.graphics.Texture.TextureFilter;
|
|||||||
import com.badlogic.gdx.graphics.Texture.TextureWrap;
|
import com.badlogic.gdx.graphics.Texture.TextureWrap;
|
||||||
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;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.ModelBatch;
|
||||||
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
|
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
|
||||||
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
|
||||||
import com.badlogic.gdx.math.Matrix4;
|
import com.badlogic.gdx.math.Matrix4;
|
||||||
@@ -69,49 +69,52 @@ public class InGameState extends BaseState{
|
|||||||
private static final float SHINYNESS = 50.0f;
|
private static final float SHINYNESS = 50.0f;
|
||||||
|
|
||||||
// Background related fields.
|
// Background related fields.
|
||||||
private float uScaling[];
|
private float uScaling[];
|
||||||
protected Sprite background;
|
protected Sprite background;
|
||||||
private Texture backgroundTexture;
|
private Texture backgroundTexture;
|
||||||
private ShaderProgram backgroundShader;
|
private ShaderProgram backgroundShader;
|
||||||
|
|
||||||
// 3D rendering fields.
|
// 3D rendering fields.
|
||||||
private Matrix4 projectionMatrix;
|
private ModelBatch modelBatch;
|
||||||
private FrameBuffer frameBuffer;
|
private Matrix4 projectionMatrix;
|
||||||
private Sprite frameBufferSprite;
|
private FrameBuffer frameBuffer;
|
||||||
|
private Sprite frameBufferSprite;
|
||||||
|
|
||||||
// Game objects.
|
// Game world objects.
|
||||||
private World gameWorld;
|
private World gameWorld;
|
||||||
private EntityCreatorBase entityCreator;
|
private EntityCreatorBase entityCreator;
|
||||||
|
private MarkerRenderingSystem markerRenderingSystem;
|
||||||
|
private ObjectRenderingSystem objectRenderingSystem;
|
||||||
|
|
||||||
// Cameras.
|
// Cameras.
|
||||||
private OrthographicCamera unitaryOrthoCamera;
|
private OrthographicCamera unitaryOrthoCamera;
|
||||||
private OrthographicCamera pixelPerfectOrthoCamera;
|
private OrthographicCamera pixelPerfectOrthoCamera;
|
||||||
private CustomPerspectiveCamera perspectiveCamera;
|
private CustomPerspectiveCamera perspectiveCamera;
|
||||||
|
|
||||||
// Video stream graphics.
|
// Video stream graphics.
|
||||||
private Texture videoFrameTexture;
|
private Texture videoFrameTexture;
|
||||||
private Sprite renderableVideoFrame;
|
private Sprite renderableVideoFrame;
|
||||||
private Pixmap videoFrame;
|
private Pixmap videoFrame;
|
||||||
|
|
||||||
// Interface buttons.
|
// Interface buttons.
|
||||||
private Texture buttonTexture;
|
private Texture buttonTexture;
|
||||||
private Texture buttonTexture2;
|
private Texture buttonTexture2;
|
||||||
private Sprite motorA;
|
private Sprite motorA;
|
||||||
private Sprite motorB;
|
private Sprite motorB;
|
||||||
private Sprite motorC;
|
private Sprite motorC;
|
||||||
private Sprite motorD;
|
private Sprite motorD;
|
||||||
private Sprite headA;
|
private Sprite headA;
|
||||||
private Sprite headB;
|
private Sprite headB;
|
||||||
private Sprite headC;
|
private Sprite headC;
|
||||||
|
|
||||||
// Button touch helper fields.
|
// Button touch helper fields.
|
||||||
private boolean[] motorButtonsTouched;
|
private boolean[] motorButtonsTouched;
|
||||||
private int[] motorButtonsPointers;
|
private int[] motorButtonsPointers;
|
||||||
private boolean[] motorGamepadButtonPressed;
|
private boolean[] motorGamepadButtonPressed;
|
||||||
|
|
||||||
// Monitors.
|
// Monitors.
|
||||||
private VideoFrameMonitor frameMonitor;
|
private VideoFrameMonitor frameMonitor;
|
||||||
private MotorEventQueue queue;
|
private MotorEventQueue queue;
|
||||||
|
|
||||||
public InGameState(final NxtARCore core){
|
public InGameState(final NxtARCore core){
|
||||||
this.core = core;
|
this.core = core;
|
||||||
@@ -179,6 +182,7 @@ public class InGameState extends BaseState{
|
|||||||
uScaling[1] = Gdx.graphics.getHeight() > Gdx.graphics.getWidth() ? 16.0f : 9.0f;
|
uScaling[1] = Gdx.graphics.getHeight() > Gdx.graphics.getWidth() ? 16.0f : 9.0f;
|
||||||
|
|
||||||
// Set up the 3D rendering.
|
// Set up the 3D rendering.
|
||||||
|
modelBatch = new ModelBatch();
|
||||||
projectionMatrix = new Matrix4().idt();
|
projectionMatrix = new Matrix4().idt();
|
||||||
frameBuffer = null;
|
frameBuffer = null;
|
||||||
perspectiveCamera = null;
|
perspectiveCamera = null;
|
||||||
@@ -191,9 +195,10 @@ public class InGameState extends BaseState{
|
|||||||
entityCreator.setWorld(gameWorld);
|
entityCreator.setWorld(gameWorld);
|
||||||
entityCreator.createAllEntities();
|
entityCreator.createAllEntities();
|
||||||
gameWorld.setSystem(new MarkerPositioningSystem());
|
gameWorld.setSystem(new MarkerPositioningSystem());
|
||||||
gameWorld.setSystem(new MarkerRenderingSystem(), true);
|
markerRenderingSystem = new MarkerRenderingSystem(modelBatch);
|
||||||
gameWorld.setSystem(new ModelBatchMarkerRenderingSystem(), true);
|
objectRenderingSystem = new ObjectRenderingSystem(modelBatch);
|
||||||
gameWorld.setSystem(new ObjectRenderingSystem(), true);
|
gameWorld.setSystem(markerRenderingSystem, true);
|
||||||
|
gameWorld.setSystem(objectRenderingSystem, true);
|
||||||
gameWorld.initialize();
|
gameWorld.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -306,14 +311,13 @@ public class InGameState extends BaseState{
|
|||||||
RenderParameters.setEyePosition(perspectiveCamera.position);
|
RenderParameters.setEyePosition(perspectiveCamera.position);
|
||||||
|
|
||||||
// Call rendering systems.
|
// Call rendering systems.
|
||||||
gameWorld.getSystem(MarkerRenderingSystem.class).setMarkerData(data);
|
markerRenderingSystem.begin(perspectiveCamera, data);
|
||||||
gameWorld.getSystem(MarkerRenderingSystem.class).process();
|
markerRenderingSystem.process();
|
||||||
|
markerRenderingSystem.end();
|
||||||
|
|
||||||
gameWorld.getSystem(ModelBatchMarkerRenderingSystem.class).begin(perspectiveCamera, data);
|
objectRenderingSystem.begin(perspectiveCamera);
|
||||||
gameWorld.getSystem(ModelBatchMarkerRenderingSystem.class).process();
|
objectRenderingSystem.process();
|
||||||
gameWorld.getSystem(ModelBatchMarkerRenderingSystem.class).end();
|
objectRenderingSystem.end();
|
||||||
|
|
||||||
gameWorld.getSystem(ObjectRenderingSystem.class).process();
|
|
||||||
}frameBuffer.end();
|
}frameBuffer.end();
|
||||||
|
|
||||||
// Set the frame buffer object texture to a renderable sprite.
|
// Set the frame buffer object texture to a renderable sprite.
|
||||||
@@ -382,7 +386,8 @@ public class InGameState extends BaseState{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose(){
|
public void dispose(){
|
||||||
gameWorld.getSystem(ModelBatchMarkerRenderingSystem.class).dispose();
|
if(modelBatch != null)
|
||||||
|
modelBatch.dispose();
|
||||||
|
|
||||||
if(entityCreator != null)
|
if(entityCreator != null)
|
||||||
entityCreator.dispose();
|
entityCreator.dispose();
|
||||||
|
37
src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java
Normal file
37
src/ve/ucv/ciens/ccg/nxtar/systems/AnimationSystem.java
Normal file
@@ -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 AnimationSystem extends EntityProcessingSystem {
|
||||||
|
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
|
public AnimationSystem(){
|
||||||
|
super(Aspect.getAspectForAll(ModelComponent.class));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void process(Entity e) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -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
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@@ -15,11 +15,11 @@
|
|||||||
*/
|
*/
|
||||||
package ve.ucv.ciens.ccg.nxtar.systems;
|
package ve.ucv.ciens.ccg.nxtar.systems;
|
||||||
|
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.CustomShaderComponent;
|
import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
|
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
|
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.MeshComponent;
|
import ve.ucv.ciens.ccg.nxtar.components.ModelComponent;
|
||||||
import ve.ucv.ciens.ccg.nxtar.graphics.RenderParameters;
|
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
|
||||||
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
|
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
|
||||||
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
|
||||||
|
|
||||||
@@ -29,16 +29,18 @@ import com.artemis.Entity;
|
|||||||
import com.artemis.annotations.Mapper;
|
import com.artemis.annotations.Mapper;
|
||||||
import com.artemis.systems.EntityProcessingSystem;
|
import com.artemis.systems.EntityProcessingSystem;
|
||||||
import com.badlogic.gdx.Gdx;
|
import com.badlogic.gdx.Gdx;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
import com.badlogic.gdx.graphics.PerspectiveCamera;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.ModelBatch;
|
||||||
import com.badlogic.gdx.math.Matrix4;
|
import com.badlogic.gdx.math.Matrix4;
|
||||||
|
|
||||||
public class MarkerRenderingSystem extends EntityProcessingSystem {
|
public class MarkerRenderingSystem extends EntityProcessingSystem {
|
||||||
@Mapper ComponentMapper<MarkerCodeComponent> markerMapper;
|
@Mapper ComponentMapper<MarkerCodeComponent> markerMapper;
|
||||||
@Mapper ComponentMapper<GeometryComponent> geometryMapper;
|
@Mapper ComponentMapper<GeometryComponent> geometryMapper;
|
||||||
@Mapper ComponentMapper<CustomShaderComponent> shaderMapper;
|
@Mapper ComponentMapper<ModelComponent> modelMapper;
|
||||||
@Mapper ComponentMapper<MeshComponent> meshMapper;
|
@Mapper ComponentMapper<EnvironmentComponent> environmentMapper;
|
||||||
|
@Mapper ComponentMapper<ShaderComponent> shaderMapper;
|
||||||
|
|
||||||
private static final String TAG = "MARKER_RENDERING_SYSTEM";
|
private static final String TAG = "MODEL_BATCH_MARKER_RENDERING_SYSTEM";
|
||||||
private static final String CLASS_NAME = MarkerRenderingSystem.class.getSimpleName();
|
private static final String CLASS_NAME = MarkerRenderingSystem.class.getSimpleName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -56,43 +58,59 @@ public class MarkerRenderingSystem extends EntityProcessingSystem {
|
|||||||
*/
|
*/
|
||||||
private Matrix4 scalingMatrix;
|
private Matrix4 scalingMatrix;
|
||||||
|
|
||||||
/**
|
private MarkerData markers;
|
||||||
* <p>The total transformation to be applied to an entity.</p>
|
|
||||||
*/
|
|
||||||
private Matrix4 combinedTransformationMatrix;
|
|
||||||
|
|
||||||
MarkerData markers;
|
private PerspectiveCamera camera;
|
||||||
|
|
||||||
|
private ModelBatch batch;
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public MarkerRenderingSystem(){
|
public MarkerRenderingSystem(ModelBatch batch){
|
||||||
super(Aspect.getAspectForAll(MarkerCodeComponent.class, GeometryComponent.class, CustomShaderComponent.class, MeshComponent.class));
|
super(Aspect.getAspectForAll(MarkerCodeComponent.class, GeometryComponent.class, ShaderComponent.class, EnvironmentComponent.class, ModelComponent.class));
|
||||||
|
|
||||||
markers = null;
|
markers = null;
|
||||||
translationMatrix = new Matrix4().setToTranslation(0.0f, 0.0f, 0.0f);
|
camera = null;
|
||||||
rotationMatrix = new Matrix4().idt();
|
this.batch = batch;
|
||||||
scalingMatrix = new Matrix4().setToScaling(0.0f, 0.0f, 0.0f);
|
translationMatrix = new Matrix4().setToTranslation(0.0f, 0.0f, 0.0f);
|
||||||
combinedTransformationMatrix = new Matrix4();
|
rotationMatrix = new Matrix4().idt();
|
||||||
|
scalingMatrix = new Matrix4().setToScaling(0.0f, 0.0f, 0.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMarkerData(MarkerData markers){
|
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.markers = markers;
|
||||||
|
this.camera = camera;
|
||||||
|
batch.begin(camera);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void end(){
|
||||||
|
batch.end();
|
||||||
|
camera = null;
|
||||||
|
markers = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void process(Entity e) {
|
protected void process(Entity e) {
|
||||||
MarkerCodeComponent marker;
|
MarkerCodeComponent marker;
|
||||||
GeometryComponent geometry;
|
GeometryComponent geometry;
|
||||||
CustomShaderComponent shaderComp;
|
EnvironmentComponent environment;
|
||||||
MeshComponent meshComp;
|
ModelComponent model;
|
||||||
|
ShaderComponent shader;
|
||||||
|
|
||||||
if(markers == null)
|
if(markers == null || camera == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".process(): Getting components.");
|
Gdx.app.log(TAG, CLASS_NAME + ".process(): Getting components.");
|
||||||
marker = markerMapper.get(e);
|
marker = markerMapper.get(e);
|
||||||
geometry = geometryMapper.get(e);
|
geometry = geometryMapper.get(e);
|
||||||
shaderComp = shaderMapper.get(e);
|
model = modelMapper.get(e);
|
||||||
meshComp = meshMapper.get(e);
|
environment = environmentMapper.get(e);
|
||||||
|
shader = shaderMapper.get(e);
|
||||||
|
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".process(): Processing markers.");
|
Gdx.app.log(TAG, CLASS_NAME + ".process(): Processing markers.");
|
||||||
for(int i = 0; i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){
|
for(int i = 0; i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){
|
||||||
@@ -123,14 +141,13 @@ public class MarkerRenderingSystem extends EntityProcessingSystem {
|
|||||||
rotationMatrix.val[Matrix4.M33] = 1;
|
rotationMatrix.val[Matrix4.M33] = 1;
|
||||||
|
|
||||||
scalingMatrix.setToScaling(geometry.scaling);
|
scalingMatrix.setToScaling(geometry.scaling);
|
||||||
combinedTransformationMatrix.idt().mul(translationMatrix).mul(rotationMatrix).mul(scalingMatrix);
|
|
||||||
RenderParameters.setTransformationMatrix(combinedTransformationMatrix);
|
// Apply the geometric transformations to the model.
|
||||||
|
model.instance.transform.idt().mul(translationMatrix).mul(rotationMatrix).mul(scalingMatrix);
|
||||||
|
model.instance.calculateTransforms();
|
||||||
|
|
||||||
// Render the marker;
|
// Render the marker;
|
||||||
shaderComp.shader.getShaderProgram().begin();{
|
batch.render(model.instance, environment.environment, shader.shader);
|
||||||
shaderComp.shader.setUniforms();
|
|
||||||
meshComp.model.render(shaderComp.shader.getShaderProgram(), GL20.GL_TRIANGLES);
|
|
||||||
}shaderComp.shader.getShaderProgram().end();
|
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".process(): Skipping marker number " + Integer.toString(i) + ".");
|
Gdx.app.log(TAG, CLASS_NAME + ".process(): Skipping marker number " + Integer.toString(i) + ".");
|
||||||
|
@@ -1,162 +0,0 @@
|
|||||||
/*
|
|
||||||
* 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 ModelBatchMarkerRenderingSystem 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 = ModelBatchMarkerRenderingSystem.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 ModelBatchMarkerRenderingSystem(){
|
|
||||||
super(Aspect.getAspectForAll(MarkerCodeComponent.class, GeometryComponent.class, ShaderComponent.class, EnvironmentComponent.class, ModelComponent.class));
|
|
||||||
|
|
||||||
markers = null;
|
|
||||||
camera = null;
|
|
||||||
batch = new ModelBatch();
|
|
||||||
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 dispose(){
|
|
||||||
batch.dispose();
|
|
||||||
}
|
|
||||||
|
|
||||||
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) + ".");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@@ -15,18 +15,19 @@
|
|||||||
*/
|
*/
|
||||||
package ve.ucv.ciens.ccg.nxtar.systems;
|
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.GeometryComponent;
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
|
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.MeshComponent;
|
import ve.ucv.ciens.ccg.nxtar.components.ModelComponent;
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.CustomShaderComponent;
|
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
|
||||||
import ve.ucv.ciens.ccg.nxtar.graphics.RenderParameters;
|
|
||||||
|
|
||||||
import com.artemis.Aspect;
|
import com.artemis.Aspect;
|
||||||
import com.artemis.ComponentMapper;
|
import com.artemis.ComponentMapper;
|
||||||
import com.artemis.Entity;
|
import com.artemis.Entity;
|
||||||
import com.artemis.annotations.Mapper;
|
import com.artemis.annotations.Mapper;
|
||||||
import com.artemis.systems.EntityProcessingSystem;
|
import com.artemis.systems.EntityProcessingSystem;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
import com.badlogic.gdx.graphics.PerspectiveCamera;
|
||||||
|
import com.badlogic.gdx.graphics.g3d.ModelBatch;
|
||||||
import com.badlogic.gdx.math.Matrix4;
|
import com.badlogic.gdx.math.Matrix4;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,9 +35,10 @@ import com.badlogic.gdx.math.Matrix4;
|
|||||||
* entities to be rendered must have a geometry, shader and mesh component associated.</p>
|
* entities to be rendered must have a geometry, shader and mesh component associated.</p>
|
||||||
*/
|
*/
|
||||||
public class ObjectRenderingSystem extends EntityProcessingSystem {
|
public class ObjectRenderingSystem extends EntityProcessingSystem {
|
||||||
@Mapper ComponentMapper<GeometryComponent> geometryMapper;
|
@Mapper ComponentMapper<GeometryComponent> geometryMapper;
|
||||||
@Mapper ComponentMapper<CustomShaderComponent> shaderMapper;
|
@Mapper ComponentMapper<ShaderComponent> shaderMapper;
|
||||||
@Mapper ComponentMapper<MeshComponent> modelMapper;
|
@Mapper ComponentMapper<ModelComponent> modelMapper;
|
||||||
|
@Mapper ComponentMapper<EnvironmentComponent> environmentMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>A matrix representing 3D translations.</p>
|
* <p>A matrix representing 3D translations.</p>
|
||||||
@@ -53,19 +55,32 @@ public class ObjectRenderingSystem extends EntityProcessingSystem {
|
|||||||
*/
|
*/
|
||||||
private Matrix4 scalingMatrix;
|
private Matrix4 scalingMatrix;
|
||||||
|
|
||||||
/**
|
private PerspectiveCamera camera;
|
||||||
* <p>The total transformation to be applied to an entity.</p>
|
|
||||||
*/
|
private ModelBatch batch;
|
||||||
private Matrix4 combinedTransformationMatrix;
|
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
public ObjectRenderingSystem() {
|
public ObjectRenderingSystem(ModelBatch batch) {
|
||||||
super(Aspect.getAspectForAll(GeometryComponent.class, CustomShaderComponent.class, MeshComponent.class).exclude(MarkerCodeComponent.class));
|
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);
|
translationMatrix = new Matrix4().setToTranslation(0.0f, 0.0f, 0.0f);
|
||||||
rotationMatrix = new Matrix4().idt();
|
rotationMatrix = new Matrix4().idt();
|
||||||
scalingMatrix = new Matrix4().setToScaling(0.0f, 0.0f, 0.0f);
|
scalingMatrix = new Matrix4().setToScaling(0.0f, 0.0f, 0.0f);
|
||||||
combinedTransformationMatrix = new Matrix4();
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -76,28 +91,25 @@ public class ObjectRenderingSystem extends EntityProcessingSystem {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
protected void process(Entity e) {
|
protected void process(Entity e) {
|
||||||
GeometryComponent geometryComponent;
|
EnvironmentComponent environment;
|
||||||
CustomShaderComponent customShaderComponent;
|
GeometryComponent geometryComponent;
|
||||||
MeshComponent meshComponent;
|
ShaderComponent shaderComponent;
|
||||||
|
ModelComponent modelComponent;
|
||||||
|
|
||||||
// Get the necessary components.
|
// Get the necessary components.
|
||||||
geometryComponent = geometryMapper.get(e);
|
geometryComponent = geometryMapper.get(e);
|
||||||
meshComponent = modelMapper.get(e);
|
modelComponent = modelMapper.get(e);
|
||||||
customShaderComponent = shaderMapper.get(e);
|
shaderComponent = shaderMapper.get(e);
|
||||||
|
environment = environmentMapper.get(e);
|
||||||
|
|
||||||
// Calculate the geometric transformation for this entity.
|
// Calculate the geometric transformation for this entity.
|
||||||
translationMatrix.setToTranslation(geometryComponent.position);
|
translationMatrix.setToTranslation(geometryComponent.position);
|
||||||
rotationMatrix.set(geometryComponent.rotation);
|
rotationMatrix.set(geometryComponent.rotation);
|
||||||
scalingMatrix.setToScaling(geometryComponent.scaling);
|
scalingMatrix.setToScaling(geometryComponent.scaling);
|
||||||
combinedTransformationMatrix.idt().mul(translationMatrix).mul(rotationMatrix).mul(scalingMatrix);
|
modelComponent.instance.transform.idt().mul(translationMatrix).mul(rotationMatrix).mul(scalingMatrix);
|
||||||
|
modelComponent.instance.calculateTransforms();
|
||||||
// Set up the global rendering parameters for this frame.
|
|
||||||
RenderParameters.setTransformationMatrix(combinedTransformationMatrix);
|
|
||||||
|
|
||||||
// Render this entity.
|
// Render this entity.
|
||||||
customShaderComponent.shader.getShaderProgram().begin();{
|
batch.render(modelComponent.instance, environment.environment, shaderComponent.shader);
|
||||||
customShaderComponent.shader.setUniforms();
|
|
||||||
meshComponent.model.render(customShaderComponent.shader.getShaderProgram(), GL20.GL_TRIANGLES);
|
|
||||||
}customShaderComponent.shader.getShaderProgram().end();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user