Scrapped robot arm movement.
This commit is contained in:
@@ -447,6 +447,8 @@ public class NxtARCore extends Game implements ApplicationEventsListener{
|
||||
for(int i = 0; i < states.length; i++){
|
||||
states[i].dispose();
|
||||
}
|
||||
|
||||
GameSettings.clearGameSettings();
|
||||
}
|
||||
|
||||
/*;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,6 @@
|
||||
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;
|
||||
@@ -233,12 +232,11 @@ 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, -0.5f), 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 AutomaticMovementComponent());
|
||||
robotArm.addComponent(new CollisionDetectionComponent());
|
||||
robotArm.addToWorld();
|
||||
}
|
||||
|
||||
@@ -167,7 +167,7 @@ public class DirectionalLightPerPixelShader implements Shader{
|
||||
float shininess;
|
||||
|
||||
// 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;
|
||||
diffuseLightColor = renderable.environment.directionalLights.get(0).color;
|
||||
}else{
|
||||
@@ -185,7 +185,7 @@ public class DirectionalLightPerPixelShader implements Shader{
|
||||
else
|
||||
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;
|
||||
else
|
||||
ambientColor = Color.BLACK;
|
||||
|
||||
@@ -82,7 +82,7 @@ public class InGameState extends BaseState{
|
||||
|
||||
// Cameras.
|
||||
private OrthographicCamera unitaryOrthographicCamera;
|
||||
private OrthographicCamera pixelPerfectOrthoCamera;
|
||||
private OrthographicCamera pixelPerfectOrthographicCamera;
|
||||
private CustomPerspectiveCamera perspectiveCamera;
|
||||
|
||||
// Video stream graphics.
|
||||
@@ -119,7 +119,7 @@ public class InGameState extends BaseState{
|
||||
videoFrame = null;
|
||||
|
||||
// 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());
|
||||
|
||||
if(!Ouya.runningOnOuya) setUpButtons();
|
||||
@@ -217,7 +217,7 @@ public class InGameState extends BaseState{
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
|
||||
// Render the background.
|
||||
core.batch.setProjectionMatrix(pixelPerfectOrthoCamera.combined);
|
||||
core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
|
||||
core.batch.begin();{
|
||||
if(backgroundShader != null){
|
||||
core.batch.setShader(backgroundShader);
|
||||
@@ -293,6 +293,7 @@ public class InGameState extends BaseState{
|
||||
objectRenderingSystem.begin(perspectiveCamera);
|
||||
objectRenderingSystem.process();
|
||||
objectRenderingSystem.end();
|
||||
|
||||
}frameBuffer.end();
|
||||
|
||||
// Set the frame buffer object texture to a renderable sprite.
|
||||
@@ -329,7 +330,7 @@ public class InGameState extends BaseState{
|
||||
if(!Ouya.runningOnOuya){
|
||||
core.batch.setProjectionMatrix(unitaryOrthographicCamera.combined);
|
||||
}else{
|
||||
core.batch.setProjectionMatrix(pixelPerfectOrthoCamera.combined);
|
||||
core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
|
||||
}
|
||||
|
||||
// Render the video frame and the frame buffer.
|
||||
@@ -344,7 +345,7 @@ public class InGameState extends BaseState{
|
||||
|
||||
// Render the interface buttons.
|
||||
if(!Ouya.runningOnOuya){
|
||||
core.batch.setProjectionMatrix(pixelPerfectOrthoCamera.combined);
|
||||
core.batch.setProjectionMatrix(pixelPerfectOrthographicCamera.combined);
|
||||
core.batch.begin();{
|
||||
motorA.draw(core.batch);
|
||||
motorB.draw(core.batch);
|
||||
@@ -541,13 +542,6 @@ public class InGameState extends BaseState{
|
||||
touchPointWorldCoords.set(win2world.x, win2world.y);
|
||||
if(frameBufferSprite != null && frameBufferSprite.getBoundingRectangle().contains(touchPointWorldCoords)){
|
||||
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);
|
||||
robotArmPositioningSystem.setUserInput(input);
|
||||
}else{
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
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;
|
||||
@@ -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.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 {
|
||||
@@ -38,16 +35,17 @@ public class RobotArmPositioningSystem extends EntityProcessingSystem {
|
||||
private static final String CLASS_NAME = RobotArmPositioningSystem.class.getSimpleName();
|
||||
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 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){
|
||||
@@ -60,58 +58,61 @@ 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, -4.5f);
|
||||
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);
|
||||
// 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);
|
||||
|
||||
}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;
|
||||
clampPosition(geometry);
|
||||
}else{
|
||||
auto.moving = true;
|
||||
auto.forward = false;
|
||||
auto.startPoint.set(geometry.position);
|
||||
auto.endPoint.set(END_POINT);
|
||||
}
|
||||
// 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;
|
||||
// clampPosition(geometry);
|
||||
// }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;
|
||||
clampPosition(geometry);
|
||||
}else{
|
||||
auto.moving = true;
|
||||
auto.forward = false;
|
||||
auto.startPoint.set(geometry.position);
|
||||
auto.endPoint.set(END_POINT);
|
||||
}
|
||||
// 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;
|
||||
// clampPosition(geometry);
|
||||
// }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.");
|
||||
@@ -120,38 +121,38 @@ 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;
|
||||
//
|
||||
// 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 clampPosition(GeometryComponent geometry){
|
||||
geometry.position.x = geometry.position.x >= -1.0f ? geometry.position.x : -1.0f;
|
||||
|
||||
@@ -48,6 +48,12 @@ public abstract class GameSettings{
|
||||
gameLogicSystem = new BombGameLogicSystem();
|
||||
}
|
||||
|
||||
public static void clearGameSettings(){
|
||||
entityCreator = null;
|
||||
gameLogicSystem = null;
|
||||
gameWorld = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the entityCreator
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user