Scrapped robot arm movement.

This commit is contained in:
2014-06-13 16:47:23 -04:30
parent 6c63ebf907
commit 7f20a09eb9
7 changed files with 98 additions and 132 deletions

View File

@@ -447,6 +447,8 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
for(int i = 0; i < states.length; i++){ for(int i = 0; i < states.length; i++){
states[i].dispose(); states[i].dispose();
} }
GameSettings.clearGameSettings();
} }
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; /*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

View File

@@ -1,35 +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.components;
import com.artemis.Component;
import com.badlogic.gdx.math.Vector3;
public class AutomaticMovementComponent extends Component {
public boolean moving;
public boolean forward;
public Vector3 startPoint;
public Vector3 endPoint;
public float distance;
public AutomaticMovementComponent(){
this.moving = false;
this.forward = true;
this.startPoint = new Vector3();
this.endPoint = new Vector3();
this.distance = 0.0f;
}
}

View File

@@ -16,7 +16,6 @@
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.AutomaticMovementComponent;
import ve.ucv.ciens.ccg.nxtar.components.BombComponent; 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.BombComponent.bomb_type_t;
import ve.ucv.ciens.ccg.nxtar.components.BombGameObjectTypeComponent; import ve.ucv.ciens.ccg.nxtar.components.BombGameObjectTypeComponent;
@@ -52,7 +51,7 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private static final boolean DEBUG_RENDER_BOMB_COLLISION_MODELS = false; private static final boolean DEBUG_RENDER_BOMB_COLLISION_MODELS = false;
private static final boolean DEBUG_RENDER_DOOR_COLLISION_MODELS = false; private static final boolean DEBUG_RENDER_DOOR_COLLISION_MODELS = false;
private static final boolean DEBUG_RENDER_PARAPHERNALIA_COLLISION_MODELS = false; private static final boolean DEBUG_RENDER_PARAPHERNALIA_COLLISION_MODELS = false;
public static final String DOORS_GROUP = "DOORS"; public static final String DOORS_GROUP = "DOORS";
private class EntityParameters{ private class EntityParameters{
public Environment environment; public Environment environment;
@@ -233,12 +232,11 @@ public class BombGameEntityCreator extends EntityCreatorBase{
private void addRobotArm(EntityParameters parameters){ private void addRobotArm(EntityParameters parameters){
Entity robotArm = world.createEntity(); 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, -0.5f), new Matrix3(), new Vector3(1, 1, 1)));
robotArm.addComponent(new EnvironmentComponent(parameters.environment)); robotArm.addComponent(new EnvironmentComponent(parameters.environment));
robotArm.addComponent(new ShaderComponent(parameters.shader)); robotArm.addComponent(new ShaderComponent(parameters.shader));
robotArm.addComponent(new RenderModelComponent(robotArmModel)); robotArm.addComponent(new RenderModelComponent(robotArmModel));
robotArm.addComponent(new CollisionModelComponent(robotArmCollisionModel)); robotArm.addComponent(new CollisionModelComponent(robotArmCollisionModel));
robotArm.addComponent(new AutomaticMovementComponent());
robotArm.addComponent(new CollisionDetectionComponent()); robotArm.addComponent(new CollisionDetectionComponent());
robotArm.addToWorld(); robotArm.addToWorld();
} }

View File

@@ -167,7 +167,7 @@ public class DirectionalLightPerPixelShader implements Shader{
float shininess; float shininess;
// Get material colors. // Get material colors.
if(renderable.environment.directionalLights.size >= 1){ if(renderable.environment != null && renderable.environment.directionalLights != null && renderable.environment.directionalLights.size >= 1){
lightPosition = renderable.environment.directionalLights.get(0).direction; lightPosition = renderable.environment.directionalLights.get(0).direction;
diffuseLightColor = renderable.environment.directionalLights.get(0).color; diffuseLightColor = renderable.environment.directionalLights.get(0).color;
}else{ }else{
@@ -185,7 +185,7 @@ public class DirectionalLightPerPixelShader implements Shader{
else else
specularColor = Color.BLACK; specularColor = Color.BLACK;
if(renderable.environment.has(ColorAttribute.AmbientLight)) if(renderable.environment != null && renderable.environment.has(ColorAttribute.AmbientLight))
ambientColor = ((ColorAttribute)renderable.environment.get(ColorAttribute.AmbientLight)).color; ambientColor = ((ColorAttribute)renderable.environment.get(ColorAttribute.AmbientLight)).color;
else else
ambientColor = Color.BLACK; ambientColor = Color.BLACK;

View File

@@ -82,7 +82,7 @@ public class InGameState extends BaseState{
// Cameras. // Cameras.
private OrthographicCamera unitaryOrthographicCamera; private OrthographicCamera unitaryOrthographicCamera;
private OrthographicCamera pixelPerfectOrthoCamera; private OrthographicCamera pixelPerfectOrthographicCamera;
private CustomPerspectiveCamera perspectiveCamera; private CustomPerspectiveCamera perspectiveCamera;
// Video stream graphics. // Video stream graphics.
@@ -119,7 +119,7 @@ public class InGameState extends BaseState{
videoFrame = null; videoFrame = null;
// Set up the cameras. // Set up the cameras.
pixelPerfectOrthoCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); pixelPerfectOrthographicCamera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
unitaryOrthographicCamera = new OrthographicCamera(1.0f, Gdx.graphics.getHeight() / Gdx.graphics.getWidth()); unitaryOrthographicCamera = new OrthographicCamera(1.0f, Gdx.graphics.getHeight() / Gdx.graphics.getWidth());
if(!Ouya.runningOnOuya) setUpButtons(); if(!Ouya.runningOnOuya) setUpButtons();
@@ -217,7 +217,7 @@ public class InGameState extends BaseState{
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT); Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
// Render the background. // Render the background.
core.batch.setProjectionMatrix(pixelPerfectOrthoCamera.combined); core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
core.batch.begin();{ core.batch.begin();{
if(backgroundShader != null){ if(backgroundShader != null){
core.batch.setShader(backgroundShader); core.batch.setShader(backgroundShader);
@@ -293,6 +293,7 @@ public class InGameState extends BaseState{
objectRenderingSystem.begin(perspectiveCamera); objectRenderingSystem.begin(perspectiveCamera);
objectRenderingSystem.process(); objectRenderingSystem.process();
objectRenderingSystem.end(); objectRenderingSystem.end();
}frameBuffer.end(); }frameBuffer.end();
// Set the frame buffer object texture to a renderable sprite. // Set the frame buffer object texture to a renderable sprite.
@@ -329,7 +330,7 @@ public class InGameState extends BaseState{
if(!Ouya.runningOnOuya){ if(!Ouya.runningOnOuya){
core.batch.setProjectionMatrix(unitaryOrthographicCamera.combined); core.batch.setProjectionMatrix(unitaryOrthographicCamera.combined);
}else{ }else{
core.batch.setProjectionMatrix(pixelPerfectOrthoCamera.combined); core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
} }
// Render the video frame and the frame buffer. // Render the video frame and the frame buffer.
@@ -344,7 +345,7 @@ public class InGameState extends BaseState{
// Render the interface buttons. // Render the interface buttons.
if(!Ouya.runningOnOuya){ if(!Ouya.runningOnOuya){
core.batch.setProjectionMatrix(pixelPerfectOrthoCamera.combined); core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
core.batch.begin();{ core.batch.begin();{
motorA.draw(core.batch); motorA.draw(core.batch);
motorB.draw(core.batch); motorB.draw(core.batch);
@@ -541,13 +542,6 @@ public class InGameState extends BaseState{
touchPointWorldCoords.set(win2world.x, win2world.y); touchPointWorldCoords.set(win2world.x, win2world.y);
if(frameBufferSprite != null && frameBufferSprite.getBoundingRectangle().contains(touchPointWorldCoords)){ if(frameBufferSprite != null && frameBufferSprite.getBoundingRectangle().contains(touchPointWorldCoords)){
Gdx.app.log(TAG, CLASS_NAME + "touchDown(): Touch point inside framebuffer."); Gdx.app.log(TAG, CLASS_NAME + "touchDown(): Touch point inside framebuffer.");
TEMP_VEC_3.set(screenX, screenY, 1.0f);
perspectiveCamera.unproject(TEMP_VEC_3, frameBufferSprite.getX(), frameBufferSprite.getY(), frameBufferSprite.getWidth() * Gdx.graphics.getWidth(), frameBufferSprite.getHeight() * Gdx.graphics.getHeight());
TEMP_VEC_3.rotate(Vector3.Z, 90).nor();
TEMP_VEC_3.y = -TEMP_VEC_3.y;
//Gdx.app.log("TAG", CLASS_NAME + "touchDown(): Unprojected" + Utils.vector2String(TEMP_VEC_3));
input = new TouchUserInput(TEMP_VEC_3); input = new TouchUserInput(TEMP_VEC_3);
robotArmPositioningSystem.setUserInput(input); robotArmPositioningSystem.setUserInput(input);
}else{ }else{

View File

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

View File

@@ -48,6 +48,12 @@ public abstract class GameSettings{
gameLogicSystem = new BombGameLogicSystem(); gameLogicSystem = new BombGameLogicSystem();
} }
public static void clearGameSettings(){
entityCreator = null;
gameLogicSystem = null;
gameWorld = null;
}
/** /**
* @return the entityCreator * @return the entityCreator
*/ */