Search in sources :

Example 31 with Vector2D

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

the class TestMoveActionWithOrientation method setUp.

@Before
public void setUp() throws Exception {
    space = new Toroidal2DPhysics(480, 640, timestep);
    targetVelocity = new Vector2D();
}
Also used : Vector2D(spacesettlers.utilities.Vector2D) Toroidal2DPhysics(spacesettlers.simulator.Toroidal2DPhysics) Before(org.junit.Before)

Example 32 with Vector2D

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

the class TestMoveActionWithOrientation method testpdControlMoveToAlongX.

/**
 * Test moving to the goal
 *
 * (30, 50) 	(50,50)  (70, 50)
 *
 * @throws SpaceSettlersActionException
 */
@Test
public void testpdControlMoveToAlongX() throws SpaceSettlersActionException {
    // first positive x (60,50)
    Position currentLoc = new Position(50, 50);
    Position goalLoc = new Position(70, 50);
    currentLoc.setOrientation(0);
    moveAction = new MoveActionWithOrientation();
    Vector2D accel = moveAction.pdControlMoveToGoal(space, goalLoc, currentLoc, targetVelocity);
    Movement movement = new Movement();
    while (accel.getMagnitude() > MoveAction.TARGET_REACHED_ACCEL) {
        movement.setTranslationalAcceleration(accel);
        currentLoc = space.applyMovement(currentLoc, movement, timestep);
        accel = moveAction.pdControlMoveToGoal(space, goalLoc, currentLoc, targetVelocity);
    }
    assertEquals(currentLoc.getOrientation(), 0, 0.01);
    assertEquals(currentLoc.getX(), 70, 0.05);
    assertEquals(currentLoc.getY(), 50, 0.05);
    // then to the negative x
    currentLoc = new Position(50, 50);
    currentLoc.setOrientation(0);
    goalLoc = new Position(30, 50);
    currentLoc.setOrientation(-Math.PI);
    accel = moveAction.pdControlMoveToGoal(space, goalLoc, currentLoc, targetVelocity);
    while (accel.getMagnitude() > MoveAction.TARGET_REACHED_ACCEL) {
        movement.setTranslationalAcceleration(accel);
        currentLoc = space.applyMovement(currentLoc, movement, timestep);
        accel = moveAction.pdControlMoveToGoal(space, goalLoc, currentLoc, targetVelocity);
    }
    assertEquals(currentLoc.getOrientation(), -Math.PI, 0.01);
    assertEquals(currentLoc.getX(), 30, 0.05);
    assertEquals(currentLoc.getY(), 50, 0.05);
}
Also used : Movement(spacesettlers.utilities.Movement) Vector2D(spacesettlers.utilities.Vector2D) Position(spacesettlers.utilities.Position) Test(org.junit.Test)

Example 33 with Vector2D

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

the class TestMoveActionWithOrientation method testpdControlMoveToAlongY.

/**
 * Test moving to the goal along the y dimension
 * (50, 40)
 * (50, 50)
 * (50,60)
 *
 * @throws SpaceSettlersActionException
 */
@Test
public void testpdControlMoveToAlongY() throws SpaceSettlersActionException {
    // first positive y (50, 60)
    Position currentLoc = new Position(50, 50);
    Position goalLoc = new Position(50, 60);
    currentLoc.setOrientation(Math.PI / 2);
    moveAction = new MoveActionWithOrientation();
    Vector2D accel = moveAction.pdControlMoveToGoal(space, goalLoc, currentLoc, targetVelocity);
    Movement movement = new Movement();
    while (accel.getMagnitude() > MoveAction.TARGET_REACHED_ACCEL) {
        movement.setTranslationalAcceleration(accel);
        currentLoc = space.applyMovement(currentLoc, movement, timestep);
        accel = moveAction.pdControlMoveToGoal(space, goalLoc, currentLoc, targetVelocity);
    }
    assertEquals(currentLoc.getOrientation(), Math.PI / 2, 0.01);
    assertEquals(currentLoc.getX(), 50, 0.05);
    assertEquals(currentLoc.getY(), 60, 0.05);
    // then to the negative y
    currentLoc = new Position(50, 50);
    currentLoc.setOrientation(0);
    goalLoc = new Position(50, 40);
    currentLoc.setOrientation(-Math.PI / 2);
    accel = moveAction.pdControlMoveToGoal(space, goalLoc, currentLoc, targetVelocity);
    while (accel.getMagnitude() > MoveAction.TARGET_REACHED_ACCEL) {
        movement.setTranslationalAcceleration(accel);
        currentLoc = space.applyMovement(currentLoc, movement, timestep);
        accel = moveAction.pdControlMoveToGoal(space, goalLoc, currentLoc, targetVelocity);
    }
    assertEquals(currentLoc.getOrientation(), -Math.PI / 2, 0.01);
    assertEquals(currentLoc.getX(), 50, 0.05);
    assertEquals(currentLoc.getY(), 40, 0.05);
}
Also used : Movement(spacesettlers.utilities.Movement) Vector2D(spacesettlers.utilities.Vector2D) Position(spacesettlers.utilities.Position) Test(org.junit.Test)

