Added more systems and components.

This commit is contained in:
2014-06-02 16:46:06 -04:30
parent eb8206668f
commit a614841664
14 changed files with 542 additions and 356 deletions

View File

@@ -0,0 +1,50 @@
/*
* 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.components;
import com.artemis.Component;
public class BombComponent extends Component {
public enum bomb_type_t{
COMBINATION(0), INCLINATION(1), WIRES(2);
private int value;
private bomb_type_t(int value){
this.value = value;
}
public int getValue(){
return this.value;
}
};
public int id;
public bomb_type_t bombType;
public boolean enabled;
public BombComponent(int id, bomb_type_t bomb_type){
this.id = id;
this.bombType = bomb_type;
this.enabled = true;
}
public BombComponent(BombComponent bomb){
this.id = bomb.id;
this.bombType = bomb.bombType;
this.enabled = bomb.enabled;
}
}

View File

@@ -0,0 +1,38 @@
/*
* 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.components;
import com.artemis.Component;
import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelInstance;
public class CollisionModelComponent extends Component {
public ModelInstance instance;
public CollisionModelComponent(Model model) throws IllegalArgumentException{
if(model == null)
throw new IllegalArgumentException("Model is null.");
this.instance = new ModelInstance(model);
}
public CollisionModelComponent(ModelInstance instance) throws IllegalArgumentException{
if(instance == null)
throw new IllegalArgumentException("Instance is null.");
this.instance = instance;
}
}

View File

@@ -19,17 +19,17 @@ import com.artemis.Component;
import com.badlogic.gdx.graphics.g3d.Model; import com.badlogic.gdx.graphics.g3d.Model;
import com.badlogic.gdx.graphics.g3d.ModelInstance; import com.badlogic.gdx.graphics.g3d.ModelInstance;
public class ModelComponent extends Component { public class RenderModelComponent extends Component {
public ModelInstance instance; public ModelInstance instance;
public ModelComponent(Model model) throws IllegalArgumentException{ public RenderModelComponent(Model model) throws IllegalArgumentException{
if(model == null) if(model == null)
throw new IllegalArgumentException("Model is null."); throw new IllegalArgumentException("Model is null.");
this.instance = new ModelInstance(model); this.instance = new ModelInstance(model);
} }
public ModelComponent(ModelInstance instance) throws IllegalArgumentException{ public RenderModelComponent(ModelInstance instance) throws IllegalArgumentException{
if(instance == null) if(instance == null)
throw new IllegalArgumentException("Instance is null."); throw new IllegalArgumentException("Instance is null.");

View File

@@ -0,0 +1,30 @@
/*
* 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.components;
import com.artemis.Component;
public class VisibilityComponent extends Component {
public boolean visible;
public VisibilityComponent(){
this.visible = true;
}
public VisibilityComponent(boolean visibility){
this.visible = visibility;
}
}

View File

@@ -16,15 +16,17 @@
package ve.ucv.ciens.ccg.nxtar.entities; package ve.ucv.ciens.ccg.nxtar.entities;
import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent; 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.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.ModelComponent; import ve.ucv.ciens.ccg.nxtar.components.RenderModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent; import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.DirectionalLightPerPixelShader; import ve.ucv.ciens.ccg.nxtar.graphics.shaders.DirectionalLightPerPixelShader;
import com.artemis.Entity; import com.artemis.Entity;
import com.artemis.World;
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.g3d.Environment; import com.badlogic.gdx.graphics.g3d.Environment;
@@ -43,25 +45,9 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private static final String TAG = "BOMB_ENTITY_CREATOR"; private static final String TAG = "BOMB_ENTITY_CREATOR";
private static final String CLASS_NAME = BombGameEntityCreator.class.getSimpleName(); private static final String CLASS_NAME = BombGameEntityCreator.class.getSimpleName();
/*private enum bomb_type_t{
COMBINATION(0), INCLINATION(1), WIRES(2);
private int value;
private bomb_type_t(int value){
this.value = value;
}
public int getValue(){
return this.value;
}
};*/
private class EntityParameters{ private class EntityParameters{
public Environment environment; public Environment environment;
public Shader shader; public Shader shader;
public Model model1;
public Model model2;
public int markerCode; public int markerCode;
public int nextAnimation; public int nextAnimation;
public boolean loopAnimation; public boolean loopAnimation;
@@ -69,8 +55,6 @@ public class BombGameEntityCreator extends EntityCreatorBase{
public EntityParameters(){ public EntityParameters(){
environment = new Environment(); environment = new Environment();
shader = null; shader = null;
model1 = null;
model2 = null;
markerCode = -1; markerCode = -1;
nextAnimation = -1; nextAnimation = -1;
loopAnimation = false; loopAnimation = false;
@@ -84,10 +68,15 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private Model bombModelCombination; private Model bombModelCombination;
private Model bombModelInclination; private Model bombModelInclination;
private Model bombModelWires; private Model bombModelWires;
private Model bombModelWiresWire1;
private Model bombModelWiresWire2;
private Model bombModelWiresWire3;
private Model easterEggModel; private Model easterEggModel;
private int currentBombId;
public BombGameEntityCreator(){ public BombGameEntityCreator(){
G3dModelLoader loader = new G3dModelLoader(new JsonReader()); G3dModelLoader loader = new G3dModelLoader(new JsonReader());
currentBombId = 0;
parameters = new EntityParameters(); parameters = new EntityParameters();
parameters.environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.0f)); parameters.environment.set(new ColorAttribute(ColorAttribute.AmbientLight, 0.3f, 0.3f, 0.3f, 1.0f));
@@ -105,45 +94,42 @@ public class BombGameEntityCreator extends EntityCreatorBase{
// Create the models. // Create the models.
// TODO: Set the correct model paths. // TODO: Set the correct model paths.
doorModel = loader.loadModel(Gdx.files.internal("")); // TODO: Load collision models.
doorFrameModel = loader.loadModel(Gdx.files.internal("")); doorModel = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
bombModelCombination = loader.loadModel(Gdx.files.internal("")); doorFrameModel = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
bombModelInclination = loader.loadModel(Gdx.files.internal("")); bombModelCombination = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
bombModelWires = loader.loadModel(Gdx.files.internal("")); bombModelInclination = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
easterEggModel = loader.loadModel(Gdx.files.internal("")); bombModelWires = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
easterEggModel = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
bombModelWiresWire1 = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
bombModelWiresWire2 = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
bombModelWiresWire3 = loader.loadModel(Gdx.files.internal("assets/models/render_models/"));
} }
@Override @Override
public void createAllEntities(){ public void createAllEntities(){
// TODO: Create the scene.
// TODO: Add the robot arms. // TODO: Add the robot arms.
// Add bombs. // Add bombs.
parameters.markerCode = 89; parameters.markerCode = 89;
parameters.model1 = bombModelCombination; addBomb(parameters, bomb_type_t.COMBINATION);
addBomb(world, parameters);
parameters.markerCode = 90; parameters.markerCode = 90;
parameters.model1 = bombModelInclination; addBomb(parameters, bomb_type_t.INCLINATION);
addBomb(world, parameters);
parameters.markerCode = 91; parameters.markerCode = 91;
parameters.model1 = bombModelWires; addBomb(parameters, bomb_type_t.WIRES);
addBomb(world, parameters);
// Add doors. // Add doors.
parameters.model1 = doorFrameModel;
parameters.model2 = doorModel;
parameters.nextAnimation = 0; parameters.nextAnimation = 0;
parameters.loopAnimation = false; parameters.loopAnimation = false;
parameters.markerCode = 89; parameters.markerCode = 89;
addDoor(world, parameters); addDoor(parameters);
parameters.markerCode = 90; parameters.markerCode = 90;
addDoor(world, parameters); addDoor(parameters);
parameters.markerCode = 91; parameters.markerCode = 91;
addDoor(world, parameters); addDoor(parameters);
} }
@Override @Override
@@ -162,44 +148,99 @@ public class BombGameEntityCreator extends EntityCreatorBase{
bombModelInclination.dispose(); bombModelInclination.dispose();
if(bombModelWires != null) if(bombModelWires != null)
bombModelWires.dispose(); bombModelWires.dispose();
if(bombModelWiresWire1 != null)
bombModelWiresWire1.dispose();
if(bombModelWiresWire2 != null)
bombModelWiresWire2.dispose();
if(bombModelWiresWire3 != null)
bombModelWiresWire3.dispose();
if(easterEggModel != null) if(easterEggModel != null)
easterEggModel.dispose(); easterEggModel.dispose();
} }
private void addBomb(World world, EntityParameters parameters){ private void addBomb(EntityParameters parameters, bomb_type_t type) throws IllegalArgumentException{
Entity bomb; Entity bomb;
BombComponent bombComponent = new BombComponent(currentBombId, type);
bomb = world.createEntity(); bomb = world.createEntity();
bomb.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1))); bomb.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
bomb.addComponent(new ModelComponent(parameters.model1));
bomb.addComponent(new EnvironmentComponent(parameters.environment)); bomb.addComponent(new EnvironmentComponent(parameters.environment));
bomb.addComponent(new ShaderComponent(parameters.shader)); bomb.addComponent(new ShaderComponent(parameters.shader));
bomb.addComponent(new MarkerCodeComponent(parameters.markerCode)); bomb.addComponent(new MarkerCodeComponent(parameters.markerCode));
bomb.addComponent(bombComponent);
bomb.addComponent(new VisibilityComponent());
if(type == bomb_type_t.COMBINATION){
bomb.addComponent(new RenderModelComponent(bombModelCombination));
}else if(type == bomb_type_t.INCLINATION){
bomb.addComponent(new RenderModelComponent(bombModelInclination));
}else if(type == bomb_type_t.WIRES){
bomb.addComponent(new RenderModelComponent(bombModelWires));
addBombWires(parameters, bombComponent);
}else
throw new IllegalArgumentException("Unrecognized bomb type: " + Integer.toString(type.getValue()));
bomb.addToWorld(); bomb.addToWorld();
currentBombId++;
} }
private void addDoor(World world, EntityParameters parameters){ private void addBombWires(EntityParameters parameters, BombComponent bomb){
ModelInstance frameModel, doorModel; // TODO: Add collision models.
Entity frame, door; Entity wire1, wire2, wire3;
frameModel = new ModelInstance(parameters.model1); wire1 = world.createEntity();
doorModel = new ModelInstance(parameters.model2); 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 BombComponent(bomb));
wire1.addComponent(new VisibilityComponent());
wire1.addToWorld();
wire2 = world.createEntity();
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 BombComponent(bomb));
wire2.addComponent(new VisibilityComponent());
wire2.addToWorld();
wire3 = world.createEntity();
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 BombComponent(bomb));
wire3.addComponent(new VisibilityComponent());
wire3.addToWorld();
}
private void addDoor(EntityParameters parameters){
// TODO: Add collision models.
ModelInstance doorInstance;
Entity frame, door;
frame = world.createEntity(); frame = world.createEntity();
frame.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1))); frame.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
frame.addComponent(new ModelComponent(frameModel)); frame.addComponent(new RenderModelComponent(doorFrameModel));
frame.addComponent(new EnvironmentComponent(parameters.environment)); frame.addComponent(new EnvironmentComponent(parameters.environment));
frame.addComponent(new ShaderComponent(parameters.shader)); frame.addComponent(new ShaderComponent(parameters.shader));
frame.addComponent(new VisibilityComponent());
frame.addComponent(new MarkerCodeComponent(parameters.markerCode)); frame.addComponent(new MarkerCodeComponent(parameters.markerCode));
frame.addToWorld(); frame.addToWorld();
door = world.createEntity(); door = world.createEntity();
door.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1))); door.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
door.addComponent(new ModelComponent(doorModel)); door.addComponent(new RenderModelComponent(doorModel));
door.addComponent(new EnvironmentComponent(parameters.environment)); door.addComponent(new EnvironmentComponent(parameters.environment));
door.addComponent(new ShaderComponent(parameters.shader)); door.addComponent(new ShaderComponent(parameters.shader));
door.addComponent(new MarkerCodeComponent(parameters.markerCode)); door.addComponent(new MarkerCodeComponent(parameters.markerCode));
door.addComponent(new AnimationComponent(doorModel, parameters.nextAnimation, parameters.loopAnimation)); door.addComponent(new VisibilityComponent());
doorInstance = door.getComponent(RenderModelComponent.class).instance;
door.addComponent(new AnimationComponent(doorInstance, parameters.nextAnimation, parameters.loopAnimation));
door.addToWorld(); door.addToWorld();
} }
} }

