Java 类com.badlogic.gdx.ai.utils.Collision 实例源码

项目:gdx-ai    文件:BulletTargetInputProcessor.java   
private btCollisionObject rayTest (Collision<Vector3> output, Ray ray) {
    rayFrom.set(ray.origin);
    // 500 meters max from the origin
    rayTo.set(ray.direction).scl(500f).add(rayFrom);

    // we reuse the ClosestRayResultCallback, thus we need to reset its
    // values
    callback.setCollisionObject(null);
    callback.setClosestHitFraction(1f);
    callback.setRayFromWorld(rayFrom);
    callback.setRayToWorld(rayTo);

    world.rayTest(rayFrom, rayTo, callback);

    if (callback.hasHit()) {
        callback.getHitPointWorld(output.point);
        callback.getHitNormalWorld(output.normal);
        return callback.getCollisionObject();
    }

    return null;
}
项目:Mindustry    文件:Raycaster.java   
@Override
public boolean findCollision(Collision<Vector2> collision, Ray<Vector2> ray){
    Vector2 v = vectorCast(ray.start.x, ray.start.y, ray.end.x, ray.end.y);
    if(v == null) return false;
    collision.point = v;
    collision.normal = v.nor();
    return true;
}
项目:Inspiration    文件:RaycastObstacleAvoidance.java   
/** 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));
}
项目:Inspiration    文件:RaycastObstacleAvoidance.java   
@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;
}
项目:gdx-ai    文件:Box2dRaycastCollisionDetector.java   
@Override
public boolean findCollision (Collision<Vector2> outputCollision, Ray<Vector2> inputRay) {
    callback.collided = false;
    if (!inputRay.start.epsilonEquals(inputRay.end, MathUtils.FLOAT_ROUNDING_ERROR)) {
        callback.outputCollision = outputCollision;
        world.rayCast(callback, inputRay.start, inputRay.end);
    }
    return callback.collided;
}
项目:gdx-ai    文件:BulletRaycastCollisionDetector.java   
@Override
public boolean findCollision (Collision<Vector3> outputCollision, Ray<Vector3> inputRay) {
    // reset because we reuse the callback
    callback.setCollisionObject(null);

    world.rayTest(inputRay.start, inputRay.end, callback);

    if (outputCollision != null) {
        callback.getHitPointWorld(outputCollision.point);
        callback.getHitNormalWorld(outputCollision.normal);
    }

    return callback.hasHit();
}
项目:gdx-ai    文件:RaycastObstacleAvoidance.java   
/** 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));
}
项目:gdx-ai    文件:RaycastObstacleAvoidance.java   
@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;
}
项目:Inspiration    文件:MyRaycastCollisionDetector.java   
public boolean findCollision (Collision<Vector2> outputCollision, Ray<Vector2> inputRay) {
    throw new UnsupportedOperationException();
}
项目:AI_TestBed_v3    文件:TiledRaycastCollisionDetector.java   
@Override
public boolean findCollision (Collision<Vector2> outputCollision, Ray<Vector2> inputRay) {
    throw new UnsupportedOperationException();
}
项目:gdx-ai    文件:TiledRaycastCollisionDetector.java   
@Override
public boolean findCollision (Collision<Vector2> outputCollision, Ray<Vector2> inputRay) {
    throw new UnsupportedOperationException();
}