com.badlogic.gdx.ai.steer.Steerable Java Examples
The following examples show how to use
com.badlogic.gdx.ai.steer.Steerable.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Box2dFieldOfViewProximity.java From gdx-ai with Apache License 2.0 | 6 votes |
@Override protected boolean accept (Steerable<Vector2> steerable) { toSteerable.set(steerable.getPosition()).sub(owner.getPosition()); // The bounding radius of the current body is taken into account // by adding it to the radius proximity float range = detectionRadius + steerable.getBoundingRadius(); float toSteerableLen2 = toSteerable.len2(); // Make sure the steerable is within the range. // Notice we're working in distance-squared space to avoid square root. if (toSteerableLen2 < range * range) { // Accept the steerable if it is within the field of view of the owner. return (ownerOrientation.dot(toSteerable) > coneThreshold); } // Reject the steerable return false; }
Example #2
Source File: Separation.java From gdx-ai with Apache License 2.0 | 6 votes |
@Override public boolean reportNeighbor (Steerable<T> neighbor) { toAgent.set(owner.getPosition()).sub(neighbor.getPosition()); float distanceSqr = toAgent.len2(); if(distanceSqr == 0) return true; float maxAcceleration = getActualLimiter().getMaxLinearAcceleration(); // Calculate the strength of repulsion through inverse square law decay float strength = getDecayCoefficient() / distanceSqr; if (strength > maxAcceleration) strength = maxAcceleration; // Add the acceleration // Optimized code for linear.mulAdd(toAgent.nor(), strength); linear.mulAdd(toAgent, strength / (float)Math.sqrt(distanceSqr)); return true; }
Example #3
Source File: Hide.java From gdx-ai with Apache License 2.0 | 6 votes |
@Override public boolean reportNeighbor (Steerable<T> neighbor) { // Calculate the position of the hiding spot for this obstacle T hidingSpot = getHidingPosition(neighbor.getPosition(), neighbor.getBoundingRadius(), target.getPosition()); // Work in distance-squared space to find the closest hiding // spot to the owner float distance2 = hidingSpot.dst2(owner.getPosition()); if (distance2 < distance2ToClosest) { distance2ToClosest = distance2; bestHidingSpot.set(hidingSpot); return true; } return false; }
Example #4
Source File: Box2dCollisionAvoidanceTest.java From gdx-ai with Apache License 2.0 | 6 votes |
@Override public void draw () { // Update and draw the character spriteBatch.begin(); for (int i = 0; i < characters.size; i++) { Box2dSteeringEntity character = characters.get(i); character.draw(spriteBatch); } spriteBatch.end(); if (drawDebug) { Steerable<Vector2> steerable = characters.get(0); shapeRenderer.begin(ShapeType.Line); shapeRenderer.setColor(0, 1, 0, 1); int centerX = Box2dSteeringTest.metersToPixels(steerable.getPosition().x); int centerY = Box2dSteeringTest.metersToPixels(steerable.getPosition().y); int radius = Box2dSteeringTest.metersToPixels(char0Proximity.getDetectionRadius()); shapeRenderer.circle(centerX, centerY, radius); shapeRenderer.end(); } }
Example #5
Source File: RayConfigurationBase.java From gdx-ai with Apache License 2.0 | 5 votes |
/** Creates a {@code RayConfigurationBase} for the given owner and the specified number of rays. * @param owner the owner of this configuration * @param numRays the number of rays used by this configuration */ @SuppressWarnings("unchecked") public RayConfigurationBase (Steerable<T> owner, int numRays) { this.owner = owner; this.rays = new Ray[numRays]; for (int i = 0; i < numRays; i++) this.rays[i] = new Ray<T>(owner.getPosition().cpy().setZero(), owner.getPosition().cpy().setZero()); }
Example #6
Source File: Interpose.java From gdx-ai with Apache License 2.0 | 5 votes |
/** Creates an {@code Interpose} behavior for the specified owner and agents using the the given interposing ratio. * @param owner the owner of this behavior * @param agentA the first agent * @param agentB the other agent * @param interpositionRatio a number between 0 and 1 indicating the percentage of the distance between the 2 agents that the * owner should reach, where 0 is agentA position and 1 is agentB position. */ public Interpose (Steerable<T> owner, Steerable<T> agentA, Steerable<T> agentB, float interpositionRatio) { super(owner); this.agentA = agentA; this.agentB = agentB; this.interpositionRatio = interpositionRatio; this.internalTargetPosition = newVector(owner); }
Example #7
Source File: InfiniteProximity.java From gdx-ai with Apache License 2.0 | 5 votes |
@Override public int findNeighbors (ProximityCallback<T> callback) { int neighborCount = 0; for (Steerable<T> currentAgent : agents) { // Make sure the agent being examined isn't the owner if (currentAgent != owner) { if (callback.reportNeighbor(currentAgent)) { neighborCount++; } } } return neighborCount; }
Example #8
Source File: Scene2dFlockingTest.java From gdx-ai with Apache License 2.0 | 5 votes |
@Override public void draw () { if (drawDebug) { Steerable<Vector2> steerable = characters.get(0); shapeRenderer.begin(ShapeType.Line); shapeRenderer.setColor(0, 1, 0, 1); float angle = char0Proximity.getAngle() * MathUtils.radiansToDegrees; shapeRenderer.arc(steerable.getPosition().x, steerable.getPosition().y, char0Proximity.getRadius(), steerable.getOrientation() * MathUtils.radiansToDegrees - angle / 2f + 90f, angle); shapeRenderer.end(); } }
Example #9
Source File: Scene2dCollisionAvoidanceTest.java From gdx-ai with Apache License 2.0 | 5 votes |
@Override public void draw () { if (drawDebug) { Steerable<Vector2> steerable = characters.get(0); shapeRenderer.begin(ShapeType.Line); shapeRenderer.setColor(0, 1, 0, 1); shapeRenderer.circle(steerable.getPosition().x, steerable.getPosition().y, char0Proximity.getRadius()); shapeRenderer.end(); } }
Example #10
Source File: Jump.java From gdx-ai with Apache License 2.0 | 5 votes |
/** Works out the trajectory calculation. */ private Steerable<T> calculateTarget () { this.jumpTarget.position = jumpDescriptor.takeoffPosition; this.airborneTime = calculateAirborneTimeAndVelocity(jumpTarget.linearVelocity, jumpDescriptor, getActualLimiter() .getMaxLinearSpeed()); this.isJumpAchievable = airborneTime >= 0; return jumpTarget; }
Example #11
Source File: CentralRayWithWhiskersConfiguration.java From gdx-ai with Apache License 2.0 | 5 votes |
/** Creates a {@code CentralRayWithWhiskersConfiguration} for the given owner where the central ray has the specified length and * the two whiskers have the specified length and angle. * @param owner the owner of this configuration * @param rayLength the length of the central ray * @param whiskerLength the length of the two whiskers (usually shorter than the central ray) * @param whiskerAngle the angle in radians of the whiskers from the central ray */ public CentralRayWithWhiskersConfiguration (Steerable<T> owner, float rayLength, float whiskerLength, float whiskerAngle) { super(owner, 3); this.rayLength = rayLength; this.whiskerLength = whiskerLength; this.whiskerAngle = whiskerAngle; }
Example #12
Source File: RaycastObstacleAvoidance.java From gdx-ai with Apache License 2.0 | 5 votes |
/** Creates a {@code RaycastObstacleAvoidance} behavior. * @param owner the owner of this behavior * @param rayConfiguration the ray configuration * @param raycastCollisionDetector the collision detector * @param distanceFromBoundary the minimum distance to a wall (i.e., how far to avoid collision). */ public RaycastObstacleAvoidance (Steerable<T> owner, RayConfiguration<T> rayConfiguration, RaycastCollisionDetector<T> raycastCollisionDetector, float distanceFromBoundary) { super(owner); this.rayConfiguration = rayConfiguration; this.raycastCollisionDetector = raycastCollisionDetector; this.distanceFromBoundary = distanceFromBoundary; this.outputCollision = new Collision<T>(newVector(owner), newVector(owner)); this.minOutputCollision = new Collision<T>(newVector(owner), newVector(owner)); }
Example #13
Source File: Hide.java From gdx-ai with Apache License 2.0 | 5 votes |
/** Creates a {@code Hide} behavior for the specified owner, target and proximity. * @param owner the owner of this behavior * @param target the target of this behavior * @param proximity the proximity to find nearby obstacles */ public Hide (Steerable<T> owner, Location<T> target, Proximity<T> proximity) { super(owner, target); this.proximity = proximity; this.bestHidingSpot = newVector(owner); this.toObstacle = null; // Set to null since we'll reuse steering.linear for this vector }
Example #14
Source File: Box2dSquareAABBProximity.java From gdx-ai with Apache License 2.0 | 5 votes |
public Box2dSquareAABBProximity (Steerable<Vector2> owner, World world, float detectionRadius) { this.owner = owner; this.world = world; this.detectionRadius = detectionRadius; this.behaviorCallback = null; this.neighborCount = 0; }
Example #15
Source File: Arrive.java From gdx-ai with Apache License 2.0 | 4 votes |
/** Creates an {@code Arrive} behavior for the specified owner. * @param owner the owner of this behavior */ public Arrive (Steerable<T> owner) { this(owner, null); }
Example #16
Source File: PrioritySteering.java From gdx-ai with Apache License 2.0 | 4 votes |
@Override public PrioritySteering<T> setOwner (Steerable<T> owner) { this.owner = owner; return this; }
Example #17
Source File: Seek.java From gdx-ai with Apache License 2.0 | 4 votes |
/** Creates a {@code Seek} behavior for the specified owner. * @param owner the owner of this behavior. */ public Seek (Steerable<T> owner) { this(owner, null); }
Example #18
Source File: Arrive.java From gdx-ai with Apache License 2.0 | 4 votes |
@Override public Arrive<T> setOwner (Steerable<T> owner) { this.owner = owner; return this; }
Example #19
Source File: Face.java From gdx-ai with Apache License 2.0 | 4 votes |
/** Creates a {@code Face} behavior for the specified owner. * @param owner the owner of this behavior. */ public Face (Steerable<T> owner) { this(owner, null); }
Example #20
Source File: RayConfigurationBase.java From gdx-ai with Apache License 2.0 | 4 votes |
/** Returns the owner of this configuration. */ public Steerable<T> getOwner () { return owner; }
Example #21
Source File: Jump.java From gdx-ai with Apache License 2.0 | 4 votes |
/** Sets the target whose velocity should be matched. Notice that this method is inherited from {@link MatchVelocity}. Usually * with {@code Jump} you should never call it because a specialized internal target has already been created implicitly. * @param target the target to set * @return this behavior for chaining. */ @Override public Jump<T> setTarget (Steerable<T> target) { this.target = target; return this; }
Example #22
Source File: Cohesion.java From gdx-ai with Apache License 2.0 | 4 votes |
@Override public Cohesion<T> setOwner (Steerable<T> owner) { this.owner = owner; return this; }
Example #23
Source File: Cohesion.java From gdx-ai with Apache License 2.0 | 4 votes |
@Override public boolean reportNeighbor (Steerable<T> neighbor) { // Accumulate neighbor position centerOfMass.add(neighbor.getPosition()); return true; }
Example #24
Source File: Cohesion.java From gdx-ai with Apache License 2.0 | 4 votes |
/** Creates a {@code Cohesion} for the specified owner and proximity. * @param owner the owner of this behavior. * @param proximity the proximity to detect the owner's neighbors */ public Cohesion (Steerable<T> owner, Proximity<T> proximity) { super(owner, proximity); }
Example #25
Source File: Seek.java From gdx-ai with Apache License 2.0 | 4 votes |
@Override public Seek<T> setOwner (Steerable<T> owner) { this.owner = owner; return this; }
Example #26
Source File: Seek.java From gdx-ai with Apache License 2.0 | 4 votes |
/** Creates a {@code Seek} behavior for the specified owner and target. * @param owner the owner of this behavior * @param target the target agent of this behavior. */ public Seek (Steerable<T> owner, Location<T> target) { super(owner); this.target = target; }
Example #27
Source File: BlendedSteering.java From gdx-ai with Apache License 2.0 | 4 votes |
@Override public BlendedSteering<T> setOwner (Steerable<T> owner) { this.owner = owner; return this; }
Example #28
Source File: Evade.java From gdx-ai with Apache License 2.0 | 4 votes |
/** Creates a {@code Evade} behavior for the specified owner and target. Maximum prediction time defaults to 1 second. * @param owner the owner of this behavior * @param target the target of this behavior, typically a pursuer. */ public Evade (Steerable<T> owner, Steerable<T> target) { this(owner, target, 1); }
Example #29
Source File: Flee.java From gdx-ai with Apache License 2.0 | 4 votes |
/** Creates a {@code Flee} behavior for the specified owner. * @param owner the owner of this behavior. */ public Flee (Steerable<T> owner) { this(owner, null); }
Example #30
Source File: CollisionAvoidance.java From gdx-ai with Apache License 2.0 | 4 votes |
@Override public CollisionAvoidance<T> setOwner (Steerable<T> owner) { this.owner = owner; return this; }