Added some more test cases. Fixed a bug when rendering markers.
This commit is contained in:
@@ -38,14 +38,14 @@ 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 markerMesh;
|
private Mesh patchMesh, sphereMesh, boxMesh;
|
||||||
private CustomShaderBase phongShader;
|
private CustomShaderBase phongShader;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createAllEntities() {
|
public void createAllEntities() {
|
||||||
MeshBuilder builder;
|
MeshBuilder builder;
|
||||||
Matrix3 identity = new Matrix3().idt();
|
Matrix3 identity = new Matrix3().idt();
|
||||||
Entity marker;
|
Entity patch, sphere, box;
|
||||||
|
|
||||||
// Create mesh.
|
// Create mesh.
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the meshes.");
|
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the meshes.");
|
||||||
@@ -58,7 +58,17 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
|
|||||||
Vector3 v01 = new Vector3( 0.5f, -0.5f, 0.0f);
|
Vector3 v01 = new Vector3( 0.5f, -0.5f, 0.0f);
|
||||||
Vector3 n = new Vector3(0.0f, 1.0f, 0.0f);
|
Vector3 n = new Vector3(0.0f, 1.0f, 0.0f);
|
||||||
builder.patch(v00, v10, v11, v01, n, 10, 10);
|
builder.patch(v00, v10, v11, v01, n, 10, 10);
|
||||||
}markerMesh = builder.end();
|
}patchMesh = 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.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();
|
||||||
|
|
||||||
// Load the phong shader.
|
// Load the phong shader.
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Loading the phong shader.");
|
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Loading the phong shader.");
|
||||||
@@ -71,15 +81,28 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
|
|||||||
|
|
||||||
// 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.");
|
||||||
marker = world.createEntity();
|
patch = world.createEntity();
|
||||||
marker.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.0f), identity, new Vector3(1.0f, 1.0f, 1.0f)));
|
patch.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.0f), identity, new Vector3(1.0f, 1.0f, 1.0f)));
|
||||||
marker.addComponent(new MeshComponent(markerMesh));
|
patch.addComponent(new MeshComponent(patchMesh));
|
||||||
marker.addComponent(new ShaderComponent(phongShader));
|
patch.addComponent(new ShaderComponent(phongShader));
|
||||||
marker.addComponent(new MarkerCodeComponent(213));
|
patch.addComponent(new MarkerCodeComponent(213));
|
||||||
|
|
||||||
|
sphere = world.createEntity();
|
||||||
|
sphere.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.0f), identity, new Vector3(1.0f, 1.0f, 1.0f)));
|
||||||
|
sphere.addComponent(new MeshComponent(sphereMesh));
|
||||||
|
sphere.addComponent(new ShaderComponent(phongShader));
|
||||||
|
sphere.addComponent(new MarkerCodeComponent(10));
|
||||||
|
|
||||||
|
box = world.createEntity();
|
||||||
|
box.addComponent(new GeometryComponent(new Vector3(-1.0f, 0.0f, 0.0f), identity, new Vector3(1.0f, 1.0f, 1.0f)));
|
||||||
|
box.addComponent(new MeshComponent(boxMesh));
|
||||||
|
box.addComponent(new ShaderComponent(phongShader));
|
||||||
|
|
||||||
// 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.");
|
||||||
marker.addToWorld();
|
sphere.addToWorld();
|
||||||
|
patch.addToWorld();
|
||||||
|
box.addToWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -87,7 +110,13 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
|
|||||||
if(phongShader != null && phongShader.getShaderProgram() != null)
|
if(phongShader != null && phongShader.getShaderProgram() != null)
|
||||||
phongShader.getShaderProgram().dispose();
|
phongShader.getShaderProgram().dispose();
|
||||||
|
|
||||||
if(markerMesh != null)
|
if(patchMesh != null)
|
||||||
markerMesh.dispose();
|
patchMesh.dispose();
|
||||||
|
|
||||||
|
if(sphereMesh != null)
|
||||||
|
sphereMesh.dispose();
|
||||||
|
|
||||||
|
if(boxMesh != null)
|
||||||
|
boxMesh.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -22,6 +22,7 @@ import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
|
|||||||
import ve.ucv.ciens.ccg.nxtar.entities.EntityCreatorBase;
|
import ve.ucv.ciens.ccg.nxtar.entities.EntityCreatorBase;
|
||||||
import ve.ucv.ciens.ccg.nxtar.entities.MarkerTestEntityCreator;
|
import ve.ucv.ciens.ccg.nxtar.entities.MarkerTestEntityCreator;
|
||||||
import ve.ucv.ciens.ccg.nxtar.graphics.CustomPerspectiveCamera;
|
import ve.ucv.ciens.ccg.nxtar.graphics.CustomPerspectiveCamera;
|
||||||
|
import ve.ucv.ciens.ccg.nxtar.graphics.LightSource;
|
||||||
import ve.ucv.ciens.ccg.nxtar.graphics.RenderParameters;
|
import ve.ucv.ciens.ccg.nxtar.graphics.RenderParameters;
|
||||||
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
|
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
|
||||||
import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue;
|
import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue;
|
||||||
@@ -36,6 +37,7 @@ 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.controllers.Controller;
|
||||||
import com.badlogic.gdx.controllers.mappings.Ouya;
|
import com.badlogic.gdx.controllers.mappings.Ouya;
|
||||||
|
import com.badlogic.gdx.graphics.Color;
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
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;
|
||||||
@@ -59,6 +61,11 @@ public class InGameState extends BaseState{
|
|||||||
private static final float FAR = 100.0f;
|
private static final float FAR = 100.0f;
|
||||||
private static final float FAR_PLUS_NEAR = FAR + NEAR;
|
private static final float FAR_PLUS_NEAR = FAR + NEAR;
|
||||||
private static final float FAR_LESS_NEAR = FAR - NEAR;
|
private static final float FAR_LESS_NEAR = FAR - NEAR;
|
||||||
|
private static final Vector3 LIGHT_POSITION = new Vector3(2.0f, 2.0f, 4.0f);
|
||||||
|
private static final Color AMBIENT_COLOR = new Color(0.0f, 0.1f, 0.2f, 1.0f);
|
||||||
|
private static final Color DIFFUSE_COLOR = new Color(1.0f, 1.0f, 1.0f, 1.0f);
|
||||||
|
private static final Color SPECULAR_COLOR = new Color(1.0f, 0.8f, 0.0f, 1.0f);
|
||||||
|
private static final float SHINYNESS = 50.0f;
|
||||||
|
|
||||||
// Background related fields.
|
// Background related fields.
|
||||||
private float uScaling[];
|
private float uScaling[];
|
||||||
@@ -175,6 +182,7 @@ public class InGameState extends BaseState{
|
|||||||
frameBuffer = null;
|
frameBuffer = null;
|
||||||
perspectiveCamera = null;
|
perspectiveCamera = null;
|
||||||
frameBufferSprite = null;
|
frameBufferSprite = null;
|
||||||
|
RenderParameters.setLightSource1(new LightSource(LIGHT_POSITION, AMBIENT_COLOR, DIFFUSE_COLOR, SPECULAR_COLOR, SHINYNESS));
|
||||||
|
|
||||||
// Set up the game world.
|
// Set up the game world.
|
||||||
gameWorld = new World();
|
gameWorld = new World();
|
||||||
|
@@ -62,17 +62,16 @@ public class MarkerPositioningSystem extends EntityProcessingSystem {
|
|||||||
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++){
|
||||||
if(markers.markerCodes[i] != 1){
|
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){
|
if(markers.markerCodes[i] == marker.code){
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".process(): Processing marker code " + Integer.toString(markers.markerCodes[i]) + ".");
|
Gdx.app.log(TAG, CLASS_NAME + ".process(): Processing marker code " + Integer.toString(markers.markerCodes[i]) + ".");
|
||||||
geometry.position.set(markers.translationVectors[i]);
|
geometry.position.set(markers.translationVectors[i]);
|
||||||
geometry.rotation.set(markers.rotationMatrices[i]);
|
geometry.rotation.set(markers.rotationMatrices[i]);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}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) + ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
markers = null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -82,6 +82,8 @@ public class MarkerRenderingSystem extends EntityProcessingSystem {
|
|||||||
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++){
|
||||||
if(markers.markerCodes[i] != 1){
|
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){
|
if(markers.markerCodes[i] == marker.code){
|
||||||
Gdx.app.log(TAG, CLASS_NAME + ".process(): Rendering marker code " + Integer.toString(markers.markerCodes[i]) + ".");
|
Gdx.app.log(TAG, CLASS_NAME + ".process(): Rendering marker code " + Integer.toString(markers.markerCodes[i]) + ".");
|
||||||
// Set the geometric transformations.
|
// Set the geometric transformations.
|
||||||
@@ -113,15 +115,11 @@ public class MarkerRenderingSystem extends EntityProcessingSystem {
|
|||||||
shaderComp.shader.setUniforms();
|
shaderComp.shader.setUniforms();
|
||||||
meshComp.model.render(shaderComp.shader.getShaderProgram(), GL20.GL_TRIANGLES);
|
meshComp.model.render(shaderComp.shader.getShaderProgram(), GL20.GL_TRIANGLES);
|
||||||
}shaderComp.shader.getShaderProgram().end();
|
}shaderComp.shader.getShaderProgram().end();
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}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) + ".");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
markers = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,6 @@ 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.MeshComponent;
|
||||||
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
|
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
|
||||||
import ve.ucv.ciens.ccg.nxtar.graphics.LightSource;
|
|
||||||
import ve.ucv.ciens.ccg.nxtar.graphics.RenderParameters;
|
import ve.ucv.ciens.ccg.nxtar.graphics.RenderParameters;
|
||||||
|
|
||||||
import com.artemis.Aspect;
|
import com.artemis.Aspect;
|
||||||
@@ -27,10 +26,8 @@ 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.Color;
|
|
||||||
import com.badlogic.gdx.graphics.GL20;
|
import com.badlogic.gdx.graphics.GL20;
|
||||||
import com.badlogic.gdx.math.Matrix4;
|
import com.badlogic.gdx.math.Matrix4;
|
||||||
import com.badlogic.gdx.math.Vector3;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>Entity processing system in charge of rendering 3D objects using OpenGL. The
|
* <p>Entity processing system in charge of rendering 3D objects using OpenGL. The
|
||||||
@@ -41,12 +38,6 @@ public class ObjectRenderingSystem extends EntityProcessingSystem {
|
|||||||
@Mapper ComponentMapper<ShaderComponent> shaderMapper;
|
@Mapper ComponentMapper<ShaderComponent> shaderMapper;
|
||||||
@Mapper ComponentMapper<MeshComponent> modelMapper;
|
@Mapper ComponentMapper<MeshComponent> modelMapper;
|
||||||
|
|
||||||
private static final Vector3 LIGHT_POSITION = new Vector3(2.0f, 2.0f, 4.0f);
|
|
||||||
private static final Color AMBIENT_COLOR = new Color(0.0f, 0.1f, 0.2f, 1.0f);
|
|
||||||
private static final Color DIFFUSE_COLOR = new Color(1.0f, 1.0f, 1.0f, 1.0f);
|
|
||||||
private static final Color SPECULAR_COLOR = new Color(1.0f, 0.8f, 0.0f, 1.0f);
|
|
||||||
private static final float SHINYNESS = 50.0f;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>A matrix representing 3D translations.</p>
|
* <p>A matrix representing 3D translations.</p>
|
||||||
*/
|
*/
|
||||||
@@ -71,8 +62,6 @@ public class ObjectRenderingSystem extends EntityProcessingSystem {
|
|||||||
public ObjectRenderingSystem() {
|
public ObjectRenderingSystem() {
|
||||||
super(Aspect.getAspectForAll(GeometryComponent.class, ShaderComponent.class, MeshComponent.class).exclude(MarkerCodeComponent.class));
|
super(Aspect.getAspectForAll(GeometryComponent.class, ShaderComponent.class, MeshComponent.class).exclude(MarkerCodeComponent.class));
|
||||||
|
|
||||||
RenderParameters.setLightSource1(new LightSource(LIGHT_POSITION, AMBIENT_COLOR, DIFFUSE_COLOR, SPECULAR_COLOR, SHINYNESS));
|
|
||||||
|
|
||||||
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);
|
||||||
|
Reference in New Issue
Block a user