View File

@@ -19,7 +19,7 @@ import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent;
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.ModelComponent; import ve.ucv.ciens.ccg.nxtar.components.RenderModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent; import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
import ve.ucv.ciens.ccg.nxtar.graphics.shaders.DirectionalLightPerPixelShader; import ve.ucv.ciens.ccg.nxtar.graphics.shaders.DirectionalLightPerPixelShader;
@@ -83,22 +83,22 @@ public class MarkerTestEntityCreator extends EntityCreatorBase {
Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the enitites."); Gdx.app.log(TAG, CLASS_NAME + ".createAllEntities(): Creating the enitites.");
bomb = world.createEntity(); bomb = 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))); bomb.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 ModelComponent(bombModel)); bomb.addComponent(new RenderModelComponent(bombModel));
bomb.addComponent(new EnvironmentComponent(environment)); bomb.addComponent(new EnvironmentComponent(environment));
bomb.addComponent(new ShaderComponent(ppShader)); bomb.addComponent(new ShaderComponent(ppShader));
bomb.addComponent(new MarkerCodeComponent(1023)); bomb.addComponent(new MarkerCodeComponent(1023));
anim = world.createEntity(); anim = world.createEntity();
anim.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.0f), new Matrix3().idt(), new Vector3(0.25f, 0.25f, -0.25f))); anim.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, 0.0f), new Matrix3().idt(), new Vector3(0.25f, 0.25f, -0.25f)));
anim.addComponent(new ModelComponent(animatedModel)); anim.addComponent(new RenderModelComponent(animatedModel));
anim.addComponent(new AnimationComponent(anim.getComponent(ModelComponent.class).instance, 0, true)); anim.addComponent(new AnimationComponent(anim.getComponent(RenderModelComponent.class).instance, 0, true));
anim.addComponent(new EnvironmentComponent(environment)); anim.addComponent(new EnvironmentComponent(environment));
anim.addComponent(new MarkerCodeComponent(89)); anim.addComponent(new MarkerCodeComponent(89));
anim.addComponent(new ShaderComponent(ppShader)); anim.addComponent(new ShaderComponent(ppShader));
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 ModelComponent(boxModel)); box.addComponent(new RenderModelComponent(boxModel));
box.addComponent(new ShaderComponent(ppShader)); box.addComponent(new ShaderComponent(ppShader));
box.addComponent(new EnvironmentComponent(environment)); box.addComponent(new EnvironmentComponent(environment));

