diff options
author | Peter Wu <lekensteyn@gmail.com> | 2013-11-29 20:23:47 +0100 |
---|---|---|
committer | Peter Wu <lekensteyn@gmail.com> | 2013-11-29 20:23:47 +0100 |
commit | e77fa46c5daea3bb81b0551cf3f8adcd38a6cdb9 (patch) | |
tree | f85436cccbcf51cd45c6ee353f8b48e5ea4aa543 | |
parent | 2249b8e339be17f809d4a021f63ffa57a760454c (diff) | |
download | 2iv60-robots-e77fa46c5daea3bb81b0551cf3f8adcd38a6cdb9.tar.gz |
RobotRace: formatting, no functional changes
-rw-r--r-- | src/RobotRace.java | 118 |
1 files changed, 63 insertions, 55 deletions
diff --git a/src/RobotRace.java b/src/RobotRace.java index 77dcd98..c755225 100644 --- a/src/RobotRace.java +++ b/src/RobotRace.java @@ -64,22 +64,30 @@ import static java.lang.Math.*; * to the GLUT object. */ public class RobotRace extends Base { - - /** Array of the four robots. */ + + /** + * Array of the four robots. + */ private final Robot[] robots; - - /** Instance of the camera. */ + + /** + * Instance of the camera. + */ private final Camera camera; - - /** Instance of the race track. */ + + /** + * Instance of the race track. + */ private final RaceTrack raceTrack; - - /** Instance of the terrain. */ + + /** + * Instance of the terrain. + */ private final Terrain terrain; - + /** - * Constructs this robot race by initializing robots, - * camera, track, and terrain. + * Constructs this robot race by initializing robots, camera, track, and + * terrain. */ public RobotRace() { // Initialize global OpenGL provider with GLU and GLUT reference. @@ -88,36 +96,36 @@ public class RobotRace extends Base { // Create a new array of four robots robots = new Robot[4]; - + // Initialize robot 0 robots[0] = new Robot(Material.GOLD - /* add other parameters that characterize this robot */); - + /* add other parameters that characterize this robot */); + // Initialize robot 1 robots[1] = new Robot(Material.SILVER - /* add other parameters that characterize this robot */); - + /* add other parameters that characterize this robot */); + // Initialize robot 2 robots[2] = new Robot(Material.WOOD - /* add other parameters that characterize this robot */); + /* add other parameters that characterize this robot */); // Initialize robot 3 robots[3] = new Robot(Material.ORANGE - /* add other parameters that characterize this robot */); - + /* add other parameters that characterize this robot */); + // Initialize the camera camera = new Camera(gs); - + // Initialize the race track raceTrack = new RaceTrack(); - + // Initialize the terrain terrain = new Terrain(); } - + /** - * Called upon the start of the application. - * Primarily used to configure OpenGL. + * Called upon the start of the application. Primarily used to configure + * OpenGL. */ @Override public void initialize() { @@ -127,17 +135,17 @@ public class RobotRace extends Base { // Enable blending. gl.glEnable(GL_BLEND); gl.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - + // Enable anti-aliasing. gl.glEnable(GL_LINE_SMOOTH); gl.glEnable(GL_POLYGON_SMOOTH); gl.glHint(GL_LINE_SMOOTH_HINT, GL_NICEST); gl.glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST); - + // Enable depth testing. gl.glEnable(GL_DEPTH_TEST); gl.glDepthFunc(GL_LESS); - + // Enable textures. gl.glEnable(GL_TEXTURE_2D); gl.glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); @@ -151,7 +159,7 @@ public class RobotRace extends Base { public void setView() { // Select part of window. gl.glViewport(0, 0, gs.w, gs.h); - + // Set projection matrix. gl.glMatrixMode(GL_PROJECTION); gl.glLoadIdentity(); @@ -165,20 +173,20 @@ public class RobotRace extends Base { 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, + glu.gluPerspective(angle, (float) gs.w / (float) gs.h, 0.1 * gs.vDist, 10.0 * gs.vDist); // Set camera. gl.glMatrixMode(GL_MODELVIEW); gl.glLoadIdentity(); - + // Update the view according to the camera mode camera.update(gs.camMode); - glu.gluLookAt(camera.eye.x(), camera.eye.y(), camera.eye.z(), - camera.center.x(), camera.center.y(), camera.center.z(), - camera.up.x(), camera.up.y(), camera.up.z()); + glu.gluLookAt(camera.eye.x(), camera.eye.y(), camera.eye.z(), + camera.center.x(), camera.center.y(), camera.center.z(), + camera.up.x(), camera.up.y(), camera.up.z()); } - + /** * Draws the entire scene. */ @@ -186,33 +194,33 @@ public class RobotRace extends Base { public void drawScene() { // Background color. gl.glClearColor(1f, 1f, 1f, 0f); - + // Clear background. gl.glClear(GL_COLOR_BUFFER_BIT); - + // Clear depth buffer. gl.glClear(GL_DEPTH_BUFFER_BIT); - + // Set color to black. gl.glColor3f(0f, 0f, 0f); - + gl.glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); - + // Draw the axis frame if (gs.showAxes) { drawAxisFrame(); } - - // Draw the robots + + // Draw the robots drawRobots(); - + // Draw race track raceTrack.draw(gs.trackNr); - + // Draw terrain terrain.draw(); } - + /** * Draw all four robots in the robots array on the scene */ @@ -220,10 +228,10 @@ public class RobotRace extends Base { // Draw all four robots on the x-axis for (int i = 0; i < 4; i++) { gl.glPushMatrix(); - + // Place the robots on a line based on the current robot gl.glTranslatef(-1.5f + i * 1f, 0f, 0f); - + // Draw the current robot robots[i].draw(gs.showStick); gl.glPopMatrix(); @@ -248,7 +256,7 @@ public class RobotRace extends Base { gl.glScalef(1f, 0.01f, 0.01f); glut.glutSolidCube(1f); // restore scale for clarity. - gl.glScalef(1f, 1/0.01f, 1/0.01f); + gl.glScalef(1f, 1 / 0.01f, 1 / 0.01f); // draw a cone on the end of the line that has a head that has a radius // which is three times larger than the line segment. @@ -262,8 +270,8 @@ public class RobotRace extends Base { } /** - * Draws the x-axis (red), y-axis (green), z-axis (blue), - * and origin (yellow). + * Draws the x-axis (red), y-axis (green), z-axis (blue), and origin + * (yellow). */ public void drawAxisFrame() { // X-axis: normal orientation @@ -286,10 +294,10 @@ public class RobotRace extends Base { // reset color gl.glColor3f(0, 0, 0); } - + /** - * Main program execution body, delegates to an instance of - * the RobotRace implementation. + * Main program execution body, delegates to an instance of the RobotRace + * implementation. */ public static void main(String args[]) { // Being able to exit by pressing Escape would be nice. @@ -304,8 +312,8 @@ public class RobotRace extends Base { return false; } }); - System.out.println("JOGL version: " + - com.jogamp.opengl.JoglVersion.getInstance().getImplementationBuild()); + System.out.println("JOGL version: " + + com.jogamp.opengl.JoglVersion.getInstance().getImplementationBuild()); RobotRace robotRace = new RobotRace(); - } + } } |