//Copyright (c) 2014, Jesús Martín Berlanga. All rights reserved. //Distributed under the BSD licence. Read "com/jme3/ai/license.txt". package steeringDemos.control; import com.jme3.ai.agents.Agent; import com.jme3.ai.agents.util.GameEntity; import com.jme3.ai.agents.util.control.MonkeyBrainsAppState; import com.jme3.ai.agents.util.control.GameControl; import com.jme3.input.FlyByCamera; import com.jme3.math.FastMath; import com.jme3.math.Vector3f; import com.jme3.renderer.Camera; /** * Custom steer control. * * @author Jesús Martín Berlanga * @version 1.3.1 */ public class CustomSteerControl implements GameControl { private float cameraMoveSpeed; private float aleatoryFactorX, aleatoryFactorY, aleatoryFactorZ; private MonkeyBrainsAppState brainsAppState = MonkeyBrainsAppState.getInstance(); /** * There is no input mapping by default. */ public void setInputManagerMapping() { //Void } public void setCameraSettings(Camera cam) { cam.setLocation(new Vector3f(0, 20, 0)); cam.lookAt(Vector3f.ZERO, Vector3f.UNIT_X); } public void setFlyCameraSettings(FlyByCamera flyCam) { flyCam.setMoveSpeed(this.cameraMoveSpeed); } public CustomSteerControl(float cameraMoveSpeed) { this.cameraMoveSpeed = cameraMoveSpeed; this.aleatoryFactorX = 10f; this.aleatoryFactorY = 10f; this.aleatoryFactorZ = 10f; } public CustomSteerControl(float cameraMoveSpeed, float aleatoryFactor) { this.cameraMoveSpeed = cameraMoveSpeed; this.aleatoryFactorX = aleatoryFactor; this.aleatoryFactorY = aleatoryFactor; this.aleatoryFactorZ = aleatoryFactor; } public CustomSteerControl(float cameraMoveSpeed, float aleatoryFactorX, float aleatoryFactorY, float aleatoryFactorZ) { this.cameraMoveSpeed = cameraMoveSpeed; this.aleatoryFactorX = aleatoryFactorX; this.aleatoryFactorY = aleatoryFactorY; this.aleatoryFactorZ = aleatoryFactorZ; } /** * @see GameControl#finish() * * @return Always return false. */ public boolean finish() { return false; } /** * @see GameControl#win(com.jme3.ai.agents.Agent) * * @param agent * @return Always return false. */ public boolean win(Agent agent) { return false; } /** * There is no restart. * * @see GameControl#restart() */ public void restart() { //Void } /** * Method for creating objects in given area. * * PRE: The area must be void or a point.
*
* * @param gameEntity entity that should be created * @param area Null for random location and a point for a stablished * location. * * @see GameControl#spawn(com.jme3.ai.agents.util.GameEntity, * com.jme3.math.Vector3f[]) */ public void spawn(GameEntity gameEntity, Vector3f... area) { if (area == null) { //Random location gameEntity.setLocalTranslation( ((float) ((FastMath.nextRandomFloat() * 2) - 1)) * this.aleatoryFactorX, ((float) ((FastMath.nextRandomFloat() * 2) - 1)) * this.aleatoryFactorY, ((float) ((FastMath.nextRandomFloat() * 2) - 1)) * this.aleatoryFactorZ); } else if (area.length == 1) { //Spawn in a point gameEntity.setLocalTranslation(area[0]); } if (gameEntity instanceof Agent) { brainsAppState.addAgent((Agent) gameEntity); } else { brainsAppState.addGameEntity(gameEntity); } } }