diff options
author | Peter Wu <lekensteyn@gmail.com> | 2013-11-21 17:26:18 +0100 |
---|---|---|
committer | Peter Wu <lekensteyn@gmail.com> | 2013-11-21 17:26:18 +0100 |
commit | 304a0baa5b74ed949216e6e41bb01bcba584546c (patch) | |
tree | fc7cf0d13235ff954863fa65fc77e559546b2e9b | |
parent | 58bfc1b0e0e69c521d60e05931fcc7852a109c24 (diff) | |
download | 2iv60-robots-304a0baa5b74ed949216e6e41bb01bcba584546c.tar.gz |
Exercise 1.2 Viewing - set Eye parameter
-rw-r--r-- | src/RobotRace.java | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/src/RobotRace.java b/src/RobotRace.java index 9d6c9b4..6b9cc44 100644 --- a/src/RobotRace.java +++ b/src/RobotRace.java @@ -7,6 +7,7 @@ import static javax.media.opengl.GL2.*; import javax.swing.UIManager; import robotrace.Base; import robotrace.Vector; +import static java.lang.Math.*; /** * Handles all of the RobotRace graphics functionality, @@ -151,7 +152,7 @@ public class RobotRace extends Base { // Set the perspective. // Modify this to meet the requirements in the assignment. glu.gluPerspective(40, (float)gs.w / (float)gs.h, 0.1, 100); - + // Set camera. gl.glMatrixMode(GL_MODELVIEW); gl.glLoadIdentity(); @@ -538,7 +539,27 @@ public class RobotRace extends Base { * on the camera's default mode. */ private void setDefaultMode() { - // code goes here ... + /* z | + * | vDist % + * | % * Ey + * |%________*________ y + * Ex / % * + * / s % * + * x / - - - - - - - * + * Ey + * E = (Ex, Ey, Ez) + * sin phi = Ez / vDist => Ez = vDist * sin phi + * cos phi = s / vDist => s = vDist * cos phi + * Ex = s * sin theta + * Ey = s * cos theta + */ + float Ex, Ey, Ez, s; + Ez = gs.vDist * (float) sin(gs.phi); + s = gs.vDist * (float) cos(gs.phi); + Ex = s * (float) sin(gs.theta); + Ey = s * (float) cos(gs.theta); + + eye = new Vector(Ex, Ey, Ez); } /** |