Java Code Examples for com.badlogic.gdx.ai.utils.Location

The following examples show how to use com.badlogic.gdx.ai.utils.Location. These examples are extracted from open source projects. 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 Project: gdx-ai   Source File: DefensiveCircleFormationPattern.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public Location<T> calculateSlotLocation (Location<T> outLocation, int slotNumber) {
	if (numberOfSlots > 1) {
		// Place the slot around the circle based on its slot number
		float angleAroundCircle = (MathUtils.PI2 * slotNumber) / numberOfSlots;

		// The radius depends on the radius of the member,
		// and the number of members in the circle:
		// we want there to be no gap between member's shoulders.
		float radius = memberRadius / (float)Math.sin(Math.PI / numberOfSlots);

		// Fill location components based on the angle around circle.
		outLocation.angleToVector(outLocation.getPosition(), angleAroundCircle).scl(radius);

		// The members should be facing out
		outLocation.setOrientation(angleAroundCircle);
	}
	else {
		outLocation.getPosition().setZero();
		outLocation.setOrientation(MathUtils.PI2 * slotNumber);
	}

	// Return the slot location
	return outLocation;
}
 
Example 2
Source Project: gdx-ai   Source File: FormationMotionModerator.java    License: 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 3
Source Project: gdx-ai   Source File: Formation.java    License: 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();
}
 
Example 4
Source Project: gdx-ai   Source File: Hide.java    License: Apache License 2.0 5 votes vote down vote up
/** Creates a {@code Hide} behavior for the specified owner, target and proximity.
 * @param owner the owner of this behavior
 * @param target the target of this behavior
 * @param proximity the proximity to find nearby obstacles */
public Hide (Steerable<T> owner, Location<T> target, Proximity<T> proximity) {
	super(owner, target);
	this.proximity = proximity;

	this.bestHidingSpot = newVector(owner);
	this.toObstacle = null; // Set to null since we'll reuse steering.linear for this vector
}
 
Example 5
Source Project: Pacman_libGdx   Source File: PlayerAI.java    License: MIT License 4 votes vote down vote up
@Override
public Location<Vector2> newLocation() {
    return new Box2dLocation();
}
 
Example 6
Source Project: Pacman_libGdx   Source File: GhostAI.java    License: MIT License 4 votes vote down vote up
@Override
public Location<Vector2> newLocation() {
    return new Box2dLocation();
}
 
Example 7
Source Project: Pacman_libGdx   Source File: Box2dLocation.java    License: MIT License 4 votes vote down vote up
@Override
public Location<Vector2> newLocation() {
    return new Box2dLocation();
}
 
Example 8
Source Project: GdxDemo3D   Source File: SteerableBody.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Location<Vector3> newLocation() {
	return new BulletLocation();
}
 
Example 9
Source Project: GdxDemo3D   Source File: BulletLocation.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Location<Vector3> newLocation() {
	return new BulletLocation();
}
 
Example 10
Source Project: gdx-ai   Source File: Box2dLocation.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Location<Vector2> newLocation () {
	return new Box2dLocation();
}
 
Example 11
Source Project: gdx-ai   Source File: Box2dSteeringEntity.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Location<Vector2> newLocation () {
	return new Box2dLocation();
}
 
Example 12
Source Project: gdx-ai   Source File: SteeringActor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Location<Vector2> newLocation () {
	return new Scene2dLocation();
}
 
Example 13
Source Project: gdx-ai   Source File: Scene2dLocation.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Location<Vector2> newLocation () {
	return new Scene2dLocation();
}
 
Example 14
Source Project: gdx-ai   Source File: SteeringActorFormationMember.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Location<Vector2> getTargetLocation () {
	return target;
}
 
Example 15
Source Project: gdx-ai   Source File: SteeringBulletEntity.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Location<Vector3> newLocation () {
	return new BulletLocation();
}
 
Example 16
Source Project: gdx-ai   Source File: BulletLocation.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Location<Vector3> newLocation () {
	return new BulletLocation();
}
 
Example 17
Source Project: gdx-ai   Source File: OffensiveCircleFormationPattern.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Location<T> calculateSlotLocation (Location<T> outLocation, int slotNumber) {
	super.calculateSlotLocation(outLocation, slotNumber);
	outLocation.setOrientation(outLocation.getOrientation() + MathUtils.PI);
	return outLocation;
}
 
Example 18
Source Project: gdx-ai   Source File: FormationPattern.java    License: Apache License 2.0 4 votes vote down vote up
/** Returns the location of the given slot index. */
public Location<T> calculateSlotLocation (Location<T> outLocation, int slotNumber);
 
Example 19
Source Project: gdx-ai   Source File: Formation.java    License: Apache License 2.0 4 votes vote down vote up
/** Returns the current anchor point of the formation. This can be the location (i.e. position and orientation) of a leader
 * member, a modified center of mass of the members in the formation, or an invisible but steered anchor point for a two-level
 * steering system. */
public Location<T> getAnchorPoint () {
	return anchor;
}
 