Example 34 with Vector2D

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

the class TestCollisionHandler method testElasticCollisionsShipsX.

@Test
public void testElasticCollisionsShipsX() {
    Ship ship1, ship2;
    Position ship1Pos = new Position(0, 0, Math.PI / 4);
    ship1Pos.setTranslationalVelocity(new Vector2D(20, 0));
    ship1 = new Ship("team1", Color.BLUE, ship1Pos);
    Position ship2Pos = new Position(10, 0, -Math.PI / 4);
    ship2Pos.setTranslationalVelocity(new Vector2D(-10, 0));
    ship2 = new Ship("team2", Color.RED, ship2Pos);
    collisionHandler.collide(ship1, ship2, space);
    assertEquals(ship1.getPosition().getTranslationalVelocityX(), -10, 0.01);
    assertEquals(ship1.getPosition().getTranslationalVelocityY(), 0, 0.01);
    assertEquals(ship2.getPosition().getTranslationalVelocityX(), 20, 0.01);
    assertEquals(ship2.getPosition().getTranslationalVelocityY(), 0, 0.01);
}
Also used : Vector2D(spacesettlers.utilities.Vector2D) Position(spacesettlers.utilities.Position) Ship(spacesettlers.objects.Ship) Test(org.junit.Test)

Example 35 with Vector2D

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

the class TestCollisionHandler method testElasticCollisionsShipsY.

@Test
public void testElasticCollisionsShipsY() {
    Ship ship1, ship2;
    Position ship1Pos = new Position(0, 0, Math.PI / 4);
    ship1Pos.setTranslationalVelocity(new Vector2D(0, 20));
    ship1 = new Ship("team1", Color.BLUE, ship1Pos);
    Position ship2Pos = new Position(0, 10, -Math.PI / 4);
    ship2Pos.setTranslationalVelocity(new Vector2D(0, -10));
    ship2 = new Ship("team2", Color.RED, ship2Pos);
    collisionHandler.collide(ship1, ship2, space);
    assertEquals(ship1.getPosition().getTranslationalVelocityX(), 0, 0.01);
    assertEquals(ship1.getPosition().getTranslationalVelocityY(), -10, 0.01);
    assertEquals(ship2.getPosition().getTranslationalVelocityX(), 0, 0.01);
    assertEquals(ship2.getPosition().getTranslationalVelocityY(), 20, 0.01);
}
Also used : Vector2D(spacesettlers.utilities.Vector2D) Position(spacesettlers.utilities.Position) Ship(spacesettlers.objects.Ship) Test(org.junit.Test)

Aggregations

Vector2D (spacesettlers.utilities.Vector2D)49 Test (org.junit.Test)33 Position (spacesettlers.utilities.Position)26 Movement (spacesettlers.utilities.Movement)15 Asteroid (spacesettlers.objects.Asteroid)8 Ship (spacesettlers.objects.Ship)8 MoveAction (spacesettlers.actions.MoveAction)4 Before (org.junit.Before)3 AbstractObject (spacesettlers.objects.AbstractObject)3 Toroidal2DPhysics (spacesettlers.simulator.Toroidal2DPhysics)2 HashMap (java.util.HashMap)1 Random (java.util.Random)1 UUID (java.util.UUID)1 AbstractAction (spacesettlers.actions.AbstractAction)1 DoNothingAction (spacesettlers.actions.DoNothingAction)1 RawAction (spacesettlers.actions.RawAction)1 LineGraphics (spacesettlers.graphics.LineGraphics)1 StarGraphics (spacesettlers.graphics.StarGraphics)1 Beacon (spacesettlers.objects.Beacon)1 Flag (spacesettlers.objects.Flag)1