diff options
-rw-r--r-- | src/Camera.java | 35 |
1 files changed, 33 insertions, 2 deletions
diff --git a/src/Camera.java b/src/Camera.java index 2ebdaa6..fb6df32 100644 --- a/src/Camera.java +++ b/src/Camera.java @@ -16,14 +16,23 @@ class Camera { /** The up vector. */ public Vector up = Vector.Z; + + /** The array with robot positions. */ + private double[] robotPositions; + + /** Race track used. */ + private RaceTrack track; /** * A reference to the global game state from RobotRace. */ private final GlobalState gs; - public Camera(GlobalState gs) { + public Camera(GlobalState gs, double[] positions, RaceTrack track) { + // Set the global state and the robot positions and track this.gs = gs; + this.robotPositions = positions; + this.track = track; } /** @@ -88,7 +97,29 @@ class Camera { * on the helicopter mode. */ private void setHelicopterMode() { - // code goes here ... + // Choose a robot to view + int robot = 0; + + /* + * First get the inner track position of a robot, then multiply this + * vector so that we have the actual position on the track. + * + * Add this lane position to the start position and we have the actual + * robot position. + */ + Vector startPosition = track.getPoint(robotPositions[robot]); + Vector lanePosition = new Vector(startPosition.x(), startPosition.y(), 0) + .normalized().scale(robot + 1); + Vector robotPosition = startPosition.add(lanePosition); + + // Set the up vector to equal the tangent of the robot + up = track.getTangent(robotPositions[robot]); + + // Set the center point to the actual robot position. + center = robotPosition; + + // Set the eye point to the center point, then increased height + eye = new Vector(center.x(), center.y(), 10f); } /** |