Example usage for com.badlogic.gdx.ai.steer Steerable getBoundingRadius

List of usage examples for com.badlogic.gdx.ai.steer Steerable getBoundingRadius

Introduction

In this page you can find the example usage for com.badlogic.gdx.ai.steer Steerable getBoundingRadius.

Prototype

public float getBoundingRadius();

Source Link

Document

Returns the bounding radius of this Steerable.

Usage

From source file:com.badlogic.gdx.ai.tests.steer.box2d.Box2dFieldOfViewProximity.java

License:Apache License

@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);
    }//from  w  ww .  j a  v a2 s .  c o  m

    // Reject the steerable
    return false;
}

From source file:com.badlogic.gdx.ai.tests.steer.box2d.Box2dRadiusProximity.java

License:Apache License

@Override
protected boolean accept(Steerable<Vector2> steerable) {
    // The bounding radius of the current body is taken into account
    // by adding it to the radius proximity
    float range = detectionRadius + steerable.getBoundingRadius();

    // Make sure the current body is within the range.
    // Notice we're working in distance-squared space to avoid square root.
    float distanceSquare = steerable.getPosition().dst2(owner.getPosition());

    return distanceSquare <= range * range;
}

From source file:com.mygdx.game.CustomCollisionAvoidance.java

License:Apache License

@Override
public boolean reportNeighbor(Steerable<T> neighbor) {
    // Calculate the time to collision
    relativePosition.set(neighbor.getPosition()).sub(owner.getPosition());
    relativeVelocity.set(neighbor.getLinearVelocity()).sub(owner.getLinearVelocity());
    float relativeSpeed2 = relativeVelocity.len2();
    float timeToCollision = -relativePosition.dot(relativeVelocity) / relativeSpeed2;

    if (Float.isNaN(timeToCollision)) {
        timeToCollision = 0.0f;// w w w .  j  a v a  2  s. com
    }

    // If timeToCollision is negative, i.e. the owner is already moving away from the the neighbor,
    // or it's not the most imminent collision then no action needs to be taken.
    if (timeToCollision <= 0 || timeToCollision >= shortestTime)
        return false;

    // Check if it is going to be a collision at all
    float distance = relativePosition.len();
    float minSeparation = distance - (float) Math.sqrt(relativeSpeed2) * timeToCollision /* shortestTime */;
    if (minSeparation > owner.getBoundingRadius() + neighbor.getBoundingRadius())
        return false;

    // Store most imminent collision data
    shortestTime = timeToCollision;
    firstNeighbor = neighbor;
    firstMinSeparation = minSeparation;
    firstDistance = distance;
    firstRelativePosition.set(relativePosition);
    firstRelativeVelocity.set(relativeVelocity);

    return true;
}

From source file:com.starsailor.util.box2d.Box2dRadiusProximity.java

License:Apache License

@Override
protected boolean accept(Steerable<Vector2> steerable) {
    // The bounding radius of the current body is taken into account
    // by adding it to the radius proximity
    float range = detectionRadius + steerable.getBoundingRadius();

    // Make sure the current body is within the range.
    // Notice we're working in distance-squared space to avoid square root.
    float distanceSquare = steerable.getPosition().dst2(owner.getPosition());

    Entity entity = (Entity) ((SteerableComponent) steerable).getBody().getUserData();
    if (entity instanceof Bullet) {
        return false;
    }/*from www .ja v  a 2  s .  c o  m*/

    return distanceSquare <= range * range;
}