Started modelling user input.

This commit is contained in:
2014-06-06 19:10:11 -04:30
parent d4edcf4909
commit aa5871b49a
10 changed files with 261 additions and 114 deletions

View File

@@ -86,7 +86,7 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
}
public static int getNumStates(){
return 4;
return 3;
}
};

View File

@@ -64,62 +64,49 @@ public class BombGameEntityCreator extends EntityCreatorBase{
}
}
private EntityParameters parameters;
private Shader shader;
private int currentBombId;
private Shader shader;
private int currentBombId;
// Render models.
private Model doorModel = null;
private Model doorFrameModel = null;
private Model combinationBombModel = null;
private Model combinationButton1Model = null;
private Model combinationButton2Model = null;
private Model combinationButton3Model = null;
private Model combinationButton4Model = null;
private Model inclinationBombModel = null;
private Model inclinationBombButtonModel = null;
private Model wiresBombModel = null;
private Model wiresBombModelWire1 = null;
private Model wiresBombModelWire2 = null;
private Model wiresBombModelWire3 = null;
// private Model easterEggModel = null;
private Model robotArmModel = null;
private Model doorModel = null;
private Model doorFrameModel = null;
private Model combinationBombModel = null;
private Model combinationButton1Model = null;
private Model combinationButton2Model = null;
private Model combinationButton3Model = null;
private Model combinationButton4Model = null;
private Model inclinationBombModel = null;
private Model inclinationBombButtonModel = 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 combinationButton1CollisionModel = null;
private Model combinationButton2CollisionModel = null;
private Model combinationButton3CollisionModel = null;
private Model combinationButton4CollisionModel = null;
private Model inclinationBombCollisionModel = null;
private Model inclinationBombButtonCollisionModel = null;
private Model wiresBombCollisionModel = null;
private Model wiresBombCollisionModelWire1 = null;
private Model wiresBombCollisionModelWire2 = null;
private Model wiresBombCollisionModelWire3 = null;
// private Model easterEggCollisionModel = null;
private Model robotArmCollisionModel = null;
private Model doorCollisionModel = null;
private Model doorFrameCollisionModel = null;
private Model combinationBombCollisionModel = null;
private Model combinationButton1CollisionModel = null;
private Model combinationButton2CollisionModel = null;
private Model combinationButton3CollisionModel = null;
private Model combinationButton4CollisionModel = null;
private Model inclinationBombCollisionModel = null;
private Model inclinationBombButtonCollisionModel = null;
private Model wiresBombCollisionModel = null;
private Model wiresBombCollisionModelWire1 = null;
private Model wiresBombCollisionModelWire2 = null;
private Model wiresBombCollisionModelWire3 = null;
private Model easterEggCollisionModel = null;
public BombGameEntityCreator(){
currentBombId = 0;
manager = new AssetManager();
// 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)));
// Load the shader.
shader = new DirectionalLightPerPixelShader();
try{
shader.init();
}catch(GdxRuntimeException gdx){
Gdx.app.error(TAG, CLASS_NAME + ".BombGameEntityCreator(): Shader failed to load: " + gdx.getMessage());
shader = null;
}
parameters.shader = shader;
// Load the render models.
manager.load("models/render_models/bomb_game/robot_arm.g3db", Model.class);
manager.load("models/render_models/bomb_game/door.g3db", Model.class);
manager.load("models/render_models/bomb_game/door_frame1.g3db", Model.class);
@@ -139,6 +126,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
// manager.load("models/render_models/bomb_game/", Model.class);
// Load the collision models.
manager.load("models/collision_models/bomb_game/robot_arm_col.g3db", Model.class);
manager.load("models/collision_models/bomb_game/door_col.g3db", Model.class);
manager.load("models/collision_models/bomb_game/door_frame1_col.g3db", Model.class);
@@ -160,7 +148,24 @@ public class BombGameEntityCreator extends EntityCreatorBase{
@Override
public void createAllEntities(){
// TODO: Add the robot arms.
EntityParameters parameters;
// 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)));
// Load the shader.
shader = new DirectionalLightPerPixelShader();
try{
shader.init();
}catch(GdxRuntimeException gdx){
Gdx.app.error(TAG, CLASS_NAME + ".BombGameEntityCreator(): Shader failed to load: " + gdx.getMessage());
shader = null;
}
parameters.shader = shader;
addRobotArm(parameters);
// Add bombs.
parameters.markerCode = 89;
@@ -209,6 +214,17 @@ public class BombGameEntityCreator extends EntityCreatorBase{
manager.dispose();
}
private void addRobotArm(EntityParameters parameters){
Entity robotArm = world.createEntity();
robotArm.addComponent(new GeometryComponent(new Vector3(), new Matrix3(), new Vector3(1, 1, 1)));
robotArm.addComponent(new EnvironmentComponent(parameters.environment));
robotArm.addComponent(new ShaderComponent(parameters.shader));
robotArm.addComponent(new RenderModelComponent(robotArmModel));
robotArm.addComponent(new CollisionModelComponent(robotArmCollisionModel));
robotArm.addToWorld();
}
private void addBomb(EntityParameters parameters, bomb_type_t type) throws IllegalArgumentException{
Entity bomb;
BombComponent bombComponent = new BombComponent(currentBombId, type);
@@ -362,7 +378,8 @@ public class BombGameEntityCreator extends EntityCreatorBase{
}
private void getModels(){
// Load the render models.
// Get the render models.
robotArmModel = manager.get("models/render_models/bomb_game/robot_arm.g3db", Model.class);
doorModel = manager.get("models/render_models/bomb_game/door.g3db", Model.class);
doorFrameModel = manager.get("models/render_models/bomb_game/door_frame1.g3db", Model.class);
@@ -381,7 +398,8 @@ public class BombGameEntityCreator extends EntityCreatorBase{
wiresBombModelWire3 = manager.get("models/render_models/bomb_game/cable_3.g3db", Model.class);
// easterEggModel = manager.get("models/render_models/bomb_game/", Model.class);
// Load the collision models.
// Get the collision models.
robotArmCollisionModel = manager.get("models/collision_models/bomb_game/robot_arm_col.g3db", Model.class);
doorCollisionModel = manager.get("models/collision_models/bomb_game/door_col.g3db", Model.class);
doorFrameCollisionModel = manager.get("models/collision_models/bomb_game/door_frame1_col.g3db", Model.class);

View File

@@ -0,0 +1,35 @@
/*
* 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.factories;
import ve.ucv.ciens.ccg.nxtar.factories.products.GamepadUserInput;
import ve.ucv.ciens.ccg.nxtar.factories.products.KeyboardUserInput;
import ve.ucv.ciens.ccg.nxtar.factories.products.TouchUserInput;
import ve.ucv.ciens.ccg.nxtar.factories.products.UserInput;
public abstract class UserInputFactory{
public static UserInput createTouchUserInput(){
return new TouchUserInput();
}
public static UserInput createGamepadUserInput(){
return new GamepadUserInput();
}
public static UserInput createKeyboardUserInput(){
return new KeyboardUserInput();
}
}

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.factories.products;
public class GamepadUserInput extends UserInput {
public float axisLeftX;
public float axisLeftY;
public float axisRightX;
public float axisRightY;
public GamepadUserInput(){
this.axisLeftX = 0.0f;
this.axisLeftY = 0.0f;
this.axisRightX = 0.0f;
this.axisRightY = 0.0f;
}
}

View File

@@ -0,0 +1,34 @@
/*
* 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.factories.products;
public class KeyboardUserInput extends UserInput {
public boolean keyLeft;
public boolean keyRight;
public boolean keyUp;
public boolean keyDown;
public boolean keyA;
public boolean keyZ;
public KeyboardUserInput(){
this.keyLeft = false;
this.keyRight = false;
this.keyUp = false;
this.keyDown = false;
this.keyA = false;
this.keyZ = false;
}
}

View File

@@ -0,0 +1,26 @@
/*
* 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.factories.products;
import com.badlogic.gdx.math.collision.Ray;
public class TouchUserInput extends UserInput {
public Ray movementRay;
public TouchUserInput(){
movementRay = null;
}
}

View File

@@ -0,0 +1,23 @@
/*
* 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.factories.products;
import ve.ucv.ciens.ccg.nxtar.factories.UserInputFactory;
/**
* Tag class for the {@link UserInputFactory} products.
*/
public abstract class UserInput{}

View File

@@ -19,6 +19,8 @@ import ve.ucv.ciens.ccg.networkdata.MotorEvent;
import ve.ucv.ciens.ccg.networkdata.MotorEvent.motor_t;
import ve.ucv.ciens.ccg.nxtar.NxtARCore;
import ve.ucv.ciens.ccg.nxtar.NxtARCore.game_states_t;
import ve.ucv.ciens.ccg.nxtar.factories.UserInputFactory;
import ve.ucv.ciens.ccg.nxtar.factories.products.UserInput;
import ve.ucv.ciens.ccg.nxtar.graphics.CustomPerspectiveCamera;
import ve.ucv.ciens.ccg.nxtar.interfaces.ImageProcessor.MarkerData;
import ve.ucv.ciens.ccg.nxtar.network.monitors.MotorEventQueue;
@@ -27,8 +29,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.RobotArmPositioningSystem;
import ve.ucv.ciens.ccg.nxtar.utils.GameSettings;
import ve.ucv.ciens.ccg.nxtar.utils.ProjectConstants;
@@ -74,6 +76,7 @@ public class InGameState extends BaseState{
private World gameWorld;
private MarkerRenderingSystem markerRenderingSystem;
private ObjectRenderingSystem objectRenderingSystem;
private RobotArmPositioningSystem robotArmPositioningSystem;
// Cameras.
private OrthographicCamera unitaryOrthoCamera;
@@ -179,8 +182,9 @@ public class InGameState extends BaseState{
// Set up the game world.
gameWorld = GameSettings.getGameWorld();
robotArmPositioningSystem = new RobotArmPositioningSystem();
gameWorld.setSystem(new MarkerPositioningSystem());
gameWorld.setSystem(new ObjectPositioningSystem(), true);
gameWorld.setSystem(robotArmPositioningSystem, true);
gameWorld.setSystem(new GeometrySystem());
gameWorld.setSystem(new AnimationSystem());
// TODO: Make and add object-marker collision detection system.
@@ -442,6 +446,7 @@ public class InGameState extends BaseState{
@Override
public boolean touchDown(int screenX, int screenY, int pointer, int button){
MotorEvent event;
UserInput input;
if(!Ouya.runningOnOuya){
win2world.set(screenX, screenY, 0.0f);
@@ -529,8 +534,14 @@ public class InGameState extends BaseState{
event.setPower((byte)0x00);
queue.addEvent(event);
}
}else{
// TODO: Send input to the input handler system.
input = UserInputFactory.createTouchUserInput();
// TODO: Calculate movement ray.
robotArmPositioningSystem.setUserInput(input);
robotArmPositioningSystem.process();
}
return true;
@@ -640,8 +651,6 @@ public class InGameState extends BaseState{
motorButtonsPointers[6] = -1;
motorButtonsTouched[6] = false;
}else{
// TODO: Pass input to the input handler system.
}
return true;
@@ -748,8 +757,6 @@ public class InGameState extends BaseState{
motorButtonsPointers[6] = -1;
motorButtonsTouched[6] = false;
}else{
// TODO: Pass input to the input handler system.
}
return true;
@@ -846,8 +853,9 @@ public class InGameState extends BaseState{
event.setMotor(motor_t.RECENTER);
event.setPower((byte)0x00);
queue.addEvent(event);
}else{
// TODO: Pass input to the input handler system.
}else if(buttonCode == Ouya.BUTTON_A){
core.nextState = game_states_t.MAIN_MENU;
}
return true;
@@ -923,8 +931,6 @@ public class InGameState extends BaseState{
}else if(buttonCode == Ouya.BUTTON_Y){
motorGamepadButtonPressed[6] = false;
}else{
// TODO: Pass input to the input handler system.
}
return true;

View File

@@ -16,11 +16,9 @@
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;
import ve.ucv.ciens.ccg.nxtar.components.VisibilityComponent;
import com.artemis.Aspect;
import com.artemis.ComponentMapper;
@@ -35,40 +33,19 @@ import com.badlogic.gdx.graphics.g3d.ModelBatch;
* entities to be rendered must have a geometry, shader and mesh component associated.</p>
*/
public class ObjectRenderingSystem extends EntityProcessingSystem {
// @Mapper ComponentMapper<GeometryComponent> geometryMapper;
@Mapper ComponentMapper<ShaderComponent> shaderMapper;
@Mapper ComponentMapper<RenderModelComponent> modelMapper;
@Mapper ComponentMapper<EnvironmentComponent> environmentMapper;
@Mapper ComponentMapper<VisibilityComponent> visibiltyMapper;
// /**
// * <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 PerspectiveCamera camera;
private ModelBatch batch;
@SuppressWarnings("unchecked")
public ObjectRenderingSystem(ModelBatch batch) {
super(Aspect.getAspectForAll(GeometryComponent.class, ShaderComponent.class, RenderModelComponent.class, EnvironmentComponent.class, VisibilityComponent.class).exclude(MarkerCodeComponent.class));
super(Aspect.getAspectForAll(ShaderComponent.class, RenderModelComponent.class, EnvironmentComponent.class).exclude(MarkerCodeComponent.class));
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) throws RuntimeException{
@@ -84,37 +61,18 @@ public class ObjectRenderingSystem extends EntityProcessingSystem {
camera = null;
}
/**
* <p>Renders the entity passed by parameter, calculating it's corresponding geometric
* transformation and setting and calling it's associated shader program.</p>
*
* @param e The entity to be processed.
*/
@Override
protected void process(Entity e) {
EnvironmentComponent environment;
// GeometryComponent geometryComponent;
ShaderComponent shaderComponent;
RenderModelComponent renderModelComponent;
VisibilityComponent visibility;
// Get the necessary components.
// geometryComponent = geometryMapper.get(e);
renderModelComponent = modelMapper.get(e);
shaderComponent = shaderMapper.get(e);
environment = environmentMapper.get(e);
visibility = visibiltyMapper.get(e);
if(visibility.visible){
// Calculate the geometric transformation for this entity.
// translationMatrix.setToTranslation(geometryComponent.position);
// rotationMatrix.set(geometryComponent.rotation);
// scalingMatrix.setToScaling(geometryComponent.scaling);
// renderModelComponent.instance.transform.idt().mul(translationMatrix).mul(rotationMatrix).mul(scalingMatrix);
// renderModelComponent.instance.calculateTransforms();
// Render this entity.
batch.render(renderModelComponent.instance, environment.environment, shaderComponent.shader);
}
// Render this entity.
batch.render(renderModelComponent.instance, environment.environment, shaderComponent.shader);
}
}

View File

@@ -16,6 +16,10 @@
package ve.ucv.ciens.ccg.nxtar.systems;
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
import ve.ucv.ciens.ccg.nxtar.factories.products.GamepadUserInput;
import ve.ucv.ciens.ccg.nxtar.factories.products.KeyboardUserInput;
import ve.ucv.ciens.ccg.nxtar.factories.products.TouchUserInput;
import ve.ucv.ciens.ccg.nxtar.factories.products.UserInput;
import com.artemis.Aspect;
import com.artemis.ComponentMapper;
@@ -23,22 +27,35 @@ import com.artemis.Entity;
import com.artemis.annotations.Mapper;
import com.artemis.systems.EntityProcessingSystem;
public class ObjectPositioningSystem extends EntityProcessingSystem {
public class RobotArmPositioningSystem extends EntityProcessingSystem {
@Mapper ComponentMapper<GeometryComponent> geometryMapper;
private UserInput input;
@SuppressWarnings("unchecked")
public ObjectPositioningSystem(){
public RobotArmPositioningSystem(){
super(Aspect.getAspectForAll(GeometryComponent.class));
}
public void setUserInput(){
// TODO: Desing a representation for user input.
// TODO: Store user input for processing.
public void setUserInput(UserInput input){
this.input = input;
}
@Override
protected void process(Entity e) {
GeometryComponent geometry = geometryMapper.get(e);
// TODO: Set the geometry fields based on user input.
if(input == null) return;
if(input instanceof TouchUserInput){
}else if(input instanceof GamepadUserInput){
}else if(input instanceof KeyboardUserInput){
}else
throw new ClassCastException("Input is not a valid UserInput instance.");
input = null;
}
}