View File

@@ -24,9 +24,11 @@ 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;
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.AnimationSystem; 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.MarkerPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem; import ve.ucv.ciens.ccg.nxtar.systems.MarkerRenderingSystem;
import ve.ucv.ciens.ccg.nxtar.systems.ObjectRenderingSystem; 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.GameSettings;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants; import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
@@ -187,6 +189,9 @@ public class InGameState extends BaseState{
GameSettings.entityCreator.createAllEntities(); GameSettings.entityCreator.createAllEntities();
gameWorld.setSystem(new MarkerPositioningSystem()); gameWorld.setSystem(new MarkerPositioningSystem());
// TODO: Make and add positioning systems.
gameWorld.setSystem(new GeometrySystem());
//gameWorld.setSystem(new VisibilitySystem());
gameWorld.setSystem(new AnimationSystem()); gameWorld.setSystem(new AnimationSystem());
// TODO: Add collision system. // TODO: Add collision system.
//gameWorld.setSystem(GameSettings.gameLogicSystem); //gameWorld.setSystem(GameSettings.gameLogicSystem);
@@ -242,6 +247,8 @@ public class InGameState extends BaseState{
perspectiveCamera.far = FAR; perspectiveCamera.far = FAR;
perspectiveCamera.lookAt(0.0f, 0.0f, -1.0f); perspectiveCamera.lookAt(0.0f, 0.0f, -1.0f);
perspectiveCamera.update(); perspectiveCamera.update();
gameWorld.getSystem(VisibilitySystem.class).setCamera(perspectiveCamera);
} }
// Attempt to find the markers in the current video frame. // Attempt to find the markers in the current video frame.

