Touch controls ready.

This commit is contained in:
2014-06-16 15:47:07 -04:30
parent 7f20a09eb9
commit fd197211b5
7 changed files with 640 additions and 336 deletions

View File

@@ -440,9 +440,6 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
font.dispose();
}
if(GameSettings.getEntityCreator() != null)
GameSettings.getEntityCreator().dispose();
// Dispose screens.
for(int i = 0; i < states.length; i++){
states[i].dispose();

View File

@@ -0,0 +1,51 @@
/*
* 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.math.Vector3;
public class AutomaticMovementComponent extends Component{
public boolean moving;
public boolean forward;
public float distance;
public Vector3 startPoint;
public Vector3 endPoint;
public AutomaticMovementComponent(Vector3 startPoint, Vector3 endPoint, boolean moving){
this.moving = moving;
this.forward = true;
this.distance = 0.0f;
this.startPoint = startPoint;
this.endPoint = endPoint;
}
public AutomaticMovementComponent(Vector3 startPoint, Vector3 endPoint){
this(startPoint, endPoint, false);
}
public AutomaticMovementComponent(boolean moving){
this(new Vector3(0.0f, 0.0f, 0.0f), new Vector3(), moving);
}
public AutomaticMovementComponent(Vector3 endPoint){
this(new Vector3(0.0f, 0.0f, 0.0f), endPoint, false);
}
public AutomaticMovementComponent(){
this(false);
}
}

View File

@@ -16,6 +16,7 @@
package ve.ucv.ciens.ccg.nxtar.entities;
import ve.ucv.ciens.ccg.nxtar.components.AnimationComponent;
import ve.ucv.ciens.ccg.nxtar.components.AutomaticMovementComponent;
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.BombGameObjectTypeComponent;
@@ -232,12 +233,13 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private void addRobotArm(EntityParameters parameters){
Entity robotArm = world.createEntity();
robotArm.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, -0.5f), new Matrix3(), new Vector3(1, 1, 1)));
robotArm.addComponent(new GeometryComponent(new Vector3(0.0f, 0.0f, -1.0f), 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.addComponent(new CollisionDetectionComponent());
robotArm.addComponent(new AutomaticMovementComponent());
robotArm.addToWorld();
}

View File

@@ -21,7 +21,7 @@ public class TouchUserInput extends UserInput {
public Vector3 userTouchEndPoint;
public TouchUserInput(){
this.userTouchEndPoint = null;
this.userTouchEndPoint = new Vector3();
}
public TouchUserInput(Vector3 userTouchEndPoint){

File diff suppressed because it is too large Load Diff

View File

@@ -15,6 +15,7 @@
*/
package ve.ucv.ciens.ccg.nxtar.systems;
import ve.ucv.ciens.ccg.nxtar.components.AutomaticMovementComponent;
import ve.ucv.ciens.ccg.nxtar.components.CollisionDetectionComponent;
import ve.ucv.ciens.ccg.nxtar.components.GeometryComponent;
import ve.ucv.ciens.ccg.nxtar.components.MarkerCodeComponent;
@@ -22,30 +23,33 @@ import ve.ucv.ciens.ccg.nxtar.input.GamepadUserInput;
import ve.ucv.ciens.ccg.nxtar.input.KeyboardUserInput;
import ve.ucv.ciens.ccg.nxtar.input.TouchUserInput;
import ve.ucv.ciens.ccg.nxtar.input.UserInput;
import ve.ucv.ciens.ccg.nxtar.utils.Utils;
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.math.Vector3;
public class RobotArmPositioningSystem extends EntityProcessingSystem {
private static final String TAG = "ROBOT_ARM_POSITIONING_SYSTEM";
private static final String CLASS_NAME = RobotArmPositioningSystem.class.getSimpleName();
private static final float INTERPOLATION_STEP = 0.05f;
private static final float STEP_SIZE = 0.05f;
private static final Vector3 END_POINT = new Vector3(-1.0f, 0.0f, 0.0f);
private static final Vector3 END_POINT = new Vector3(0.0f, 0.0f, -0.5f);
private static final float MAX_Z = -4.5f;
@Mapper ComponentMapper<GeometryComponent> geometryMapper;
// @Mapper ComponentMapper<AutomaticMovementComponent> autoMapper;
@Mapper ComponentMapper<AutomaticMovementComponent> autoMapper;
@Mapper ComponentMapper<CollisionDetectionComponent> collisionMapper;
private UserInput input;
@SuppressWarnings("unchecked")
public RobotArmPositioningSystem(){
super(Aspect.getAspectForAll(GeometryComponent.class, /*AutomaticMovementComponent.class,*/ CollisionDetectionComponent.class).exclude(MarkerCodeComponent.class));
super(Aspect.getAspectForAll(GeometryComponent.class, AutomaticMovementComponent.class, CollisionDetectionComponent.class).exclude(MarkerCodeComponent.class));
}
public void setUserInput(UserInput input){
@@ -58,61 +62,58 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
GamepadUserInput tempGP;
KeyboardUserInput tempKey;
GeometryComponent geometry = geometryMapper.get(e);
// AutomaticMovementComponent auto = autoMapper.get(e);
AutomaticMovementComponent auto = autoMapper.get(e);
CollisionDetectionComponent collision = collisionMapper.get(e);
if(input == null){
/*if(auto.moving) autoMove(geometry, auto, collision);
else */return;
if(auto.moving) autoMove(geometry, auto, collision);
else return;
}else{
if(input instanceof TouchUserInput){
// if(!auto.moving){
// endPoint = ((TouchUserInput) input).userTouchEndPoint;
// endPoint.set(endPoint.x, endPoint.y, MAX_Z);
// auto.startPoint.set(geometry.position);
// auto.endPoint.set(endPoint);
// auto.moving = true;
// auto.forward = true;
//
// auto.target.set(endPoint).sub(auto.startPoint);
// auto.epsilon = 0.05f;
//
// Gdx.app.log(TAG, CLASS_NAME + ".process(): Started moving from " + Utils.vector2String(auto.startPoint) + " to " + Utils.vector2String(auto.endPoint));
// }else autoMove(geometry, auto, collision);
if(!auto.moving){
endPoint = ((TouchUserInput) input).userTouchEndPoint;
endPoint.set(endPoint.x, endPoint.y, MAX_Z);
auto.startPoint.set(geometry.position);
auto.endPoint.set(endPoint);
auto.moving = true;
auto.forward = true;
Gdx.app.log(TAG, CLASS_NAME + ".process(): Started moving from " + Utils.vector2String(auto.startPoint) + " to " + Utils.vector2String(auto.endPoint));
}else autoMove(geometry, auto, collision);
}else if(input instanceof GamepadUserInput){
// tempGP = (GamepadUserInput) input;
//
// if(!collision.colliding && !auto.moving){
// geometry.position.x += tempGP.axisLeftY * STEP_SIZE;
// geometry.position.y += tempGP.axisLeftX * STEP_SIZE;
// geometry.position.z += tempGP.axisRightY * STEP_SIZE;
tempGP = (GamepadUserInput) input;
if(!collision.colliding){
geometry.position.x += tempGP.axisLeftY * STEP_SIZE;
geometry.position.y += tempGP.axisLeftX * STEP_SIZE;
geometry.position.z += tempGP.axisRightY * STEP_SIZE;
//clampPosition(geometry);
// }else{
// auto.moving = true;
// auto.forward = false;
// auto.startPoint.set(geometry.position);
// auto.endPoint.set(END_POINT);
// }
}else{
auto.moving = true;
auto.forward = false;
auto.startPoint.set(geometry.position);
auto.endPoint.set(END_POINT);
}
}else if(input instanceof KeyboardUserInput){
// tempKey = (KeyboardUserInput) input;
//
// if(!collision.colliding && !auto.moving){
// geometry.position.x -= tempKey.keyUp ? STEP_SIZE : 0.0f;
// geometry.position.x += tempKey.keyDown ? STEP_SIZE : 0.0f;
// geometry.position.y -= tempKey.keyLeft ? STEP_SIZE : 0.0f;
// geometry.position.y += tempKey.keyRight ? STEP_SIZE : 0.0f;
// geometry.position.z -= tempKey.keyZ ? STEP_SIZE : 0.0f;
// geometry.position.z += tempKey.keyA ? STEP_SIZE : 0.0f;
tempKey = (KeyboardUserInput) input;
if(!collision.colliding){
geometry.position.x += tempKey.keyUp ? STEP_SIZE : 0.0f;
geometry.position.x -= tempKey.keyDown ? STEP_SIZE : 0.0f;
geometry.position.y -= tempKey.keyLeft ? STEP_SIZE : 0.0f;
geometry.position.y += tempKey.keyRight ? STEP_SIZE : 0.0f;
geometry.position.z -= tempKey.keyZ ? STEP_SIZE : 0.0f;
geometry.position.z += tempKey.keyA ? STEP_SIZE : 0.0f;
//clampPosition(geometry);
// }else{
// auto.moving = true;
// auto.forward = false;
// auto.startPoint.set(geometry.position);
// auto.endPoint.set(END_POINT);
// }
}else{
auto.moving = true;
auto.forward = false;
auto.startPoint.set(geometry.position);
auto.endPoint.set(END_POINT);
}
}else
throw new ClassCastException("Input is not a valid UserInput instance.");
@@ -121,45 +122,45 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
input = null;
}
// private void autoMove(GeometryComponent geometry, AutomaticMovementComponent auto, CollisionDetectionComponent collision){
// float step;
//
// if(auto.moving){
// if(auto.forward)
// step = STEP_SIZE;
// else
// step = -STEP_SIZE;
//
// Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Step = " + Float.toString(step));
//
// auto.distance += step;
//
// Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Step = " + Float.toString(auto.distance));
//
// geometry.position.x = (auto.startPoint.x * (1.0f - auto.distance)) + (auto.endPoint.x * auto.distance);
// geometry.position.y = (auto.startPoint.y * (1.0f - auto.distance)) + (auto.endPoint.y * auto.distance);
// geometry.position.z = (auto.startPoint.z * (1.0f - auto.distance)) + (auto.endPoint.z * auto.distance);
//
// Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Current position: " + Utils.vector2String(geometry.position));
//
// if(auto.distance <= 0.0f){
// auto.forward = true;
// auto.moving = false;
// Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Going forward now.");
// }else if(auto.distance >= 1.0f || collision.colliding){
// auto.forward = false;
// Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Going backwards now.");
// }
//
// }else return;
// }
private void autoMove(GeometryComponent geometry, AutomaticMovementComponent auto, CollisionDetectionComponent collision){
float step;
private void clampPosition(GeometryComponent geometry){
geometry.position.x = geometry.position.x >= -1.0f ? geometry.position.x : -1.0f;
geometry.position.x = geometry.position.x <= 1.0f ? geometry.position.x : 1.0f;
geometry.position.y = geometry.position.y >= -1.0f ? geometry.position.y : -1.0f;
geometry.position.y = geometry.position.y <= 1.0f ? geometry.position.y : 1.0f;
geometry.position.z = geometry.position.z >= 0.0f ? geometry.position.z : 0.0f;
geometry.position.z = geometry.position.z <= 6.0f ? geometry.position.z : 6.0f;
if(auto.moving){
if(auto.forward)
step = INTERPOLATION_STEP;
else
step = -INTERPOLATION_STEP;
Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Step = " + Float.toString(step));
auto.distance += step;
Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Step = " + Float.toString(auto.distance));
geometry.position.x = (auto.startPoint.x * (1.0f - auto.distance)) + (auto.endPoint.x * auto.distance);
geometry.position.y = (auto.startPoint.y * (1.0f - auto.distance)) + (auto.endPoint.y * auto.distance);
geometry.position.z = (auto.startPoint.z * (1.0f - auto.distance)) + (auto.endPoint.z * auto.distance);
Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Current position: " + Utils.vector2String(geometry.position));
if(auto.distance <= 0.0f){
auto.forward = true;
auto.moving = false;
Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Going forward now.");
}else if(auto.distance >= 1.0f || collision.colliding){
auto.forward = false;
Gdx.app.log(TAG, CLASS_NAME + ".autoMove(): Going backwards now.");
}
}else return;
}
// private void clampPosition(GeometryComponent geometry){
// geometry.position.x = geometry.position.x >= -1.0f ? geometry.position.x : -1.0f;
// geometry.position.x = geometry.position.x <= 1.0f ? geometry.position.x : 1.0f;
// geometry.position.y = geometry.position.y >= -1.0f ? geometry.position.y : -1.0f;
// geometry.position.y = geometry.position.y <= 1.0f ? geometry.position.y : 1.0f;
// geometry.position.z = geometry.position.z >= 0.0f ? geometry.position.z : 0.0f;
// geometry.position.z = geometry.position.z <= 6.0f ? geometry.position.z : 6.0f;
// }
}

View File

@@ -49,9 +49,11 @@ public abstract class GameSettings{
}
public static void clearGameSettings(){
entityCreator.dispose();
entityCreator = null;
gameLogicSystem = null;
gameWorld = null;
System.gc();
}
/**