Java Code Examples for com.badlogic.gdx.ai.steer.Steerable#getBoundingRadius()

The following examples show how to use com.badlogic.gdx.ai.steer.Steerable#getBoundingRadius() . 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 vote down vote up
@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: Box2dRadiusProximity.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
@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;
}
 
Example 3
Source File: CollisionAvoidance.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
@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();

	// Collision can't happen when the agents have the same linear velocity.
	// Also, note that timeToCollision would be NaN due to the indeterminate form 0/0 and,
	// since any comparison involving NaN returns false, it would become the shortestTime,
	// so defeating the algorithm.
	if (relativeSpeed2 == 0) return false;
	
	float timeToCollision = -relativePosition.dot(relativeVelocity) / relativeSpeed2;

	// 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;
}