From 3c65f52e9e097cfa0ce7c3fa06e48e9894de3d71 Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 15 May 2014 16:58:23 -0430 Subject: [PATCH] Added some more test cases. Fixed a bug when rendering markers. --- .../entities/MarkerTestEntityCreator.java | 51 +++++++++++++++---- .../ciens/ccg/nxtar/states/InGameState.java | 22 +++++--- .../systems/MarkerPositioningSystem.java | 5 +- .../nxtar/systems/MarkerRenderingSystem.java | 6 +-- .../nxtar/systems/ObjectRenderingSystem.java | 11 ---- 5 files changed, 59 insertions(+), 36 deletions(-) diff --git a/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java b/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java index be01c0b..2cdf4f6 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java +++ b/src/ve/ucv/ciens/ccg/nxtar/entities/MarkerTestEntityCreator.java @@ -38,14 +38,14 @@ public class MarkerTestEntityCreator extends EntityCreatorBase { private static final String TAG = "MARKER_TEST_ENTITY_CREATOR"; private static final String CLASS_NAME = MarkerTestEntityCreator.class.getSimpleName(); - private Mesh markerMesh; + private Mesh patchMesh, sphereMesh, boxMesh; private CustomShaderBase phongShader; @Override public void createAllEntities() { MeshBuilder builder; Matrix3 identity = new Matrix3().idt(); - Entity marker; + Entity patch, sphere, box; // Create mesh. 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 n = new Vector3(0.0f, 1.0f, 0.0f); 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. Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Loading the phong shader."); @@ -71,15 +81,28 @@ public class MarkerTestEntityCreator extends EntityCreatorBase { // Create the entities. Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the enitites."); - marker = world.createEntity(); - marker.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)); - marker.addComponent(new ShaderComponent(phongShader)); - marker.addComponent(new MarkerCodeComponent(213)); + patch = world.createEntity(); + patch.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.0f), identity, new Vector3(1.0f, 1.0f, 1.0f))); + patch.addComponent(new MeshComponent(patchMesh)); + patch.addComponent(new ShaderComponent(phongShader)); + 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. Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Adding entities to the world."); - marker.addToWorld(); + sphere.addToWorld(); + patch.addToWorld(); + box.addToWorld(); } @Override @@ -87,7 +110,13 @@ public class MarkerTestEntityCreator extends EntityCreatorBase { if(phongShader != null && phongShader.getShaderProgram() != null) phongShader.getShaderProgram().dispose(); - if(markerMesh != null) - markerMesh.dispose(); + if(patchMesh != null) + patchMesh.dispose(); + + if(sphereMesh != null) + sphereMesh.dispose(); + + if(boxMesh != null) + boxMesh.dispose(); } } diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java index 81a0073..de7019a 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java +++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java @@ -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.MarkerTestEntityCreator; 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.interfaces.ImageProcessor.MarkerData; 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.controllers.Controller; import com.badlogic.gdx.controllers.mappings.Ouya; +import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Pixmap; @@ -52,13 +54,18 @@ import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.math.Vector3; public class InGameState extends BaseState{ - private static final String TAG = "IN_GAME_STATE"; - private static final String CLASS_NAME = InGameState.class.getSimpleName(); - private static final String BACKGROUND_SHADER_PATH = "shaders/bckg/bckg"; - private static final float NEAR = 0.01f; - private static final float FAR = 100.0f; - private static final float FAR_PLUS_NEAR = FAR + NEAR; - private static final float FAR_LESS_NEAR = FAR - NEAR; + private static final String TAG = "IN_GAME_STATE"; + private static final String CLASS_NAME = InGameState.class.getSimpleName(); + private static final String BACKGROUND_SHADER_PATH = "shaders/bckg/bckg"; + private static final float NEAR = 0.01f; + private static final float FAR = 100.0f; + private static final float FAR_PLUS_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. private float uScaling[]; @@ -175,6 +182,7 @@ public class InGameState extends BaseState{ frameBuffer = null; perspectiveCamera = null; frameBufferSprite = null; + RenderParameters.setLightSource1(new LightSource(LIGHT_POSITION, AMBIENT_COLOR, DIFFUSE_COLOR, SPECULAR_COLOR, SHINYNESS)); // Set up the game world. gameWorld = new World(); diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerPositioningSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerPositioningSystem.java index f544007..bfde1da 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerPositioningSystem.java +++ b/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerPositioningSystem.java @@ -62,17 +62,16 @@ public class MarkerPositioningSystem extends EntityProcessingSystem { Gdx.app.log(TAG, CLASS_NAME + ".process(): Processing markers."); for(int i = 0; i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){ if(markers.markerCodes[i] != 1){ + Gdx.app.log(TAG, CLASS_NAME + ".process(): Checking marker code: " + Integer.toString(markers.markerCodes[i])); + Gdx.app.log(TAG, CLASS_NAME + ".process(): This entity's code is: " + Integer.toString(marker.code)); if(markers.markerCodes[i] == marker.code){ Gdx.app.log(TAG, CLASS_NAME + ".process(): Processing marker code " + Integer.toString(markers.markerCodes[i]) + "."); geometry.position.set(markers.translationVectors[i]); geometry.rotation.set(markers.rotationMatrices[i]); - break; } }else{ Gdx.app.log(TAG, CLASS_NAME + ".process(): Skipping marker number " + Integer.toString(i) + "."); } } - - markers = null; } } diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerRenderingSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerRenderingSystem.java index 2f72ac8..f09714b 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerRenderingSystem.java +++ b/src/ve/ucv/ciens/ccg/nxtar/systems/MarkerRenderingSystem.java @@ -82,6 +82,8 @@ public class MarkerRenderingSystem extends EntityProcessingSystem { Gdx.app.log(TAG, CLASS_NAME + ".process(): Processing markers."); for(int i = 0; i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){ if(markers.markerCodes[i] != 1){ + Gdx.app.log(TAG, CLASS_NAME + ".process(): Checking marker code: " + Integer.toString(markers.markerCodes[i])); + Gdx.app.log(TAG, CLASS_NAME + ".process(): This entity's code is: " + Integer.toString(marker.code)); if(markers.markerCodes[i] == marker.code){ Gdx.app.log(TAG, CLASS_NAME + ".process(): Rendering marker code " + Integer.toString(markers.markerCodes[i]) + "."); // Set the geometric transformations. @@ -113,15 +115,11 @@ public class MarkerRenderingSystem extends EntityProcessingSystem { shaderComp.shader.setUniforms(); meshComp.model.render(shaderComp.shader.getShaderProgram(), GL20.GL_TRIANGLES); }shaderComp.shader.getShaderProgram().end(); - - break; } }else{ Gdx.app.log(TAG, CLASS_NAME + ".process(): Skipping marker number " + Integer.toString(i) + "."); } } - - markers = null; } } diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/ObjectRenderingSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/ObjectRenderingSystem.java index 6d0b9d3..4934608 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/systems/ObjectRenderingSystem.java +++ b/src/ve/ucv/ciens/ccg/nxtar/systems/ObjectRenderingSystem.java @@ -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.MeshComponent; 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 com.artemis.Aspect; @@ -27,10 +26,8 @@ import com.artemis.ComponentMapper; import com.artemis.Entity; import com.artemis.annotations.Mapper; import com.artemis.systems.EntityProcessingSystem; -import com.badlogic.gdx.graphics.Color; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.math.Matrix4; -import com.badlogic.gdx.math.Vector3; /** *

Entity processing system in charge of rendering 3D objects using OpenGL. The @@ -41,12 +38,6 @@ public class ObjectRenderingSystem extends EntityProcessingSystem { @Mapper ComponentMapper shaderMapper; @Mapper ComponentMapper 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; - /** *

A matrix representing 3D translations.

*/ @@ -71,8 +62,6 @@ public class ObjectRenderingSystem extends EntityProcessingSystem { public ObjectRenderingSystem() { 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); rotationMatrix = new Matrix4().idt(); scalingMatrix = new Matrix4().setToScaling(0.0f, 0.0f, 0.0f);