summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <lekensteyn@gmail.com>2013-12-02 23:20:12 +0100
committerPeter Wu <lekensteyn@gmail.com>2013-12-02 23:20:12 +0100
commit0f4533e3df3a519bbe8c647b8b9acdf926e7da1a (patch)
tree2990722c812ad81b8c5564b4fcc519b71df0b99d
parent3665481649bc9e2ac34f31504a70d93aa5bd44c9 (diff)
download2iv60-robots-0f4533e3df3a519bbe8c647b8b9acdf926e7da1a.tar.gz
drawRobots: reduce push/pop and better commentssubmission-20131202
Now robots are drawn from left to right (gold, silver, brown, orange), the direction is now explicitly documented.
-rw-r--r--src/RobotRace.java24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/RobotRace.java b/src/RobotRace.java
index a7fc2e7..5d5a99c 100644
--- a/src/RobotRace.java
+++ b/src/RobotRace.java
@@ -287,17 +287,27 @@ public class RobotRace extends Base {
* Draw all four robots in the robots array on the scene
*/
private void drawRobots() {
- // Draw all four robots on the x-axis
- for (int i = 0; i < 4; i++) {
- gl.glPushMatrix();
+ // laziness, save current positions because of translations
+ gl.glPushMatrix();
- // Place the robots on a line based on the current robot
- gl.glTranslatef(-1.5f + i * 1f, 0f, 0f);
+ // Place the robots on a line based on the current robot. Robots are
+ // drawn with a distance of 1 meter between the middle of each robot,
+ // from left to right (seen from the robot's POV). First, set the
+ // starting point in a way such that the robot is drawn left of the
+ // axis (for an even number of robots).
+ gl.glTranslatef(.5f - robots.length / 2, 0f, 0f);
+ // Draw each robot on the X-axis
+ for (Robot robot: robots) {
// Draw the current robot
- robots[i].draw(gs.showStick);
- gl.glPopMatrix();
+ robot.draw(gs.showStick);
+
+ // Position the next robot 1 meter away from the current one.
+ gl.glTranslatef(1f, 0f, 0f);
}
+
+ // restore positions
+ gl.glPopMatrix();
}
/**