Example usage for com.badlogic.gdx.ai.steer SteeringAcceleration setZero

List of usage examples for com.badlogic.gdx.ai.steer SteeringAcceleration setZero

Introduction

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

Prototype

public SteeringAcceleration<T> setZero() 

Source Link

Document

Zeros the linear and angular components of this steering acceleration.

Usage

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

License:Apache License

@Override
protected SteeringAcceleration<T> calculateRealSteering(SteeringAcceleration<T> steering) {
    shortestTime = Float.POSITIVE_INFINITY;
    firstNeighbor = null;/*from w  ww. j  a v a  2s .  c o  m*/
    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
    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;
}

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

License:Apache License

@Override
protected SteeringAcceleration<T> calculateRealSteering(SteeringAcceleration<T> steering) {
    steering.setZero();
    steering.linear = linear;//  w  w  w.j  a  v  a 2 s.c  o m
    proximity.findNeighbors(this);
    return steering;
}