View File

@@ -17,186 +17,33 @@ package ve.ucv.ciens.ccg.nxtar.states;
import ve.ucv.ciens.ccg.nxtar.NxtARCore; import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import com.badlogic.gdx.controllers.Controller;
import com.badlogic.gdx.controllers.PovDirection;
import com.badlogic.gdx.math.Vector3;
public class PauseState extends BaseState { public class PauseState extends BaseState {
public PauseState(final NxtARCore core){ public PauseState(final NxtARCore core){
this.core = core; this.core = core;
} }
@Override
public void onStateSet() {
// TODO Auto-generated method stub
}
@Override
public void onStateUnset() {
// TODO Auto-generated method stub
}
@Override @Override
public void render(float delta) { public void render(float delta) {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
@Override
public void resize(int width, int height) {
// TODO Auto-generated method stub
}
@Override
public void show() {
// TODO Auto-generated method stub
}
@Override
public void hide() {
// TODO Auto-generated method stub
}
@Override
public void pause() {
// TODO Auto-generated method stub
}
@Override
public void resume() {
// TODO Auto-generated method stub
}
@Override @Override
public void dispose() { public void dispose() {
// TODO Auto-generated method stub // TODO Auto-generated method stub
} }
/*;;;;;;;;;;;;;;;;;;
; HELPER METHODS ;
;;;;;;;;;;;;;;;;;;*/
@Override
public void onStateSet(){
}
@Override
public void onStateUnset(){
}
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; BEGIN INPUT PROCESSOR METHODS ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
@Override
public boolean keyDown(int keycode) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean keyUp(int keycode) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean keyTyped(char character) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
// TODO Auto-generated method stub
return false;
}
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; END INPUT PROCESSOR METHODS ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; BEGIN CONTROLLER LISTENER METHODS ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
@Override
public boolean scrolled(int amount) {
// TODO Auto-generated method stub
return false;
}
@Override
public void connected(Controller controller) {
// TODO Auto-generated method stub
}
@Override
public void disconnected(Controller controller) {
// TODO Auto-generated method stub
}
@Override
public boolean buttonDown(Controller controller, int buttonCode) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean buttonUp(Controller controller, int buttonCode) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean axisMoved(Controller controller, int axisCode, float value) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean povMoved(Controller controller, int povCode,
PovDirection value) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean xSliderMoved(Controller controller, int sliderCode,
boolean value) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean ySliderMoved(Controller controller, int sliderCode,
boolean value) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean accelerometerMoved(Controller controller,
int accelerometerCode, Vector3 value) {
// TODO Auto-generated method stub
return false;
}
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; END CONTROLLER LISTENER METHODS ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;*/
} }

View File

@@ -16,6 +16,7 @@
package ve.ucv.ciens.ccg.nxtar.systems; package ve.ucv.ciens.ccg.nxtar.systems;
import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent; import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent;
import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
import com.artemis.Aspect; import com.artemis.Aspect;
import com.artemis.ComponentMapper; import com.artemis.ComponentMapper;
@@ -26,24 +27,26 @@ import com.badlogic.gdx.Gdx;
public class AnimationSystem extends EntityProcessingSystem { public class AnimationSystem extends EntityProcessingSystem {
@Mapper ComponentMapper<AnimationComponent> animationMapper; @Mapper ComponentMapper<AnimationComponent> animationMapper;
@Mapper ComponentMapper<VisibilityComponent> visibilityMapper;
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public AnimationSystem(){ public AnimationSystem(){
super(Aspect.getAspectForAll(AnimationComponent.class)); super(Aspect.getAspectForAll(AnimationComponent.class, VisibilityComponent.class));
} }
@Override @Override
protected void process(Entity e) { protected void process(Entity e) {
AnimationComponent animation = animationMapper.get(e); AnimationComponent animation = animationMapper.get(e);
VisibilityComponent visibility = visibilityMapper.get(e);
if(animation.current != animation.next && animation.next >= 0 && animation.next < animation.animationsIds.size()){ if(animation.current != animation.next && animation.next >= 0 && animation.next < animation.animationsIds.size()){
if(animation.loop) if(animation.loop)
animation.controller.setAnimation(animation.animationsIds.get(animation.next), -1); animation.controller.animate(animation.animationsIds.get(animation.next), -1, 1, null,0.1f);
else else
animation.controller.setAnimation(animation.animationsIds.get(animation.next)); animation.controller.animate(animation.animationsIds.get(animation.next), 1, 1, null,0.1f);
} }
animation.controller.update(Gdx.graphics.getDeltaTime()); if(visibility.visible)
animation.controller.update(Gdx.graphics.getDeltaTime());
} }
} }

View File

@@ -15,7 +15,7 @@
*/ */
package ve.ucv.ciens.ccg.nxtar.systems; package ve.ucv.ciens.ccg.nxtar.systems;
import ve.ucv.ciens.ccg.nxtar.components.ModelComponent; import ve.ucv.ciens.ccg.nxtar.components.CollisionModelComponent;
import com.artemis.Aspect; import com.artemis.Aspect;
import com.artemis.Entity; import com.artemis.Entity;
@@ -25,7 +25,7 @@ public class CollisionDetectionSystem extends EntityProcessingSystem {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public CollisionDetectionSystem(){ public CollisionDetectionSystem(){
super(Aspect.getAspectForAll(ModelComponent.class)); super(Aspect.getAspectForAll(CollisionModelComponent.class));
} }
@Override @Override

View File

@@ -0,0 +1,103 @@
/*
* 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.RenderModelComponent;
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.g3d.ModelInstance;
import com.badlogic.gdx.math.Matrix4;
public class GeometrySystem extends EntityProcessingSystem {
@Mapper ComponentMapper<GeometryComponent> geometryMapper;
@Mapper ComponentMapper<RenderModelComponent> renderModelMapper;
@Mapper ComponentMapper<CollisionModelComponent> colModelMapper;
/**
* <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;
@SuppressWarnings("unchecked")
public GeometrySystem(){
super(Aspect.getAspectForAll(GeometryComponent.class).one(RenderModelComponent.class, CollisionModelComponent.class));
translationMatrix = new Matrix4().setToTranslation(0.0f, 0.0f, 0.0f);
rotationMatrix = new Matrix4().idt();
scalingMatrix = new Matrix4().setToScaling(0.0f, 0.0f, 0.0f);
}
@Override
protected void process(Entity e) {
GeometryComponent geometry;
RenderModelComponent renderModel;
CollisionModelComponent colModel;
geometry = geometryMapper.get(e);
renderModel = renderModelMapper.getSafe(e);
colModel = colModelMapper.getSafe(e);
if(renderModel != null)
applyWorldTransform(renderModel.instance, geometry);
if(colModel != null)
applyWorldTransform(colModel.instance, geometry);
}
private void applyWorldTransform(ModelInstance model, GeometryComponent geometry){
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);
model.transform.idt().mul(translationMatrix).mul(rotationMatrix).mul(scalingMatrix);
model.calculateTransforms();
}
}

View File

@@ -16,10 +16,10 @@
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.EnvironmentComponent;
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.ModelComponent; import ve.ucv.ciens.ccg.nxtar.components.RenderModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent; 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.interfaces.ImageProcessor.MarkerData;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants; import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
@@ -31,14 +31,14 @@ import com.artemis.systems.EntityProcessingSystem;
import com.badlogic.gdx.Gdx; import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.PerspectiveCamera; import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.g3d.ModelBatch; import com.badlogic.gdx.graphics.g3d.ModelBatch;
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<ModelComponent> modelMapper; @Mapper ComponentMapper<RenderModelComponent> modelMapper;
@Mapper ComponentMapper<EnvironmentComponent> environmentMapper; @Mapper ComponentMapper<EnvironmentComponent> environmentMapper;
@Mapper ComponentMapper<ShaderComponent> shaderMapper; @Mapper ComponentMapper<ShaderComponent> shaderMapper;
@Mapper ComponentMapper<VisibilityComponent> visibiltyMapper;
private static final String TAG = "MODEL_BATCH_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();
@@ -46,17 +46,17 @@ public class MarkerRenderingSystem extends EntityProcessingSystem {
/** /**
* <p>A matrix representing 3D translations.</p> * <p>A matrix representing 3D translations.</p>
*/ */
private Matrix4 translationMatrix; //private Matrix4 translationMatrix;
/** /**
* <p>A matrix representing 3D rotations.</p> * <p>A matrix representing 3D rotations.</p>
*/ */
private Matrix4 rotationMatrix; //private Matrix4 rotationMatrix;
/** /**
* <p>A matrix representing 3D scalings.</p> * <p>A matrix representing 3D scalings.</p>
*/ */
private Matrix4 scalingMatrix; //private Matrix4 scalingMatrix;
private MarkerData markers; private MarkerData markers;
@@ -66,14 +66,14 @@ public class MarkerRenderingSystem extends EntityProcessingSystem {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public MarkerRenderingSystem(ModelBatch batch){ public MarkerRenderingSystem(ModelBatch batch){
super(Aspect.getAspectForAll(MarkerCodeComponent.class, GeometryComponent.class, ShaderComponent.class, EnvironmentComponent.class, ModelComponent.class)); super(Aspect.getAspectForAll(MarkerCodeComponent.class, /*GeometryComponent.class,*/ ShaderComponent.class, EnvironmentComponent.class, RenderModelComponent.class, VisibilityComponent.class));
markers = null; markers = null;
camera = null; camera = null;
this.batch = batch; 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);
} }
public void begin(PerspectiveCamera camera, MarkerData markers) throws RuntimeException{ public void begin(PerspectiveCamera camera, MarkerData markers) throws RuntimeException{
@@ -97,62 +97,65 @@ public class MarkerRenderingSystem extends EntityProcessingSystem {
@Override @Override
protected void process(Entity e) { protected void process(Entity e) {
MarkerCodeComponent marker; MarkerCodeComponent marker;
GeometryComponent geometry; // GeometryComponent geometry;
EnvironmentComponent environment; EnvironmentComponent environment;
ModelComponent model; RenderModelComponent model;
ShaderComponent shader; ShaderComponent shader;
VisibilityComponent visibility;
if(markers == null || camera == 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);
model = modelMapper.get(e); model = modelMapper.get(e);
environment = environmentMapper.get(e); environment = environmentMapper.get(e);
shader = shaderMapper.get(e); shader = shaderMapper.get(e);
visibility = visibiltyMapper.get(e);
Gdx.app.log(TAG, CLASS_NAME + ".process(): Processing markers."); if(visibility.visible){
for(int i = 0; i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){ Gdx.app.log(TAG, CLASS_NAME + ".process(): Processing markers.");
if(markers.markerCodes[i] != 1){ for(int i = 0; i < ProjectConstants.MAXIMUM_NUMBER_OF_MARKERS; i++){
if(markers.markerCodes[i] == marker.code){ if(markers.markerCodes[i] != 1){
Gdx.app.log(TAG, CLASS_NAME + ".process(): Rendering marker code " + Integer.toString(markers.markerCodes[i]) + "."); if(markers.markerCodes[i] == marker.code){
// Set the geometric transformations. Gdx.app.log(TAG, CLASS_NAME + ".process(): Rendering marker code " + Integer.toString(markers.markerCodes[i]) + ".");
translationMatrix.setToTranslation(geometry.position); // 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();
rotationMatrix.val[Matrix4.M00] = geometry.rotation.val[0]; // Render the marker;
rotationMatrix.val[Matrix4.M10] = geometry.rotation.val[1]; batch.render(model.instance, environment.environment, shader.shader);
rotationMatrix.val[Matrix4.M20] = geometry.rotation.val[2]; }
rotationMatrix.val[Matrix4.M30] = 0; }else{
Gdx.app.log(TAG, CLASS_NAME + ".process(): Skipping marker number " + Integer.toString(i) + ".");
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) + ".");
} }
} }
} }
} }

View File

@@ -18,8 +18,9 @@ package ve.ucv.ciens.ccg.nxtar.systems;
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.ModelComponent; import ve.ucv.ciens.ccg.nxtar.components.RenderModelComponent;
import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent; import ve.ucv.ciens.ccg.nxtar.components.ShaderComponent;
import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
import com.artemis.Aspect; import com.artemis.Aspect;
import com.artemis.ComponentMapper; import com.artemis.ComponentMapper;
@@ -28,32 +29,32 @@ import com.artemis.annotations.Mapper;
import com.artemis.systems.EntityProcessingSystem; import com.artemis.systems.EntityProcessingSystem;
import com.badlogic.gdx.graphics.PerspectiveCamera; import com.badlogic.gdx.graphics.PerspectiveCamera;
import com.badlogic.gdx.graphics.g3d.ModelBatch; import com.badlogic.gdx.graphics.g3d.ModelBatch;
import com.badlogic.gdx.math.Matrix4;
/** /**
* <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
* 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<ShaderComponent> shaderMapper; @Mapper ComponentMapper<ShaderComponent> shaderMapper;
@Mapper ComponentMapper<ModelComponent> modelMapper; @Mapper ComponentMapper<RenderModelComponent> modelMapper;
@Mapper ComponentMapper<EnvironmentComponent> environmentMapper; @Mapper ComponentMapper<EnvironmentComponent> environmentMapper;
@Mapper ComponentMapper<VisibilityComponent> visibiltyMapper;
/** // /**
* <p>A matrix representing 3D translations.</p> // * <p>A matrix representing 3D translations.</p>
*/ // */
private Matrix4 translationMatrix; // private Matrix4 translationMatrix;
//
/** // /**
* <p>A matrix representing 3D rotations.</p> // * <p>A matrix representing 3D rotations.</p>
*/ // */
private Matrix4 rotationMatrix; // private Matrix4 rotationMatrix;
//
/** // /**
* <p>A matrix representing 3D scalings.</p> // * <p>A matrix representing 3D scalings.</p>
*/ // */
private Matrix4 scalingMatrix; // private Matrix4 scalingMatrix;
private PerspectiveCamera camera; private PerspectiveCamera camera;
@@ -61,13 +62,13 @@ public class ObjectRenderingSystem extends EntityProcessingSystem {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public ObjectRenderingSystem(ModelBatch batch) { public ObjectRenderingSystem(ModelBatch batch) {
super(Aspect.getAspectForAll(GeometryComponent.class, ShaderComponent.class, ModelComponent.class, EnvironmentComponent.class).exclude(MarkerCodeComponent.class)); super(Aspect.getAspectForAll(GeometryComponent.class, ShaderComponent.class, RenderModelComponent.class, EnvironmentComponent.class, VisibilityComponent.class).exclude(MarkerCodeComponent.class));
camera = null; camera = null;
this.batch = batch; 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);
} }
public void begin(PerspectiveCamera camera) throws RuntimeException{ public void begin(PerspectiveCamera camera) throws RuntimeException{
@@ -92,24 +93,28 @@ public class ObjectRenderingSystem extends EntityProcessingSystem {
@Override @Override
protected void process(Entity e) { protected void process(Entity e) {
EnvironmentComponent environment; EnvironmentComponent environment;
GeometryComponent geometryComponent; // GeometryComponent geometryComponent;
ShaderComponent shaderComponent; ShaderComponent shaderComponent;
ModelComponent modelComponent; RenderModelComponent renderModelComponent;
VisibilityComponent visibility;
// Get the necessary components. // Get the necessary components.
geometryComponent = geometryMapper.get(e); // geometryComponent = geometryMapper.get(e);
modelComponent = modelMapper.get(e); renderModelComponent = modelMapper.get(e);
shaderComponent = shaderMapper.get(e); shaderComponent = shaderMapper.get(e);
environment = environmentMapper.get(e); environment = environmentMapper.get(e);
visibility = visibiltyMapper.get(e);
// Calculate the geometric transformation for this entity. if(visibility.visible){
translationMatrix.setToTranslation(geometryComponent.position); // Calculate the geometric transformation for this entity.
rotationMatrix.set(geometryComponent.rotation); // translationMatrix.setToTranslation(geometryComponent.position);
scalingMatrix.setToScaling(geometryComponent.scaling); // rotationMatrix.set(geometryComponent.rotation);
modelComponent.instance.transform.idt().mul(translationMatrix).mul(rotationMatrix).mul(scalingMatrix); // scalingMatrix.setToScaling(geometryComponent.scaling);
modelComponent.instance.calculateTransforms(); // renderModelComponent.instance.transform.idt().mul(translationMatrix).mul(rotationMatrix).mul(scalingMatrix);
// renderModelComponent.instance.calculateTransforms();
// Render this entity. // Render this entity.
batch.render(modelComponent.instance, environment.environment, shaderComponent.shader); batch.render(renderModelComponent.instance, environment.environment, shaderComponent.shader);
}
} }
} }

View File

@@ -0,0 +1,59 @@
/*
* 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);
}
}
}