Skip to content

Commit

Permalink
EditorCameraController now uses an AnimationHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaskelly committed May 1, 2020
1 parent 3e49898 commit 5f9663b
Showing 1 changed file with 14 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.badlogic.gdx.math.collision.BoundingBox;
import com.interrupt.dungeoneer.entities.Player;
import com.interrupt.dungeoneer.game.Level;
import com.interrupt.helpers.AnimationHelper;
import com.interrupt.helpers.InterpolationHelper;

/** Subsystem for controlling and positioning the editor camera. */
public class EditorCameraController extends InputAdapter implements EditorSubsystem {
Expand All @@ -30,11 +32,7 @@ public class EditorCameraController extends InputAdapter implements EditorSubsys

int scrollAmount;

boolean isMoving;
float currentMoveTime;
final float moveTime = 0.0625f;
final Vector3 moveStart = new Vector3();
final Vector3 moveEnd = new Vector3();
AnimationHelper animationHelper;

public EditorCameraController() {}

Expand Down Expand Up @@ -179,18 +177,9 @@ else if (scrollAmount > 0) {
position.set(cameraNewDirection.x, cameraNewDirection.z, cameraNewDirection.y);
}

// Handle smoothly lerping to a destination.
if (isMoving) {
currentMoveTime += Gdx.graphics.getDeltaTime();

position.set(moveStart);
position.lerp(moveEnd, currentMoveTime / moveTime);

if (currentMoveTime >= moveTime) {
currentMoveTime = 0;
isMoving = false;
position.set(moveEnd);
}
if (animationHelper != null && !animationHelper.isDonePlaying()) {
animationHelper.tickAnimation(Gdx.graphics.getDeltaTime());
position.set(animationHelper.getCurrentPosition());
}

camera.position.set(position.x, position.z, position.y);
Expand Down Expand Up @@ -294,9 +283,13 @@ else if (Editor.app.selected) {

/** Smoothly move to given destination. */
public void moveTo(Vector3 destination) {
moveStart.set(position);
moveEnd.set(destination);
isMoving = true;
currentMoveTime = 0;
animationHelper = new AnimationHelper(
position,
Vector3.Zero,
destination,
Vector3.Zero,
0.5f,
InterpolationHelper.InterpolationMode.exp10Out
);
}
}

0 comments on commit 5f9663b

Please sign in to comment.