Java Code Examples for com.badlogic.gdx.ai.utils.Location#newLocation()

The following examples show how to use com.badlogic.gdx.ai.utils.Location#newLocation() . 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: FormationMotionModerator.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
/** Calculates the drift offset when members are in the given set of slots for the specified pattern.
 * @param centerOfMass the output location set to the calculated drift offset
 * @param slotAssignments the set of slots
 * @param pattern the pattern
 * @return the given location for chaining. */
public Location<T> calculateDriftOffset (Location<T> centerOfMass, Array<SlotAssignment<T>> slotAssignments,
	FormationPattern<T> pattern) {

	// Clear the center of mass
	centerOfMass.getPosition().setZero();
	float centerOfMassOrientation = 0;

	// Make sure tempLocation is instantiated
	if (tempLocation == null) tempLocation = centerOfMass.newLocation();

	T centerOfMassPos = centerOfMass.getPosition();
	T tempLocationPos = tempLocation.getPosition();

	// Go through each assignment and add its contribution to the center
	float numberOfAssignments = slotAssignments.size;
	for (int i = 0; i < numberOfAssignments; i++) {
		pattern.calculateSlotLocation(tempLocation, slotAssignments.get(i).slotNumber);
		centerOfMassPos.add(tempLocationPos);
		centerOfMassOrientation += tempLocation.getOrientation();
	}

	// Divide through to get the drift offset.
	centerOfMassPos.scl(1f / numberOfAssignments);
	centerOfMassOrientation /= numberOfAssignments;
	centerOfMass.setOrientation(centerOfMassOrientation);

	return centerOfMass;
}
 
Example 2
Source File: Formation.java    From gdx-ai with Apache License 2.0 5 votes vote down vote up
/** Creates a {@code Formation} for the specified {@code pattern}, {@code slotAssignmentStrategy} and {@code moderator}.
 * @param anchor the anchor point of this formation, usually a {@link Steerable}. Cannot be {@code null}.
 * @param pattern the pattern of this formation
 * @param slotAssignmentStrategy the strategy used to assign a member to his slot
 * @param motionModerator the motion moderator. Can be {@code null} if moderation is not needed
 * @throws IllegalArgumentException if the anchor point is {@code null} */
public Formation (Location<T> anchor, FormationPattern<T> pattern, SlotAssignmentStrategy<T> slotAssignmentStrategy,
	FormationMotionModerator<T> motionModerator) {
	if (anchor == null) throw new IllegalArgumentException("The anchor point cannot be null");
	this.anchor = anchor;
	this.pattern = pattern;
	this.slotAssignmentStrategy = slotAssignmentStrategy;
	this.motionModerator = motionModerator;

	this.slotAssignments = new Array<SlotAssignment<T>>();
	this.driftOffset = anchor.newLocation();
	this.positionOffset = anchor.getPosition().cpy();
}