summaryrefslogtreecommitdiff
path: root/src/RobotRace.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/RobotRace.java')
-rw-r--r--src/RobotRace.java12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/RobotRace.java b/src/RobotRace.java
index 42850d1..608438f 100644
--- a/src/RobotRace.java
+++ b/src/RobotRace.java
@@ -150,8 +150,16 @@ public class RobotRace extends Base {
gl.glLoadIdentity();
// Set the perspective.
- // Modify this to meet the requirements in the assignment.
- glu.gluPerspective(40, (float)gs.w / (float)gs.h, 0.1, 100);
+ // angle = 2 arctan(vWidth / 2vDist)
+ float angle;
+
+ angle = 2f * (float) atan((0.5f * gs.vWidth) / gs.vDist);
+ // radians to degree (degree = rad / pi * 180)
+ angle = 180 * angle / (float) PI;
+ // lower than 1 would yield no picture, great values cause an "infinite" line segment
+ angle = max(1, min(179, angle));
+ glu.gluPerspective(angle, (float)gs.w / (float)gs.h,
+ 0.1 * gs.vDist, 10.0 * gs.vDist);
// Set camera.
gl.glMatrixMode(GL_MODELVIEW);