Java 类com.badlogic.gdx.ai.steer.SteeringBehavior 实例源码
项目:Inspiration
文件:PrioritySteering.java
@Override
protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) {
// We'll need epsilon squared later.
float epsilonSquared = epsilon * epsilon;
// Go through the behaviors until one has a large enough acceleration
int n = behaviors.size;
selectedBehaviorIndex = -1;
for (int i = 0; i < n; i++) {
selectedBehaviorIndex = i;
SteeringBehavior<T> behavior = behaviors.get(i);
// Calculate the behavior's steering
behavior.calculateSteering(steering);
// If we're above the threshold return the current steering
if (steering.calculateSquareMagnitude() > epsilonSquared) return steering;
}
// If we get here, it means that no behavior had a large enough acceleration,
// so return the small acceleration from the final behavior or zero if there are
// no behaviors in the list.
return n > 0 ? steering : steering.setZero();
}
项目:gdx-ai
文件:PrioritySteering.java
@Override
protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) {
// We'll need epsilon squared later.
float epsilonSquared = epsilon * epsilon;
// Go through the behaviors until one has a large enough acceleration
int n = behaviors.size;
selectedBehaviorIndex = -1;
for (int i = 0; i < n; i++) {
selectedBehaviorIndex = i;
SteeringBehavior<T> behavior = behaviors.get(i);
// Calculate the behavior's steering
behavior.calculateSteering(steering);
// If we're above the threshold return the current steering
if (steering.calculateSquareMagnitude() > epsilonSquared) return steering;
}
// If we get here, it means that no behavior had a large enough acceleration,
// so return the small acceleration from the final behavior or zero if there are
// no behaviors in the list.
return n > 0 ? steering : steering.setZero();
}
项目:gdxjam-ugg
文件:BehaviorUtils.java
public static SteerLocation getTarget(SteeringBehavior behavior){
SteerLocation targetL = null;
if(behavior instanceof Face) targetL = (SteerLocation)((Face) behavior).getTarget();
else if(behavior instanceof Arrive) targetL = (SteerLocation)((Arrive) behavior).getTarget();
else if(behavior instanceof Seek) targetL = (SteerLocation)((Seek) behavior).getTarget();
return targetL;
}
项目:GDXJam
文件:EntityFactory.java
public static Entity createSquad (Vector2 position, Faction faction) {
Entity entity = builder.createEntity(EntityCategory.SQUAD, position).physicsBody(BodyType.DynamicBody).circleSensor(30.0f)
.faction(faction).target().filter(EntityCategory.SQUAD, 0, EntityCategory.SQUAD | EntityCategory.RESOURCE)
.steeringBehavior().stateMachine().getWithoutAdding();
SteerableComponent steerable = engine.createComponent(SteerableComponent.class).init(
Components.PHYSICS.get(entity).getBody(), 30.0f);
SquadComponent squadComp = engine.createComponent(SquadComponent.class).init(steerable);
squadComp.targetLocation.getPosition().set(position);
entity.add(squadComp);
// A good rule of thumb is to make the maximum speed of the formation
// around
// half that of the members. We also give the anchor point far less
// acceleration.
steerable.setMaxLinearSpeed(SteerableComponent.MAX_LINEAR_SPEED / 2);
steerable.setMaxLinearAcceleration(SteerableComponent.MAX_LINEAR_ACCELERATION / 10);
Arrive<Vector2> arriveSB = new Arrive<Vector2>(steerable).setTarget(squadComp.targetLocation).setTimeToTarget(0.001f)
.setDecelerationRadius(2f).setArrivalTolerance(0.0001f);
SteeringBehavior<Vector2> sb = arriveSB;
RadiusProximity<Vector2> proximity = new RadiusProximity<Vector2>(steerable, squadComp.friendlyAgents, 3.0f);
Separation<Vector2> separationSB = new Separation<Vector2>(steerable, proximity);
BlendedSteering<Vector2> blendedSteering = new BlendedSteering<Vector2>(steerable) //
.setLimiter(NullLimiter.NEUTRAL_LIMITER) //
.add(separationSB, 10000f)
.add(arriveSB, 0.5f);
sb = blendedSteering;
Components.FSM.get(entity).changeState(SquadComponent.DEFAULT_STATE);
Components.STEERING_BEHAVIOR.get(entity).setBehavior(sb);
entity.add(steerable);
engine.addEntity(entity);
return entity;
}
项目:gdx-ai
文件:BlendedSteering.java
/** Removes a steering behavior from the list.
* @param behavior the steering behavior to remove */
public void remove (SteeringBehavior<T> behavior) {
for (int i = 0; i < list.size; i++) {
if(list.get(i).behavior == behavior) {
list.removeIndex(i);
return;
}
}
}
项目:DarkDay
文件:B2dSteeringEntity.java
public void setBehavior(SteeringBehavior<Vector2> behavior) {
this.behavior = behavior;
}
项目:DarkDay
文件:B2dSteeringEntity.java
public SteeringBehavior<Vector2> getBehavior() {
return behavior;
}
项目:gdxjam-ugg
文件:GameEntity.java
public <T extends SteeringBehavior> SteeringBehavior getBehavior(Class<T> behaviorClass){
return cachedBehaviors.get(behaviorClass);
}
项目:gdxjam-ugg
文件:GameEntity.java
public GameEntity cacheBehavior(SteeringBehavior behavior){
if(behavior == null) return this;
this.cachedBehaviors.put(behavior.getClass(), behavior);
return this;
}
项目:JACWfA
文件:Agent.java
public SteeringBehavior<Vector2> getSteeringBehavior() {
return steeringBehavior;
}
项目:JACWfA
文件:Agent.java
public void setSteeringBehavior(SteeringBehavior<Vector2> steeringBehavior) {
this.steeringBehavior = steeringBehavior;
}
项目:Inspiration
文件:BlendedSteering.java
public BehaviorAndWeight (SteeringBehavior<T> behavior, float weight) {
this.behavior = behavior;
this.weight = weight;
}
项目:Inspiration
文件:BlendedSteering.java
public SteeringBehavior<T> getBehavior () {
return behavior;
}
项目:Inspiration
文件:BlendedSteering.java
public void setBehavior (SteeringBehavior<T> behavior) {
this.behavior = behavior;
}
项目:Inspiration
文件:PrioritySteering.java
/** Adds the specified behavior to the priority list.
* @param behavior the behavior to add
* @return this behavior for chaining. */
public PrioritySteering<T> add (SteeringBehavior<T> behavior) {
behaviors.add(behavior);
return this;
}
项目:Pacman_libGdx
文件:GhostAI.java
public SteeringBehavior<Vector2> getSteeringBehavior() {
return steeringBehavior;
}
项目:Pacman_libGdx
文件:GhostAI.java
public void setSteeringBehavior(SteeringBehavior<Vector2> steeringBehavior) {
this.steeringBehavior = steeringBehavior;
}
项目:GdxDemo3D
文件:CollisionAvoidanceSteererBase.java
@Override
public SteeringBehavior<Vector3> getSteeringBehavior() {
return prioritySteering;
}
项目:GDXJam
文件:SteeringSystem.java
@Override
protected void processEntity(Entity entity, float deltaTime) {
SteeringBehavior<Vector2> behavior = Components.STEERING_BEHAVIOR.get(entity).getBehavior();
SteerableComponent steerable = Components.STEERABLE.get(entity);
if(behavior == null) return;
if(steerable.getBody() == null) return; //We shouldn't need this
behavior.calculateSteering(steeringOutput);
boolean anyAccelerations = false;
Body body = steerable.getBody();
if (!steeringOutput.linear.isZero()) {
Vector2 force = steeringOutput.linear.scl(deltaTime);
body.applyForceToCenter(force, true);
anyAccelerations = true;
}
// Update orientation and angular velocity
if (steerable.isIndependentFacing()) {
if (steeringOutput.angular != 0) {
body.applyTorque(steeringOutput.angular * deltaTime, true);
anyAccelerations = true;
}
}
else {
// If we haven't got any velocity, then we can do nothing.
Vector2 linVel = body.getLinearVelocity();
if (!linVel.isZero(steerable.getZeroLinearSpeedThreshold())) {
float newOrientation = steerable.vectorToAngle(linVel);
body.setAngularVelocity((newOrientation - steerable.getAngularVelocity()) * deltaTime); // this is superfluous if independentFacing is always true
body.setTransform(body.getPosition(), newOrientation);
}
}
if (anyAccelerations) {
// Cap the linear speed
Vector2 velocity = body.getLinearVelocity();
float currentSpeedSquare = velocity.len2();
float maxLinearSpeed = steerable.getMaxLinearSpeed();
if (currentSpeedSquare > maxLinearSpeed * maxLinearSpeed) {
body.setLinearVelocity(velocity.scl(maxLinearSpeed / (float)Math.sqrt(currentSpeedSquare)));
}
// Cap the angular speed
float maxAngVelocity = steerable.getMaxAngularSpeed();
if (body.getAngularVelocity() > maxAngVelocity) {
body.setAngularVelocity(maxAngVelocity);
}
}
}
项目:GDXJam
文件:SteeringBehaviorComponent.java
public SteeringBehaviorComponent init (SteeringBehavior<Vector2> behavior) {
setBehavior(behavior);
return this;
}
项目:GDXJam
文件:SteeringBehaviorComponent.java
public void setBehavior (SteeringBehavior<Vector2> behavior) {
this.behavior = behavior;
}
项目:GDXJam
文件:SteeringBehaviorComponent.java
public SteeringBehavior<Vector2> getBehavior () {
return behavior;
}
项目:NicolasRage
文件:ActorSteerer.java
public void setSteeringBehavior(SteeringBehavior<Vector2> behavior)
{
steeringBehavior = behavior;
}
项目:0Bit-Engine
文件:SteeringEntity.java
public SteeringBehavior<Vector2> getSteeringBehavior() {
return steeringBehavior;
}
项目:0Bit-Engine
文件:SteeringEntity.java
public void setSteeringBehavior(SteeringBehavior<Vector2> steeringBehavior) {
this.steeringBehavior = steeringBehavior;
}
项目:gdx-ai
文件:Box2dSteeringEntity.java
public SteeringBehavior<Vector2> getSteeringBehavior () {
return steeringBehavior;
}
项目:gdx-ai
文件:Box2dSteeringEntity.java
public void setSteeringBehavior (SteeringBehavior<Vector2> steeringBehavior) {
this.steeringBehavior = steeringBehavior;
}
项目:gdx-ai
文件:SteeringActor.java
public SteeringBehavior<Vector2> getSteeringBehavior () {
return steeringBehavior;
}
项目:gdx-ai
文件:SteeringActor.java
public void setSteeringBehavior (SteeringBehavior<Vector2> steeringBehavior) {
this.steeringBehavior = steeringBehavior;
}
项目:gdx-ai
文件:SteeringBulletEntity.java
public SteeringBehavior<Vector3> getSteeringBehavior () {
return steeringBehavior;
}
项目:gdx-ai
文件:SteeringBulletEntity.java
public void setSteeringBehavior (SteeringBehavior<Vector3> steeringBehavior) {
this.steeringBehavior = steeringBehavior;
}
项目:gdx-ai
文件:BlendedSteering.java
public BehaviorAndWeight (SteeringBehavior<T> behavior, float weight) {
this.behavior = behavior;
this.weight = weight;
}
项目:gdx-ai
文件:BlendedSteering.java
public SteeringBehavior<T> getBehavior () {
return behavior;
}
项目:gdx-ai
文件:BlendedSteering.java
public void setBehavior (SteeringBehavior<T> behavior) {
this.behavior = behavior;
}
项目:gdx-ai
文件:PrioritySteering.java
/** Adds the specified behavior to the priority list.
* @param behavior the behavior to add
* @return this behavior for chaining. */
public PrioritySteering<T> add (SteeringBehavior<T> behavior) {
behaviors.add(behavior);
return this;
}
项目:Inspiration
文件:BlendedSteering.java
/** Adds a steering behavior and its weight to the list.
* @param behavior the steering behavior to add
* @param weight the weight of the behavior
* @return this behavior for chaining. */
public BlendedSteering<T> add (SteeringBehavior<T> behavior, float weight) {
return add(new BehaviorAndWeight<T>(behavior, weight));
}
项目:GdxDemo3D
文件:Steerer.java
/**
* Returns the steering behavior of this steerer, usually a priority or a blended steering grouping other steering behaviors.
*/
public abstract SteeringBehavior<Vector3> getSteeringBehavior();
项目:gdx-ai
文件:BlendedSteering.java
/** Adds a steering behavior and its weight to the list.
* @param behavior the steering behavior to add
* @param weight the weight of the behavior
* @return this behavior for chaining. */
public BlendedSteering<T> add (SteeringBehavior<T> behavior, float weight) {
return add(new BehaviorAndWeight<T>(behavior, weight));
}