Search in sources :

Example 6 with Movement

use of spacesettlers.utilities.Movement in project spacesettlers by amymcgovern.

the class TestToroidal2DPhysics method testApplyOrientationMoveFromStop.

@Test
public void testApplyOrientationMoveFromStop() {
    Movement movement = new Movement();
    double angularAccel = Math.PI / 60.0;
    movement.setAngularAccleration(angularAccel);
    movement.setTranslationalAcceleration(new Vector2D());
    double expectedOrientation = angularAccel;
    Position newPosition = space.applyMovement(position, movement, timestep);
    assertEquals(newPosition.getOrientation(), expectedOrientation, 0.01);
    assertEquals(newPosition.getAngularVelocity(), angularAccel, 0.01);
    assertEquals(newPosition.getX(), 0, 0.0);
    assertEquals(newPosition.getY(), 0, 0.0);
    assertEquals(newPosition.getTotalTranslationalVelocity(), 0, 0);
}
Also used : Movement(spacesettlers.utilities.Movement) Vector2D(spacesettlers.utilities.Vector2D) Position(spacesettlers.utilities.Position) Test(org.junit.Test)

Example 7 with Movement

use of spacesettlers.utilities.Movement in project spacesettlers by amymcgovern.

the class TestToroidal2DPhysics method testApplyTranslationalMovementVerticalFromStop.

@Test
public void testApplyTranslationalMovementVerticalFromStop() {
    Movement movement = new Movement();
    movement.setAngularAccleration(0);
    movement.setTranslationalAcceleration(new Vector2D(0, 10));
    position.setOrientation(Math.PI / 2);
    double expectedX = 0;
    double expectedY = 10;
    Position newPosition = space.applyMovement(position, movement, timestep);
    assertEquals(newPosition.getX(), expectedX, 0.01);
    assertEquals(newPosition.getY(), expectedY, 0.01);
    assertEquals(newPosition.getOrientation(), Math.PI / 2, 0.01);
    assertEquals(newPosition.getAngularVelocity(), 0, 0.01);
    assertEquals(newPosition.getTranslationalVelocityX(), 0, 0.01);
    assertEquals(newPosition.getTranslationalVelocityY(), 10, 0.01);
}
Also used : Movement(spacesettlers.utilities.Movement) Vector2D(spacesettlers.utilities.Vector2D) Position(spacesettlers.utilities.Position) Test(org.junit.Test)

Example 8 with Movement

use of spacesettlers.utilities.Movement in project spacesettlers by amymcgovern.

the class TestToroidal2DPhysics method testApplyTranslationalMovementAngledFromStop.

@Test
public void testApplyTranslationalMovementAngledFromStop() {
    Movement movement = new Movement();
    movement.setAngularAccleration(0);
    movement.setTranslationalAcceleration(new Vector2D(10, 10));
    position.setOrientation(Math.PI / 4);
    double expectedX = 10;
    double expectedY = 10;
    Position newPosition = space.applyMovement(position, movement, timestep);
    assertEquals(newPosition.getX(), expectedX, 0.01);
    assertEquals(newPosition.getY(), expectedY, 0.01);
    assertEquals(newPosition.getOrientation(), Math.PI / 4, 0.01);
    assertEquals(newPosition.getAngularVelocity(), 0, 0.01);
    assertEquals(newPosition.getTranslationalVelocityX(), 10, 0.01);
    assertEquals(newPosition.getTranslationalVelocityY(), 10, 0.01);
}
Also used : Movement(spacesettlers.utilities.Movement) Vector2D(spacesettlers.utilities.Vector2D) Position(spacesettlers.utilities.Position) Test(org.junit.Test)

Example 9 with Movement

use of spacesettlers.utilities.Movement in project spacesettlers by amymcgovern.

the class MoveAction method getMovement.

/**
 * Move the ship to the goal by turning and moving to the goal at the same time.
 */
public Movement getMovement(Toroidal2DPhysics space, Ship ship) {
    // isOrientedToGoal, isAtGoal, isOrientedAtGoal, isOrientingAtGoal
    Movement movement = new Movement();
    if (isFinished) {
        return movement;
    }
    // set the angular and translational velocity at the same time
    double angularAccel = pdControlOrientToGoal(space, targetLocation, ship.getPosition(), 0);
    movement.setAngularAccleration(angularAccel);
    Vector2D goalAccel = pdControlMoveToGoal(space, targetLocation, ship.getPosition(), targetVelocity);
    movement.setTranslationalAcceleration(goalAccel);
    // figure out if it has reached the goal
    if ((goalAccel.getMagnitude() < TARGET_REACHED_ACCEL) || (space.findShortestDistance(targetLocation, ship.getPosition()) < TARGET_REACHED_ERROR)) {
        isFinished = true;
    }
    return movement;
}
Also used : Movement(spacesettlers.utilities.Movement) Vector2D(spacesettlers.utilities.Vector2D)

Example 10 with Movement

use of spacesettlers.utilities.Movement in project spacesettlers by amymcgovern.

the class MoveActionWithOrientation method getMovement.

/**
 * Move the ship to the goal by turning and moving to the goal at the same time.
 */
public Movement getMovement(Toroidal2DPhysics space, Ship ship) {
    // isOrientedToGoal, isAtGoal, isOrientedAtGoal, isOrientingAtGoal
    Movement movement = new Movement();
    if (isFinished) {
        return movement;
    }
    // set the angular and translational velocity at the same time
    double angularAccel = this.pdControlOrientToGoal(space, targetLocation, ship.getPosition(), 0);
    movement.setAngularAccleration(angularAccel);
    Vector2D goalAccel = super.pdControlMoveToGoal(space, targetLocation, ship.getPosition(), targetVelocity);
    movement.setTranslationalAcceleration(goalAccel);
    // figure out if it has reached the goal
    if ((goalAccel.getMagnitude() < TARGET_REACHED_ACCEL) || (space.findShortestDistance(targetLocation, ship.getPosition()) < TARGET_REACHED_ERROR)) {
        isFinished = true;
    }
    return movement;
}
Also used : Movement(spacesettlers.utilities.Movement) Vector2D(spacesettlers.utilities.Vector2D)

Aggregations

Movement (spacesettlers.utilities.Movement)20 Position (spacesettlers.utilities.Position)16 Test (org.junit.Test)15 Vector2D (spacesettlers.utilities.Vector2D)15 MoveAction (spacesettlers.actions.MoveAction)4 LinkedHashSet (java.util.LinkedHashSet)1 UUID (java.util.UUID)1 ExecutionException (java.util.concurrent.ExecutionException)1 ExecutorService (java.util.concurrent.ExecutorService)1 TimeoutException (java.util.concurrent.TimeoutException)1 AbstractAction (spacesettlers.actions.AbstractAction)1 DoNothingAction (spacesettlers.actions.DoNothingAction)1 AbstractActionableObject (spacesettlers.objects.AbstractActionableObject)1 AbstractObject (spacesettlers.objects.AbstractObject)1 AiCore (spacesettlers.objects.AiCore)1 Base (spacesettlers.objects.Base)1 Ship (spacesettlers.objects.Ship)1 ResourcePile (spacesettlers.objects.resources.ResourcePile)1