Example 20
Source Project: gdx-ai   Source File: Formation.java    License: Apache License 2.0 4 votes vote down vote up
/** Sets the anchor point of the formation.
 * @param anchor the anchor point to set */
public void setAnchorPoint (Location<T> anchor) {
	this.anchor = anchor;
}
 
Example 21
Source Project: gdx-ai   Source File: Formation.java    License: Apache License 2.0 4 votes vote down vote up
/** Writes new slot locations to each member */
	public void updateSlots () {
		// Find the anchor point
		Location<T> anchor = getAnchorPoint();

		positionOffset.set(anchor.getPosition());
		float orientationOffset = anchor.getOrientation();
		if (motionModerator != null) {
			positionOffset.sub(driftOffset.getPosition());
			orientationOffset -= driftOffset.getOrientation();
		}

		// Get the orientation of the anchor point as a matrix
		orientationMatrix.idt().rotateRad(anchor.getOrientation());

		// Go through each member in turn
		for (int i = 0; i < slotAssignments.size; i++) {
			SlotAssignment<T> slotAssignment = slotAssignments.get(i);

			// Retrieve the location reference of the formation member to calculate the new value
			Location<T> relativeLoc = slotAssignment.member.getTargetLocation();

			// Ask for the location of the slot relative to the anchor point
			pattern.calculateSlotLocation(relativeLoc, slotAssignment.slotNumber);

			T relativeLocPosition = relativeLoc.getPosition();

// System.out.println("relativeLoc.position = " + relativeLocPosition);

// [17:31] <@Xoppa> davebaol, interface Transform<T extends Vector<T>> { T getTranslation(); T getScale(); float getRotation();
// void transform(T val); }
// [17:31] <@Xoppa>
// https://github.com/libgdx/libgdx/blob/master/gdx/src/com/badlogic/gdx/graphics/g3d/utils/BaseAnimationController.java#L40
// [17:34] * ThreadL0ck ([email protected]) Quit (Remote host closed the connection)
// [17:35] <davebaol> thanks Xoppa, sounds interesting

			// TODO Consider the possibility of declaring mul(orientationMatrix) in Vector
			// Transform it by the anchor point's position and orientation
// relativeLocPosition.mul(orientationMatrix).add(anchor.position);
			if (relativeLocPosition instanceof Vector2)
				((Vector2)relativeLocPosition).mul(orientationMatrix);
			else if (relativeLocPosition instanceof Vector3) ((Vector3)relativeLocPosition).mul(orientationMatrix);

			// Add the anchor and drift components
			relativeLocPosition.add(positionOffset);
			relativeLoc.setOrientation(relativeLoc.getOrientation() + orientationOffset);
		}

		// Possibly reset the anchor point if a moderator is set
		if (motionModerator != null) {
			motionModerator.updateAnchorPoint(anchor);
		}
	}
 
Example 22
Source Project: gdx-ai   Source File: FormationMember.java    License: Apache License 2.0 4 votes vote down vote up
/** Returns the target location of this formation member. */
public Location<T> getTargetLocation ();
 
Example 23
Source Project: gdx-ai   Source File: Interpose.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Interpose<T> setTarget (Location<T> target) {
	this.target = target;
	return this;
}
 
Example 24
Source Project: gdx-ai   Source File: Flee.java    License: Apache License 2.0 4 votes vote down vote up
/** Creates a {@code Flee} behavior for the specified owner and target.
 * @param owner the owner of this behavior
 * @param target the target agent of this behavior. */
public Flee (Steerable<T> owner, Location<T> target) {
	super(owner, target);
}
 
Example 25
Source Project: gdx-ai   Source File: Flee.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Flee<T> setTarget (Location<T> target) {
	this.target = target;
	return this;
}
 
Example 26
Source Project: gdx-ai   Source File: Seek.java    License: Apache License 2.0 4 votes vote down vote up
/** Creates a {@code Seek} behavior for the specified owner and target.
 * @param owner the owner of this behavior
 * @param target the target agent of this behavior. */
public Seek (Steerable<T> owner, Location<T> target) {
	super(owner);
	this.target = target;
}
 
Example 27
Source Project: gdx-ai   Source File: Seek.java    License: Apache License 2.0 4 votes vote down vote up
/** Returns the target to seek. */
public Location<T> getTarget () {
	return target;
}
 
Example 28
Source Project: gdx-ai   Source File: Seek.java    License: Apache License 2.0 4 votes vote down vote up
/** Sets the target to seek.
 * @return this behavior for chaining. */
public Seek<T> setTarget (Location<T> target) {
	this.target = target;
	return this;
}
 
Example 29
Source Project: gdx-ai   Source File: Arrive.java    License: Apache License 2.0 4 votes vote down vote up
/** Creates an {@code Arrive} behavior for the specified owner and target.
 * @param owner the owner of this behavior
 * @param target the target of this behavior */
public Arrive (Steerable<T> owner, Location<T> target) {
	super(owner);
	this.target = target;
}
 
Example 30
Source Project: gdx-ai   Source File: Arrive.java    License: Apache License 2.0 4 votes vote down vote up
/** Returns the target to arrive to. */
public Location<T> getTarget () {
	return target;
}