summaryrefslogtreecommitdiff
path: root/src/Camera.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/Camera.java')
-rw-r--r--src/Camera.java49
1 files changed, 36 insertions, 13 deletions
diff --git a/src/Camera.java b/src/Camera.java
index a7c2300..57c6d70 100644
--- a/src/Camera.java
+++ b/src/Camera.java
@@ -103,23 +103,16 @@ class Camera {
private void setHelicopterMode() {
/**
* 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.
+ * robots.
*/
- double time_sum = 0;
- for (Robot robot : robots) {
- time_sum += robot.getTimePos();
- }
- // for now stay in the middle of the robots, later we could follow the
- // fastest (or slowest) robot if desired.
- double time_avg = time_sum / robots.length;
+ Robot focus = getFocusedRobot();
- // center at the center lane
- center = track.getPointForLane(time_avg, robots.length / 2 + .5);
+ // center at the chosen robot.
+ center = track.getPointForLane(focus.getTimePos(), focus.getLane());
// look in the direction where the robots walks, namely the tangent
// FIXME: getTangent() is broken, or this snippet is wrong.
- up = track.getTangent(time_avg);
+ up = track.getTangent(focus.getTimePos());
// "above" is 10 meters.
eye = center.add(new Vector(0, 0, 10f));
@@ -130,7 +123,22 @@ class Camera {
* on the motorcycle mode.
*/
private void setMotorCycleMode() {
- // code goes here ...
+ /**
+ * In the Motor Cycle view, the camera is at the side of a track,
+ * following the robots.
+ */
+ Robot focus = getFocusedRobot();
+
+ // Center at the focused robot.
+ center = track.getPointForLane(focus.getTimePos(), focus.getLane());
+
+ // We are looking at the robot from the side.
+ up = Vector.Z;
+
+ // look at a distance of 10 meters from the center of the first lane
+ eye = track.getPointForLane(focus.getTimePos(), 10);
+ // assume that the motor camera is one meter above the race track.
+ eye = eye.add(new Vector(0, 0, 1f));
}
/**
@@ -140,4 +148,19 @@ class Camera {
private void setFirstPersonMode() {
// code goes here ...
}
+
+ /**
+ * Returns the robot on which the camera is focused.
+ */
+ private Robot getFocusedRobot() {
+ Robot selected = robots[0];
+ for (Robot robot : robots) {
+ // Many possibilities here, fastest, slowest, loser, winner...
+ if (selected.getSpeed() < robot.getSpeed()) {
+ // select the fastest accelerating robot.
+ selected = robot;
+ }
+ }
+ return selected;
+ }
}