From 238f62d4d3723f187c2120c5236809ad0750c1e5 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 30 Jun 2014 12:42:43 -0430 Subject: [PATCH] Added robot arm movement ray rendering. --- .../ccg/nxtar/scenarios/ScenarioGlobals.java | 4 +- .../ciens/ccg/nxtar/states/InGameState.java | 14 +++--- .../systems/RobotArmPositioningSystem.java | 4 +- ...stem.java => RobotArmRenderingSystem.java} | 43 +++++++++++++++++-- 4 files changed, 51 insertions(+), 14 deletions(-) rename src/ve/ucv/ciens/ccg/nxtar/systems/{ObjectRenderingSystem.java => RobotArmRenderingSystem.java} (52%) diff --git a/src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioGlobals.java b/src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioGlobals.java index 864df04..267d609 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioGlobals.java +++ b/src/ve/ucv/ciens/ccg/nxtar/scenarios/ScenarioGlobals.java @@ -24,7 +24,7 @@ import ve.ucv.ciens.ccg.nxtar.systems.GameLogicSystemBase; import ve.ucv.ciens.ccg.nxtar.systems.GeometrySystem; import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem; import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem; -import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem; +import ve.ucv.ciens.ccg.nxtar.systems.RobotArmRenderingSystem; import ve.ucv.ciens.ccg.nxtar.systems.PlayerSystemBase; import ve.ucv.ciens.ccg.nxtar.systems.RobotArmPositioningSystem; @@ -154,7 +154,7 @@ public abstract class ScenarioGlobals{ gameWorld.setSystem(gameLogicSystem); gameWorld.setSystem(playerSystem, true); gameWorld.setSystem(new MarkerRenderingSystem(modelBatch), true); - gameWorld.setSystem(new ObjectRenderingSystem(modelBatch), true); + gameWorld.setSystem(new RobotArmRenderingSystem(modelBatch), true); gameWorld.setSystem(new FadeEffectRenderingSystem(), true); gameWorld.initialize(); diff --git a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java index 66a73cf..e2a7e4c 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java +++ b/src/ve/ucv/ciens/ccg/nxtar/states/InGameState.java @@ -32,7 +32,7 @@ import ve.ucv.ciens.ccg.nxtar.systems.CollisionDetectionSystem; import ve.ucv.ciens.ccg.nxtar.systems.FadeEffectRenderingSystem; import ve.ucv.ciens.ccg.nxtar.systems.MarkerPositioningSystem; import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem; -import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem; +import ve.ucv.ciens.ccg.nxtar.systems.RobotArmRenderingSystem; import ve.ucv.ciens.ccg.nxtar.systems.PlayerSystemBase; import ve.ucv.ciens.ccg.nxtar.systems.RobotArmPositioningSystem; import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants; @@ -98,7 +98,7 @@ public class InGameState extends BaseState{ // Game related fields. private World gameWorld; private MarkerRenderingSystem markerRenderingSystem; - private ObjectRenderingSystem objectRenderingSystem; + private RobotArmRenderingSystem robotArmRenderingSystem; private RobotArmPositioningSystem robotArmPositioningSystem; private FadeEffectRenderingSystem fadeEffectRenderingSystem; private PlayerSystemBase playerSystem; @@ -249,11 +249,11 @@ public class InGameState extends BaseState{ robotArmPositioningSystem = gameWorld.getSystem(RobotArmPositioningSystem.class); markerRenderingSystem = gameWorld.getSystem(MarkerRenderingSystem.class); - objectRenderingSystem = gameWorld.getSystem(ObjectRenderingSystem.class); + robotArmRenderingSystem = gameWorld.getSystem(RobotArmRenderingSystem.class); fadeEffectRenderingSystem = gameWorld.getSystem(FadeEffectRenderingSystem.class); playerSystem = ScenarioGlobals.getPlayerSystem(); - if(robotArmPositioningSystem == null || markerRenderingSystem == null || objectRenderingSystem == null || fadeEffectRenderingSystem == null) + if(robotArmPositioningSystem == null || markerRenderingSystem == null || robotArmRenderingSystem == null || fadeEffectRenderingSystem == null) throw new IllegalStateException("One or more essential systems are null."); } @@ -357,9 +357,9 @@ public class InGameState extends BaseState{ markerRenderingSystem.end(); if(controlMode.getValue() == robot_control_mode_t.ARM_CONTROL.getValue() || Ouya.runningOnOuya){ - objectRenderingSystem.begin(perspectiveCamera); - objectRenderingSystem.process(); - objectRenderingSystem.end(); + robotArmRenderingSystem.begin(perspectiveCamera); + robotArmRenderingSystem.process(); + robotArmRenderingSystem.end(); } }frameBuffer.end(); diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java index daab97a..84ab364 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java +++ b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmPositioningSystem.java @@ -39,8 +39,8 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem { private static final String CLASS_NAME = RobotArmPositioningSystem.class.getSimpleName(); private static final float INTERPOLATION_STEP = 0.05f; private static final float STEP_SIZE = 0.05f; - private static final float MAX_Z = -4.5f; - private static final float MIN_Z = -1.0f; + public static final float MAX_Z = -4.5f; + public static final float MIN_Z = -1.0f; @Mapper ComponentMapper geometryMapper; @Mapper ComponentMapper autoMapper; diff --git a/src/ve/ucv/ciens/ccg/nxtar/systems/ObjectRenderingSystem.java b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmRenderingSystem.java similarity index 52% rename from src/ve/ucv/ciens/ccg/nxtar/systems/ObjectRenderingSystem.java rename to src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmRenderingSystem.java index bdf9654..ed7f4dc 100644 --- a/src/ve/ucv/ciens/ccg/nxtar/systems/ObjectRenderingSystem.java +++ b/src/ve/ucv/ciens/ccg/nxtar/systems/RobotArmRenderingSystem.java @@ -16,6 +16,7 @@ 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.RenderModelComponent; import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent; @@ -25,27 +26,49 @@ 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.PerspectiveCamera; +import com.badlogic.gdx.graphics.VertexAttributes.Usage; +import com.badlogic.gdx.graphics.g3d.Material; +import com.badlogic.gdx.graphics.g3d.Model; import com.badlogic.gdx.graphics.g3d.ModelBatch; +import com.badlogic.gdx.graphics.g3d.ModelInstance; +import com.badlogic.gdx.graphics.g3d.attributes.ColorAttribute; +import com.badlogic.gdx.graphics.g3d.utils.ModelBuilder; +import com.badlogic.gdx.math.Vector3; +import com.badlogic.gdx.utils.Disposable; /** *

Entity processing system in charge of rendering 3D objects using OpenGL. The * entities to be rendered must have a geometry, shader and mesh component associated.

*/ -public class ObjectRenderingSystem extends EntityProcessingSystem { +public class RobotArmRenderingSystem extends EntityProcessingSystem implements Disposable{ @Mapper ComponentMapper shaderMapper; @Mapper ComponentMapper modelMapper; @Mapper ComponentMapper environmentMapper; + @Mapper ComponentMapper geometryMapper; private PerspectiveCamera camera; - private ModelBatch batch; + private ModelBatch batch; + private Model lineModel; + private ModelInstance lineInstance; + private Vector3 temp; @SuppressWarnings("unchecked") - public ObjectRenderingSystem(ModelBatch batch) { + public RobotArmRenderingSystem(ModelBatch batch) { super(Aspect.getAspectForAll(ShaderComponent.class, RenderModelComponent.class, EnvironmentComponent.class).exclude(MarkerCodeComponent.class)); camera = null; this.batch = batch; +// MeshBuilder builder = new MeshBuilder(); +// builder.begin(new VertexAttributes(new VertexAttribute(Usage.Position, 4, "a_position"), new VertexAttribute(Usage.Color, 4, "a_color")), GL20.GL_LINES);{ +// builder.line(new Vector3(0.0f, 0.0f, RobotArmPositioningSystem.MIN_Z), Color.YELLOW, new Vector3(0.0f, 0.0f, RobotArmPositioningSystem.MAX_Z), Color.YELLOW); +// }lineMesh = builder.end(); +// lineModel = ModelBuilder.createFromMesh(lineMesh, GL20.GL_LINES, new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.YELLOW))); +// lineModel = new ModelBuilder().createArrow(new Vector3(0.0f, 0.0f, RobotArmPositioningSystem.MIN_Z), new Vector3(0.0f, 0.0f, RobotArmPositioningSystem.MAX_Z), new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.YELLOW)), Usage.Position | Usage.Color | Usage.Normal); + lineModel = new ModelBuilder().createBox(0.01f, 0.01f, 3.5f, new Material(new ColorAttribute(ColorAttribute.Diffuse, Color.YELLOW)), Usage.Position | Usage.Color | Usage.Normal); + lineInstance = new ModelInstance(lineModel); + temp = new Vector3(); } public void begin(PerspectiveCamera camera) throws RuntimeException{ @@ -66,13 +89,27 @@ public class ObjectRenderingSystem extends EntityProcessingSystem { EnvironmentComponent environment; ShaderComponent shaderComponent; RenderModelComponent renderModelComponent; + GeometryComponent geometry; // Get the necessary components. renderModelComponent = modelMapper.get(e); shaderComponent = shaderMapper.get(e); environment = environmentMapper.get(e); + geometry = geometryMapper.getSafe(e); + + if(geometry != null){ + temp.set(geometry.position.x, geometry.position.y, -2.5f); + lineInstance.transform.idt().setToTranslation(temp); + } // Render this entity. batch.render(renderModelComponent.instance, environment.environment, shaderComponent.shader); + batch.render(lineInstance, environment.environment, shaderComponent.shader); + } + + @Override + public void dispose() { + if(lineModel != null) + lineModel.dispose(); } }