summaryrefslogtreecommitdiff
path: root/src/Camera.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/Camera.java')
-rw-r--r--src/Camera.java56
1 files changed, 28 insertions, 28 deletions
diff --git a/src/Camera.java b/src/Camera.java
index c0ea5cd..fd29482 100644
--- a/src/Camera.java
+++ b/src/Camera.java
@@ -17,9 +17,6 @@ class Camera {
/** The up vector. */
public Vector up = Vector.Z;
- /** The array with robot positions. */
- private double[] robotPositions;
-
/** Race track used. */
private RaceTrack track;
@@ -28,11 +25,15 @@ class Camera {
*/
private final GlobalState gs;
- public Camera(GlobalState gs, double[] positions, RaceTrack track) {
- // Set the global state and the robot positions and track
+ /**
+ * Robots that are to be tracked by the camera.
+ */
+ private final Robot[] robots;
+
+ public Camera(GlobalState gs, RaceTrack track, Robot[] robots) {
this.gs = gs;
- this.robotPositions = positions;
this.track = track;
+ this.robots = robots;
}
/**
@@ -90,6 +91,9 @@ class Camera {
Cz = gs.cnt.z();
center = new Vector(Cx, Cy, Cz);
eye = eye.add(center);
+
+ // just look straight forward
+ up = Vector.Z;
}
/**
@@ -97,29 +101,25 @@ class Camera {
* on the helicopter mode.
*/
private void setHelicopterMode() {
- // 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.
+ /**
+ * In the Helicopter view, the camera (eye point) is located above the
+ * robots. Take the average time of the robots and use that to determine
+ * the position and direction.
*/
- 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);
+ double time_sum = 0;
+ for (Robot robot : robots) {
+ time_sum += robot.getTimePos();
+ }
+ double time_avg = time_sum / robots.length;
+
+ // center at the center lane
+ center = track.getPointForLane(time_avg, robots.length / 2 + .5);
+
+ // look in the direction where the robots walks, namely the tangent
+ up = track.getTangent(time_avg);
+
+ // "above" is 10 meters.
+ eye = center.add(new Vector(center.x(), center.y(), 10f));
}
/**