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);
}
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);
}
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);
}
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;
}
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;
}
Aggregations