Added visibility testing for marker objects.

This commit is contained in:
2014-06-03 18:49:52 -04:30
parent e65da3234b
commit 6ecb373b11
7 changed files with 168 additions and 270 deletions

View File

@@ -18,6 +18,7 @@ package ve.ucv.ciens.ccg.nxtar.entities;
import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent;
import ve.ucv.ciens.ccg.nxtar.components.BombComponent;
import ve.ucv.ciens.ccg.nxtar.components.BombComponent.bomb_type_t;
import ve.ucv.ciens.ccg.nxtar.components.CollisionModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
@@ -63,21 +64,35 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private EntityParameters parameters;
private Shader shader;
private Model doorModel;
private Model doorFrameModel;
private Model bombModelCombination;
private Model bombModelInclination;
private Model bombModelWires;
private Model bombModelWiresWire1;
private Model bombModelWiresWire2;
private Model bombModelWiresWire3;
private Model easterEggModel;
private int currentBombId;
// Render models.
private Model doorModel = null;
private Model doorFrameModel = null;
private Model combinationBombModel = null;
private Model inclinationBombModel = null;
private Model wiresBombModel = null;
private Model wiresBombModelWire1 = null;
private Model wiresBombModelWire2 = null;
private Model wiresBombModelWire3 = null;
private Model easterEggModel = null;
// Collision models.
private Model doorCollisionModel = null;
private Model doorFrameCollisionModel = null;
private Model combinationBombCollisionModel = null;
private Model inclinationBombCollisionModel = null;
private Model wiresBombCollisionModel = null;
private Model wiresBombCollisionModelWire1 = null;
private Model wiresBombCollisionModelWire2 = null;
private Model wiresBombCollisionModelWire3 = null;
private Model easterEggCollisionModel = null;
public BombGameEntityCreator(){
G3dModelLoader loader = new G3dModelLoader(new UBJsonReader());
currentBombId = 0;
// Create and set the lighting.
parameters = new EntityParameters();
parameters.environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.0f));
parameters.environment.add(new DirectionalLight().set(new Color(1, 1, 1, 1), new Vector3(0, 0, -1)));
@@ -92,18 +107,27 @@ public class BombGameEntityCreator extends EntityCreatorBase{
}
parameters.shader = shader;
// Create the models.
// TODO: Set the correct model paths.
// TODO: Load collision models.
// Load the render models.
doorModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/door.g3db"));
doorFrameModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/door_frame1.g3db"));
// bombModelCombination = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
// bombModelInclination = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
bombModelWires = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_1_body.g3db"));
// easterEggModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
bombModelWiresWire1 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_1.g3db"));
bombModelWiresWire2 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_2.g3db"));
bombModelWiresWire3 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_3.g3db"));
// bombModelCombination = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
// bombModelInclination = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
wiresBombModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/bomb_1_body.g3db"));
wiresBombModelWire1 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_1.g3db"));
wiresBombModelWire2 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_2.g3db"));
wiresBombModelWire3 = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/cable_3.g3db"));
// easterEggModel = loader.loadModel(Gdx.files.internal("models/render_models/bomb_game/"));
// Load the collision models.
doorCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door_col.g3db"));
doorFrameCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door_frame1_col.g3db"));
// combinationBombCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door.g3db"));
// inclinationBombCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door.g3db"));
wiresBombCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/bomb_1_body_col.g3db"));
wiresBombCollisionModelWire1 = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/cable_1_col.g3db"));
wiresBombCollisionModelWire2 = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/cable_2_col.g3db"));
wiresBombCollisionModelWire3 = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/cable_3_col.g3db"));
// easterEggCollisionModel = loader.loadModel(Gdx.files.internal("models/collision_models/bomb_game/door.g3db"));
}
@Override
@@ -111,11 +135,11 @@ public class BombGameEntityCreator extends EntityCreatorBase{
// TODO: Add the robot arms.
// Add bombs.
// parameters.markerCode = 89;
// addBomb(parameters, bomb_type_t.COMBINATION);
//
// parameters.markerCode = 90;
// addBomb(parameters, bomb_type_t.INCLINATION);
// parameters.markerCode = 89;
// addBomb(parameters, bomb_type_t.COMBINATION);
//
// parameters.markerCode = 90;
// addBomb(parameters, bomb_type_t.INCLINATION);
parameters.markerCode = 91;
addBomb(parameters, bomb_type_t.WIRES);
@@ -124,44 +148,48 @@ public class BombGameEntityCreator extends EntityCreatorBase{
parameters.nextAnimation = 1;
parameters.loopAnimation = false;
// parameters.markerCode = 89;
// addDoor(parameters);
// parameters.markerCode = 90;
// addDoor(parameters);
// parameters.markerCode = 89;
// addDoor(parameters);
// parameters.markerCode = 90;
// addDoor(parameters);
parameters.markerCode = 91;
addDoor(parameters);
// TODO: Add easter egg.
}
@Override
public void dispose() {
if(shader != null)
shader.dispose();
if(shader != null) shader.dispose();
// Dispose of the models.
if(doorModel != null)
doorModel.dispose();
if(doorFrameModel != null)
doorFrameModel.dispose();
if(bombModelCombination != null)
bombModelCombination.dispose();
if(bombModelInclination != null)
bombModelInclination.dispose();
if(bombModelWires != null)
bombModelWires.dispose();
if(bombModelWiresWire1 != null)
bombModelWiresWire1.dispose();
if(bombModelWiresWire2 != null)
bombModelWiresWire2.dispose();
if(bombModelWiresWire3 != null)
bombModelWiresWire3.dispose();
if(easterEggModel != null)
easterEggModel.dispose();
// Dispose of the render models.
if(doorModel != null) doorModel.dispose();
if(doorFrameModel != null) doorFrameModel.dispose();
if(combinationBombModel != null) combinationBombModel.dispose();
if(inclinationBombModel != null) inclinationBombModel.dispose();
if(wiresBombModel != null) wiresBombModel.dispose();
if(wiresBombModelWire1 != null) wiresBombModelWire1.dispose();
if(wiresBombModelWire2 != null) wiresBombModelWire2.dispose();
if(wiresBombModelWire3 != null) wiresBombModelWire3.dispose();
if(easterEggModel != null) easterEggModel.dispose();
// Dispose of the collision models.
if(doorCollisionModel != null) doorCollisionModel.dispose();
if(doorFrameCollisionModel != null) doorFrameCollisionModel.dispose();
if(combinationBombCollisionModel != null) combinationBombCollisionModel.dispose();
if(inclinationBombCollisionModel != null) inclinationBombCollisionModel.dispose();
if(wiresBombCollisionModel != null) wiresBombCollisionModel.dispose();
if(wiresBombCollisionModelWire1 != null) wiresBombCollisionModelWire1.dispose();
if(wiresBombCollisionModelWire2 != null) wiresBombCollisionModelWire2.dispose();
if(wiresBombCollisionModelWire3 != null) wiresBombCollisionModelWire3.dispose();
if(easterEggCollisionModel != null) easterEggCollisionModel.dispose();
}
private void addBomb(EntityParameters parameters, bomb_type_t type) throws IllegalArgumentException{
Entity bomb;
BombComponent bombComponent = new BombComponent(currentBombId, type);
// Create a bomb entity and add it's generic components.
bomb = world.createEntity();
bomb.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
bomb.addComponent(new EnvironmentComponent(parameters.environment));
@@ -172,28 +200,42 @@ public class BombGameEntityCreator extends EntityCreatorBase{
// Add the collision and render models depending on the bomb type.
if(type == bomb_type_t.COMBINATION){
bomb.addComponent(new RenderModelComponent(bombModelCombination));
bomb.addComponent(new RenderModelComponent(combinationBombModel));
bomb.addComponent(new CollisionModelComponent(combinationBombCollisionModel));
addBombCombinationButtons(parameters, bombComponent);
}else if(type == bomb_type_t.INCLINATION){
bomb.addComponent(new RenderModelComponent(bombModelInclination));
bomb.addComponent(new RenderModelComponent(inclinationBombModel));
bomb.addComponent(new CollisionModelComponent(inclinationBombCollisionModel));
addBombInclinationButton(parameters, bombComponent);
}else if(type == bomb_type_t.WIRES){
bomb.addComponent(new RenderModelComponent(bombModelWires));
bomb.addComponent(new RenderModelComponent(wiresBombModel));
bomb.addComponent(new CollisionModelComponent(wiresBombCollisionModel));
addBombWires(parameters, bombComponent);
}else
throw new IllegalArgumentException("Unrecognized bomb type: " + Integer.toString(type.getValue()));
// Add the bomb and increase the id for the next one.
bomb.addToWorld();
currentBombId++;
}
private void addBombCombinationButtons(EntityParameters parameters, BombComponent bomb){
// TODO: Add the buttons.
}
private void addBombInclinationButton(EntityParameters parameters, BombComponent bomb){
// TODO: Add the button.
}
private void addBombWires(EntityParameters parameters, BombComponent bomb){
// TODO: Add collision models.
Entity wire1, wire2, wire3;
wire1 = world.createEntity();
wire1.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
wire1.addComponent(new EnvironmentComponent(parameters.environment));
wire1.addComponent(new ShaderComponent(parameters.shader));
wire1.addComponent(new RenderModelComponent(bombModelWiresWire1));
wire1.addComponent(new RenderModelComponent(wiresBombModelWire1));
wire1.addComponent(new CollisionModelComponent(wiresBombCollisionModelWire1));
wire1.addComponent(new BombComponent(bomb));
wire1.addComponent(new VisibilityComponent());
wire1.addComponent(new MarkerCodeComponent(parameters.markerCode));
@@ -203,7 +245,8 @@ public class BombGameEntityCreator extends EntityCreatorBase{
wire2.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
wire2.addComponent(new EnvironmentComponent(parameters.environment));
wire2.addComponent(new ShaderComponent(parameters.shader));
wire2.addComponent(new RenderModelComponent(bombModelWiresWire2));
wire2.addComponent(new RenderModelComponent(wiresBombModelWire2));
wire2.addComponent(new CollisionModelComponent(wiresBombCollisionModelWire2));
wire2.addComponent(new BombComponent(bomb));
wire2.addComponent(new VisibilityComponent());
wire2.addComponent(new MarkerCodeComponent(parameters.markerCode));
@@ -213,7 +256,8 @@ public class BombGameEntityCreator extends EntityCreatorBase{
wire3.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
wire3.addComponent(new EnvironmentComponent(parameters.environment));
wire3.addComponent(new ShaderComponent(parameters.shader));
wire3.addComponent(new RenderModelComponent(bombModelWiresWire3));
wire3.addComponent(new RenderModelComponent(wiresBombModelWire3));
wire3.addComponent(new CollisionModelComponent(wiresBombCollisionModelWire3));
wire3.addComponent(new BombComponent(bomb));
wire3.addComponent(new VisibilityComponent());
wire3.addComponent(new MarkerCodeComponent(parameters.markerCode));
@@ -221,30 +265,29 @@ public class BombGameEntityCreator extends EntityCreatorBase{
}
private void addDoor(EntityParameters parameters){
// TODO: Add collision models.
ModelInstance doorInstance;
Entity frame, door;
frame = world.createEntity();
frame.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
frame.addComponent(new RenderModelComponent(doorFrameModel));
frame.addComponent(new CollisionModelComponent(doorFrameCollisionModel));
frame.addComponent(new EnvironmentComponent(parameters.environment));
frame.addComponent(new ShaderComponent(parameters.shader));
frame.addComponent(new VisibilityComponent());
frame.addComponent(new MarkerCodeComponent(parameters.markerCode));
frame.addToWorld();
door = world.createEntity();
door.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
door.addComponent(new RenderModelComponent(doorModel));
door.addComponent(new CollisionModelComponent(doorCollisionModel));
door.addComponent(new EnvironmentComponent(parameters.environment));
door.addComponent(new ShaderComponent(parameters.shader));
door.addComponent(new MarkerCodeComponent(parameters.markerCode));
door.addComponent(new VisibilityComponent());
doorInstance = door.getComponent(RenderModelComponent.class).instance;
door.addComponent(new AnimationComponent(doorInstance, parameters.nextAnimation, parameters.loopAnimation));
door.addToWorld();
}
}

View File

@@ -27,22 +27,47 @@ public class CustomPerspectiveCamera extends PerspectiveCamera{
private final Vector3 tmp = new Vector3();
public CustomPerspectiveCamera(float fieldOfView, float viewportWidth, float viewportHeight){
this.fieldOfView = fieldOfView;
this.viewportWidth = viewportWidth;
this.viewportHeight = viewportHeight;
super(fieldOfView, viewportWidth, viewportHeight);
update();
}
public void update(Matrix4 customProjection){
this.update(customProjection, true);
}
public void update(Matrix4 customProjection, boolean updateFrustum){
projection.set(customProjection);
view.setToLookAt(position, tmp.set(position).add(direction), up);
combined.set(projection);
Matrix4.mul(combined.val, view.val);
combined.set(projection).mul(view);
if(updateFrustum){
invProjectionView.set(combined);
Matrix4.inv(invProjectionView.val);
invProjectionView.set(combined).inv();
frustum.update(invProjectionView);
}
}
public void setCustomARProjectionMatrix(final float focalPointX, final float focalPointY, final float cameraCenterX, final float cameraCenterY, final float near, final float far, final float w, final float h){
final float FAR_PLUS_NEAR = far + near;
final float FAR_LESS_NEAR = far - near;
projection.val[Matrix4.M00] = -2.0f * focalPointX / w;
projection.val[Matrix4.M10] = 0.0f;
projection.val[Matrix4.M20] = 0.0f;
projection.val[Matrix4.M30] = 0.0f;
projection.val[Matrix4.M01] = 0.0f;
projection.val[Matrix4.M11] = 2.0f * focalPointY / h;
projection.val[Matrix4.M21] = 0.0f;
projection.val[Matrix4.M31] = 0.0f;
projection.val[Matrix4.M02] = 2.0f * cameraCenterX / w - 1.0f;
projection.val[Matrix4.M12] = 2.0f * cameraCenterY / h - 1.0f;
projection.val[Matrix4.M22] = -FAR_PLUS_NEAR / FAR_LESS_NEAR;
projection.val[Matrix4.M32] = -1.0f;
projection.val[Matrix4.M03] = 0.0f;
projection.val[Matrix4.M13] = 0.0f;
projection.val[Matrix4.M23] = -2.0f * far * near / FAR_LESS_NEAR;
projection.val[Matrix4.M33] = 0.0f;
}
}

View File

@@ -27,8 +27,8 @@ import ve.ucv.ciens.ccg.nxtar.systems.AnimationSystem;
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.ObjectPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.VisibilitySystem;
import ve.ucv.ciens.ccg.nxtar.utils.GameSettings;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
@@ -49,7 +49,6 @@ 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.ShaderProgram;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.math.Vector3;
@@ -59,8 +58,6 @@ public class InGameState extends BaseState{
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;
// Background related fields.
private float uScaling[];
@@ -70,7 +67,6 @@ public class InGameState extends BaseState{
// 3D rendering fields.
private ModelBatch modelBatch;
private Matrix4 projectionMatrix;
private FrameBuffer frameBuffer;
private Sprite frameBufferSprite;
@@ -176,7 +172,6 @@ public class InGameState extends BaseState{
// Set up the 3D rendering.
modelBatch = new ModelBatch();
projectionMatrix = new Matrix4().idt();
frameBuffer = null;
perspectiveCamera = null;
frameBufferSprite = null;
@@ -189,11 +184,10 @@ public class InGameState extends BaseState{
GameSettings.entityCreator.createAllEntities();
gameWorld.setSystem(new MarkerPositioningSystem());
// TODO: Make and add positioning systems.
gameWorld.setSystem(new ObjectPositioningSystem(), true);
gameWorld.setSystem(new GeometrySystem());
//gameWorld.setSystem(new VisibilitySystem());
gameWorld.setSystem(new AnimationSystem());
// TODO: Add collision system.
// TODO: Make and add object-marker collision detection system.
//gameWorld.setSystem(GameSettings.gameLogicSystem);
markerRenderingSystem = new MarkerRenderingSystem(modelBatch);
@@ -247,8 +241,6 @@ public class InGameState extends BaseState{
perspectiveCamera.far = FAR;
perspectiveCamera.lookAt(0.0f, 0.0f, -1.0f);
perspectiveCamera.update();
// gameWorld.getSystem(VisibilitySystem.class).setCamera(perspectiveCamera);
}
// Attempt to find the markers in the current video frame.
@@ -256,6 +248,14 @@ public class InGameState extends BaseState{
// If a valid frame was fetched.
if(data != null && data.outFrame != null){
// Set the camera to the correct projection.
focalPointX = core.cvProc.getFocalPointX();
focalPointY = core.cvProc.getFocalPointY();
cameraCenterX = core.cvProc.getCameraCenterX();
cameraCenterY = core.cvProc.getCameraCenterY();
perspectiveCamera.setCustomARProjectionMatrix(focalPointX, focalPointY, cameraCenterX, cameraCenterY, NEAR, FAR, w, h);
perspectiveCamera.update(perspectiveCamera.projection);
// Update the game state.
gameWorld.setDelta(Gdx.graphics.getDeltaTime() * 1000);
gameWorld.getSystem(MarkerPositioningSystem.class).setMarkerData(data);
@@ -283,37 +283,8 @@ public class InGameState extends BaseState{
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT | GL20.GL_DEPTH_BUFFER_BIT);
Gdx.gl.glDisable(GL20.GL_TEXTURE_2D);
// Build the projection matrix.
focalPointX = core.cvProc.getFocalPointX();
focalPointY = core.cvProc.getFocalPointY();
cameraCenterX = core.cvProc.getCameraCenterX();
cameraCenterY = core.cvProc.getCameraCenterY();
projectionMatrix.val[Matrix4.M00] = -2.0f * focalPointX / w;
projectionMatrix.val[Matrix4.M10] = 0.0f;
projectionMatrix.val[Matrix4.M20] = 0.0f;
projectionMatrix.val[Matrix4.M30] = 0.0f;
projectionMatrix.val[Matrix4.M01] = 0.0f;
projectionMatrix.val[Matrix4.M11] = 2.0f * focalPointY / h;
projectionMatrix.val[Matrix4.M21] = 0.0f;
projectionMatrix.val[Matrix4.M31] = 0.0f;
projectionMatrix.val[Matrix4.M02] = 2.0f * cameraCenterX / w - 1.0f;
projectionMatrix.val[Matrix4.M12] = 2.0f * cameraCenterY / h - 1.0f;
projectionMatrix.val[Matrix4.M22] = -FAR_PLUS_NEAR / FAR_LESS_NEAR;
projectionMatrix.val[Matrix4.M32] = -1.0f;
projectionMatrix.val[Matrix4.M03] = 0.0f;
projectionMatrix.val[Matrix4.M13] = 0.0f;
projectionMatrix.val[Matrix4.M23] = -2.0f * FAR * NEAR / FAR_LESS_NEAR;
projectionMatrix.val[Matrix4.M33] = 0.0f;
// Set rendering parameters.
perspectiveCamera.update(projectionMatrix, true);
// Call rendering systems.
markerRenderingSystem.begin(perspectiveCamera, data);
markerRenderingSystem.begin(perspectiveCamera);
markerRenderingSystem.process();
markerRenderingSystem.end();

View File

@@ -28,8 +28,8 @@ import com.badlogic.gdx.graphics.g3d.ModelInstance;
import com.badlogic.gdx.math.Matrix4;
public class GeometrySystem extends EntityProcessingSystem {
@Mapper ComponentMapper<GeometryComponent> geometryMapper;
@Mapper ComponentMapper<RenderModelComponent> renderModelMapper;
@Mapper ComponentMapper<GeometryComponent> geometryMapper;
@Mapper ComponentMapper<RenderModelComponent> renderModelMapper;
@Mapper ComponentMapper<CollisionModelComponent> colModelMapper;
/**

View File

@@ -17,6 +17,7 @@ package ve.ucv.ciens.ccg.nxtar.systems;
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
@@ -25,20 +26,17 @@ import com.artemis.ComponentMapper;
import com.artemis.Entity;
import com.artemis.annotations.Mapper;
import com.artemis.systems.EntityProcessingSystem;
import com.badlogic.gdx.Gdx;
public class MarkerPositioningSystem extends EntityProcessingSystem {
@Mapper ComponentMapper<MarkerCodeComponent> markerMapper;
@Mapper ComponentMapper<GeometryComponent> geometryMapper;
private static final String TAG = "MARKER_POSITIONING_SYSTEM";
private static final String CLASS_NAME = MarkerPositioningSystem.class.getSimpleName();
@Mapper ComponentMapper<GeometryComponent> geometryMapper;
@Mapper ComponentMapper<VisibilityComponent> visibilityMapper;
private MarkerData markers;
@SuppressWarnings("unchecked")
public MarkerPositioningSystem(){
super(Aspect.getAspectForAll(MarkerCodeComponent.class, GeometryComponent.class));
super(Aspect.getAspectForAll(MarkerCodeComponent.class, GeometryComponent.class, VisibilityComponent.class));
markers = null;
}
@@ -51,26 +49,25 @@ public class MarkerPositioningSystem extends EntityProcessingSystem {
protected void process(Entity e) {
MarkerCodeComponent marker;
GeometryComponent geometry;
VisibilityComponent visibility;
if(markers == null)
return;
Gdx.app.log(TAG, CLASS_NAME + ".process(): Getting components.");
marker = markerMapper.get(e);
geometry = geometryMapper.get(e);
marker = markerMapper.get(e);
geometry = geometryMapper.get(e);
visibility = visibilityMapper.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){
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]);
visibility.visible = true;
break;
}else{
visibility.visible = false;
}
}else{
Gdx.app.log(TAG, CLASS_NAME + ".process(): Skipping marker number " + Integer.toString(i) + ".");
}
}
}

View File

@@ -16,74 +16,40 @@
package ve.ucv.ciens.ccg.nxtar.systems;
import ve.ucv.ciens.ccg.nxtar.components.EnvironmentComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
import ve.ucv.ciens.ccg.nxtar.components.RenderModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
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;
public class MarkerRenderingSystem extends EntityProcessingSystem {
@Mapper ComponentMapper<MarkerCodeComponent> markerMapper;
// @Mapper ComponentMapper<GeometryComponent> geometryMapper;
// @Mapper ComponentMapper<MarkerCodeComponent> markerMapper;
@Mapper ComponentMapper<RenderModelComponent> modelMapper;
@Mapper ComponentMapper<EnvironmentComponent> environmentMapper;
@Mapper ComponentMapper<ShaderComponent> shaderMapper;
@Mapper ComponentMapper<VisibilityComponent> visibiltyMapper;
private static final String TAG = "MODEL_BATCH_MARKER_RENDERING_SYSTEM";
private static final String CLASS_NAME = MarkerRenderingSystem.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 MarkerRenderingSystem(ModelBatch batch){
super(Aspect.getAspectForAll(MarkerCodeComponent.class, /*GeometryComponent.class,*/ ShaderComponent.class, EnvironmentComponent.class, RenderModelComponent.class, VisibilityComponent.class));
super(Aspect.getAspectForAll(ShaderComponent.class, EnvironmentComponent.class, RenderModelComponent.class, VisibilityComponent.class));
markers = null;
camera = null;
this.batch = batch;
// translationMatrix = new Matrix4().setToTranslation(0.0f, 0.0f, 0.0f);
// rotationMatrix = new Matrix4().idt();
// scalingMatrix = new Matrix4().setToScaling(0.0f, 0.0f, 0.0f);
camera = null;
this.batch = batch;
}
public void begin(PerspectiveCamera camera, MarkerData markers) throws RuntimeException{
public void begin(PerspectiveCamera camera) 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);
}
@@ -91,71 +57,26 @@ public class MarkerRenderingSystem extends EntityProcessingSystem {
public void end(){
batch.end();
camera = null;
markers = null;
}
@Override
protected void process(Entity e) {
MarkerCodeComponent marker;
// GeometryComponent geometry;
EnvironmentComponent environment;
RenderModelComponent model;
ShaderComponent shader;
VisibilityComponent visibility;
if(markers == null || camera == null)
if(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);
visibility = visibiltyMapper.get(e);
if(visibility.visible){
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) + ".");
}
}
// Render the marker;
batch.render(model.instance, environment.environment, shader.shader);
}
}
}

View File

@@ -1,59 +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.CollisionModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
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.graphics.PerspectiveCamera;
import com.badlogic.gdx.math.collision.BoundingBox;
public class VisibilitySystem extends EntityProcessingSystem {
@Mapper ComponentMapper<VisibilityComponent> visibilityMapper;
@Mapper ComponentMapper<GeometryComponent> geometryMapper;
@Mapper ComponentMapper<CollisionModelComponent> collisionMapper;
private PerspectiveCamera camera;
@SuppressWarnings("unchecked")
public VisibilitySystem(){
super(Aspect.getAspectForAll(VisibilityComponent.class, CollisionModelComponent.class));
this.camera = null;
}
public void setCamera(PerspectiveCamera camera){
this.camera = camera;
}
@Override
protected void process(Entity e){
VisibilityComponent visibility = visibilityMapper.get(e);
CollisionModelComponent colModel = collisionMapper.get(e);
BoundingBox bBox = new BoundingBox();
if(camera != null){
colModel.instance.calculateBoundingBox(bBox);
bBox.mul(colModel.instance.transform);
visibility.visible = camera.frustum.boundsInFrustum(bBox);
}
}
}