本文整理汇总了Java中com.badlogic.gdx.ai.steer.SteeringAcceleration类的典型用法代码示例。如果您正苦于以下问题:Java SteeringAcceleration类的具体用法?Java SteeringAcceleration怎么用?Java SteeringAcceleration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SteeringAcceleration类属于com.badlogic.gdx.ai.steer包,在下文中一共展示了SteeringAcceleration类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: calculateRealSteering
import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入依赖的package包/类
@Override
protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) {
// First we need to figure out where the two agents are going to be at
// time T in the future. This is approximated by determining the time
// taken by the owner to reach the desired point between the 2 agents
// at the current time at the max speed. This desired point P is given by
// P = posA + interpositionRatio * (posB - posA)
internalTargetPosition.set(agentB.getPosition()).sub(agentA.getPosition()).scl(interpositionRatio)
.add(agentA.getPosition());
float timeToTargetPosition = owner.getPosition().dst(internalTargetPosition) / getActualLimiter().getMaxLinearSpeed();
// Now we have the time, we assume that agent A and agent B will continue on a
// straight trajectory and extrapolate to get their future positions.
// Note that here we are reusing steering.linear vector as agentA future position
// and targetPosition as agentB future position.
steering.linear.set(agentA.getPosition()).mulAdd(agentA.getLinearVelocity(), timeToTargetPosition);
internalTargetPosition.set(agentB.getPosition()).mulAdd(agentB.getLinearVelocity(), timeToTargetPosition);
// Calculate the target position between these predicted positions
internalTargetPosition.sub(steering.linear).scl(interpositionRatio).add(steering.linear);
// Finally delegate to Arrive
return arrive(steering, internalTargetPosition);
}
开发者ID:Mignet,项目名称:Inspiration,代码行数:26,代码来源:Interpose.java
示例2: calculateRealSteering
import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入依赖的package包/类
@Override
protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> blendedSteering) {
// Clear the output to start with
blendedSteering.setZero();
// Go through all the behaviors
int len = list.size;
for (int i = 0; i < len; i++) {
BehaviorAndWeight<T> bw = list.get(i);
// Calculate the behavior's steering
bw.behavior.calculateSteering(steering);
// Scale and add the steering to the accumulator
blendedSteering.mulAdd(steering, bw.weight);
}
Limiter actualLimiter = getActualLimiter();
// Crop the result
blendedSteering.linear.limit(actualLimiter.getMaxLinearAcceleration());
if (blendedSteering.angular > actualLimiter.getMaxAngularAcceleration())
blendedSteering.angular = actualLimiter.getMaxAngularAcceleration();
return blendedSteering;
}
开发者ID:Mignet,项目名称:Inspiration,代码行数:27,代码来源:BlendedSteering.java
示例3: calculateRealSteering
import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入依赖的package包/类
@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();
}
开发者ID:Mignet,项目名称:Inspiration,代码行数:26,代码来源:PrioritySteering.java
示例4: calculateRealSteering
import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入依赖的package包/类
@Override
protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) {
steering.setZero();
averageVelocity = steering.linear;
int neighborCount = proximity.findNeighbors(this);
if (neighborCount > 0) {
// Average the accumulated velocities
averageVelocity.scl(1f / neighborCount);
// Match the average velocity.
// Notice that steering.linear and averageVelocity are the same vector here.
averageVelocity.sub(owner.getLinearVelocity()).limit(getActualLimiter().getMaxLinearAcceleration());
}
return steering;
}
开发者ID:Mignet,项目名称:Inspiration,代码行数:20,代码来源:Alignment.java
示例5: CollisionAvoidanceSteererBase
import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入依赖的package包/类
public CollisionAvoidanceSteererBase(final SteerableBody steerableBody) {
super(steerableBody);
this.proximity = new RadiusProximity<Vector3>(steerableBody, GameScreen.screen.engine.characters, steerableBody.getBoundingRadius() * 1.8f);
this.collisionAvoidanceSB = new CollisionAvoidance<Vector3>(steerableBody, proximity) {
@Override
protected SteeringAcceleration<Vector3> calculateRealSteering(SteeringAcceleration<Vector3> steering) {
super.calculateRealSteering(steering);
steering.linear.y = 0; // remove any vertical acceleration
return steering;
}
};
this.prioritySteering = new PrioritySteering<Vector3>(steerableBody, 0.001f) //
.add(collisionAvoidanceSB);
}
开发者ID:jsjolund,项目名称:GdxDemo3D,代码行数:17,代码来源:CollisionAvoidanceSteererBase.java
示例6: WanderSteerer
import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入依赖的package包/类
public WanderSteerer(final SteerableBody steerableBody) {
super(steerableBody);
this.wanderSB = new Wander<Vector3>(steerableBody) {
@Override
protected SteeringAcceleration<Vector3> calculateRealSteering(SteeringAcceleration<Vector3> steering) {
super.calculateRealSteering(steering);
steering.linear.y = 0; // remove any vertical acceleration
return steering;
}
};
this.wanderSB.setWanderOffset(8) //
.setWanderOrientation(0) //
.setWanderRadius(0.5f) //
.setWanderRate(MathUtils.PI2 * 4);
this.prioritySteering.add(wanderSB);
}
开发者ID:jsjolund,项目名称:GdxDemo3D,代码行数:19,代码来源:WanderSteerer.java
示例7: calculateRealSteering
import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入依赖的package包/类
@Override
protected SteeringAcceleration<Vector2> calculateRealSteering(SteeringAcceleration<Vector2> steering) {
targetPosition = owner.getPosition().x + ((wanderOrientation == 1)? 0.5f : -0.5f);
if (!stopped) {
if (Utils.randRange(0f, 1f) < 0.01f) {
stopTime = Utils.randRange(minStopTime, maxStopTime);
stopped = true;
}
return doSteering(steering);
}
else {
currStopTime += Gdx.graphics.getDeltaTime();
if (currStopTime >= stopTime) {
stopped = false;
currStopTime = 0;
wanderOrientation = Utils.randRange(0, 1);
}
steering.setZero();
}
return steering;
}
开发者ID:ALPSquid,项目名称:0Bit-Engine,代码行数:23,代码来源:Wander2D.java
示例8: calculateRealSteering
import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入依赖的package包/类
@Override
protected SteeringAcceleration<Vector2> calculateRealSteering(SteeringAcceleration<Vector2> steering) {
if (!stopped) {
if ((targetPosition == entity.getMinX() && owner.getPosition().x <= targetPosition + 0.1) ||
(targetPosition == entity.getMaxX() && owner.getPosition().x >= targetPosition - 0.1)) {
stopTime = Utils.randRange(minStopTime, maxStopTime);
stopped = true;
}
return doSteering(steering);
} else {
currStopTime += Gdx.graphics.getDeltaTime();
if (currStopTime >= stopTime) {
stopped = false;
currStopTime = 0;
targetPosition = (targetPosition == entity.getMaxX()) ? entity.getMinX() : entity.getMaxX();
}
steering.setZero();
}
return steering;
}
开发者ID:ALPSquid,项目名称:0Bit-Engine,代码行数:21,代码来源:Patrol2D.java
示例9: applySteering
import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入依赖的package包/类
private void applySteering (SteeringAcceleration<Vector2> steering, float time) {
// Update position and linear velocity. Velocity is trimmed to maximum speed
position.mulAdd(linearVelocity, time);
linearVelocity.mulAdd(steering.linear, time).limit(getMaxLinearSpeed());
// Update orientation and angular velocity
if (independentFacing) {
setRotation(getRotation() + (angularVelocity * time) * MathUtils.radiansToDegrees);
angularVelocity += steering.angular * time;
} else {
// If we haven't got any velocity, then we can do nothing.
if (!linearVelocity.isZero(getZeroLinearSpeedThreshold())) {
float newOrientation = vectorToAngle(linearVelocity);
angularVelocity = (newOrientation - getRotation() * MathUtils.degreesToRadians) * time; // this is superfluous if independentFacing is always true
setRotation(newOrientation * MathUtils.radiansToDegrees);
}
}
}
开发者ID:libgdx,项目名称:gdx-ai,代码行数:19,代码来源:SteeringActor.java
示例10: B2dSteeringEntity
import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入依赖的package包/类
public B2dSteeringEntity(Body body, float boundingRadius) {
this.body = body;
this.boundingRadius = boundingRadius;
this.maxAngularSpeed = 500;
this.maxLinearAcceleration = 5000;
this.maxAngularSpeed = 30;
this.maxAngularAcceleration = 5;
this.tagged = false;
this.steeringOutput = new SteeringAcceleration<Vector2>(new Vector2());
this.body.setUserData(this);
}
开发者ID:MSLacerda,项目名称:DarkDay,代码行数:14,代码来源:B2dSteeringEntity.java
示例11: applySteering
import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入依赖的package包/类
private void applySteering(SteeringAcceleration<Vector2> steering, float deltaTime) {
position.mulAdd(linearVelocity, deltaTime);
linearVelocity.mulAdd(steering.linear, deltaTime).limit(this.getMaxLinearSpeed());
orientation += angularVelocity * deltaTime;
angularVelocity += steering.angular * deltaTime;
}
开发者ID:android-workloads,项目名称:JACWfA,代码行数:8,代码来源:Agent.java
示例12: calculateRealSteering
import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入依赖的package包/类
@Override
protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) {
// Acceleration tries to get to the target velocity without exceeding max acceleration
steering.linear.set(target.getLinearVelocity()).sub(owner.getLinearVelocity()).scl(1f / timeToTarget)
.limit(getActualLimiter().getMaxLinearAcceleration());
// No angular acceleration
steering.angular = 0;
// Output steering acceleration
return steering;
}
开发者ID:Mignet,项目名称:Inspiration,代码行数:13,代码来源:MatchVelocity.java
示例13: calculateRealSteering
import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入依赖的package包/类
@Override
protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) {
T ownerPosition = owner.getPosition();
float minDistanceSquare = Float.POSITIVE_INFINITY;
// Get the updated rays
Ray<T>[] inputRays = rayConfiguration.updateRays();
// Process rays
for (int i = 0; i < inputRays.length; i++) {
// Find the collision with current ray
boolean collided = raycastCollisionDetector.findCollision(outputCollision, inputRays[i]);
if (collided) {
float distanceSquare = ownerPosition.dst2(outputCollision.point);
if (distanceSquare < minDistanceSquare) {
minDistanceSquare = distanceSquare;
// Swap collisions
Collision<T> tmpCollision = outputCollision;
outputCollision = minOutputCollision;
minOutputCollision = tmpCollision;
}
}
}
// Return zero steering if no collision has occurred
if (minDistanceSquare == Float.POSITIVE_INFINITY) return steering.setZero();
// Calculate and seek the target position
steering.linear.set(minOutputCollision.point)
.mulAdd(minOutputCollision.normal, owner.getBoundingRadius() + distanceFromBoundary).sub(owner.getPosition()).nor()
.scl(getActualLimiter().getMaxLinearAcceleration());
// No angular acceleration
steering.angular = 0;
// Output steering acceleration
return steering;
}
开发者ID:Mignet,项目名称:Inspiration,代码行数:40,代码来源:RaycastObstacleAvoidance.java
示例14: calculateRealSteering
import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入依赖的package包/类
@Override
protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) {
shortestTime = Float.POSITIVE_INFINITY;
firstNeighbor = null;
firstMinSeparation = 0;
firstDistance = 0;
relativePosition = steering.linear;
// Take into consideration each neighbor to find the most imminent collision.
int neighborCount = proximity.findNeighbors(this);
// If we have no target, then return no steering acceleration
//
// NOTE: You might think that the condition below always evaluates to true since
// firstNeighbor has been set to null when entering this method. In fact, we have just
// executed findNeighbors(this) that has possibly set firstNeighbor to a non null value
// through the method reportNeighbor defined below.
if (neighborCount == 0 || firstNeighbor == null) return steering.setZero();
// If we're going to hit exactly, or if we're already
// colliding, then do the steering based on current position.
if (firstMinSeparation <= 0 || firstDistance < owner.getBoundingRadius() + firstNeighbor.getBoundingRadius()) {
relativePosition.set(firstNeighbor.getPosition()).sub(owner.getPosition());
} else {
// Otherwise calculate the future relative position
relativePosition.set(firstRelativePosition).mulAdd(firstRelativeVelocity, shortestTime);
}
// Avoid the target
// Notice that steerling.linear and relativePosition are the same vector
relativePosition.nor().scl(-getActualLimiter().getMaxLinearAcceleration());
// No angular acceleration
steering.angular = 0f;
// Output the steering
return steering;
}
开发者ID:Mignet,项目名称:Inspiration,代码行数:39,代码来源:CollisionAvoidance.java
示例15: calculateRealSteering
import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入依赖的package包/类
@Override
protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) {
// We just do the opposite of seek, i.e. (owner.getPosition() - target.getPosition())
// instead of (target.getPosition() - owner.getPosition())
steering.linear.set(owner.getPosition()).sub(target.getPosition()).nor().scl(getActualLimiter().getMaxLinearAcceleration());
// No angular acceleration
steering.angular = 0;
// Output steering acceleration
return steering;
}
开发者ID:Mignet,项目名称:Inspiration,代码行数:13,代码来源:Flee.java
示例16: calculateRealSteering
import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入依赖的package包/类
@Override
protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) {
// Try to match the position of the character with the position of the target by calculating
// the direction to the target and by moving toward it as fast as possible.
steering.linear.set(target.getPosition()).sub(owner.getPosition()).nor().scl(getActualLimiter().getMaxLinearAcceleration());
// No angular acceleration
steering.angular = 0;
// Output steering acceleration
return steering;
}
开发者ID:Mignet,项目名称:Inspiration,代码行数:13,代码来源:Seek.java
示例17: arrive
import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入依赖的package包/类
protected SteeringAcceleration<T> arrive (SteeringAcceleration<T> steering, T targetPosition) {
// Get the direction and distance to the target
T toTarget = steering.linear.set(targetPosition).sub(owner.getPosition());
float distance = toTarget.len();
// Check if we are there, return no steering
if (distance <= arrivalTolerance) return steering.setZero();
Limiter actualLimiter = getActualLimiter();
// Go max speed
float targetSpeed = actualLimiter.getMaxLinearSpeed();
// If we are inside the slow down radius calculate a scaled speed
if (distance <= decelerationRadius) targetSpeed *= distance / decelerationRadius;
// Target velocity combines speed and direction
T targetVelocity = toTarget.scl(targetSpeed / distance); // Optimized code for: toTarget.nor().scl(targetSpeed)
// Acceleration tries to get to the target velocity without exceeding max acceleration
// Notice that steering.linear and targetVelocity are the same vector
targetVelocity.sub(owner.getLinearVelocity()).scl(1f / timeToTarget).limit(actualLimiter.getMaxLinearAcceleration());
// No angular acceleration
steering.angular = 0f;
// Output the steering
return steering;
}
开发者ID:Mignet,项目名称:Inspiration,代码行数:29,代码来源:Arrive.java
示例18: face
import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入依赖的package包/类
protected SteeringAcceleration<T> face (SteeringAcceleration<T> steering, T targetPosition) {
// Get the direction to target
T toTarget = steering.linear.set(targetPosition).sub(owner.getPosition());
// Check for a zero direction, and return no steering if so
if (toTarget.isZero(getActualLimiter().getZeroLinearSpeedThreshold())) return steering.setZero();
// Calculate the orientation to face the target
float orientation = owner.vectorToAngle(toTarget);
// Delegate to ReachOrientation
return reachOrientation(steering, orientation);
}
开发者ID:Mignet,项目名称:Inspiration,代码行数:14,代码来源:Face.java
示例19: BlendedSteering
import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入依赖的package包/类
/** Creates a {@code BlendedSteering} for the specified {@code owner}, {@code maxLinearAcceleration} and
* {@code maxAngularAcceleration}.
* @param owner the owner of this behavior. */
public BlendedSteering (Steerable<T> owner) {
super(owner);
this.list = new Array<BehaviorAndWeight<T>>();
this.steering = new SteeringAcceleration<T>(newVector(owner));
}
开发者ID:Mignet,项目名称:Inspiration,代码行数:10,代码来源:BlendedSteering.java
示例20: calculateRealSteering
import com.badlogic.gdx.ai.steer.SteeringAcceleration; //导入依赖的package包/类
@Override
protected SteeringAcceleration<T> calculateRealSteering (SteeringAcceleration<T> steering) {
// Predictive or non-predictive behavior?
T location = (predictionTime == 0) ?
// Use the current position of the owner
owner.getPosition()
:
// Calculate the predicted future position of the owner. We're reusing steering.linear here.
steering.linear.set(owner.getPosition()).mulAdd(owner.getLinearVelocity(), predictionTime);
// Retrieve the flow vector at the specified location
T flowVector = flowField.lookup(location);
// Clear both linear and angular components
steering.setZero();
if (flowVector != null && !flowVector.isZero()) {
Limiter actualLimiter = getActualLimiter();
// Calculate linear acceleration
steering.linear.mulAdd(flowVector, actualLimiter.getMaxLinearSpeed()).sub(owner.getLinearVelocity())
.limit(actualLimiter.getMaxLinearAcceleration());
}
// Output steering
return steering;
}
开发者ID:Mignet,项目名称:Inspiration,代码行数:28,代码来源:FollowFlowField.java
注:本文中的com.badlogic.gdx.ai.steer.SteeringAcceleration类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论