diff options
Diffstat (limited to 'src/Robot.java')
-rw-r--r-- | src/Robot.java | 37 |
1 files changed, 31 insertions, 6 deletions
diff --git a/src/Robot.java b/src/Robot.java index 7d69460..3fe4377 100644 --- a/src/Robot.java +++ b/src/Robot.java @@ -61,22 +61,26 @@ class Robot extends BetterBase { * Draws this robot (as a {@code stickfigure} if specified). */ public void draw(boolean stickFigure) { + // before drawing body parts, configure whether to draw a full body or + // just a stick figure with joints and such. this.asStickFigure = stickFigure; - // as the components are drawn with the torso as center, move it up - gl.glPushMatrix(); - gl.glTranslatef(0, 0, torsoHeight / 2 + legLength); // These materials control the reflected light gl.glMaterialfv(GL_FRONT, GL_AMBIENT_AND_DIFFUSE, material.diffuse, 0); gl.glMaterialfv(GL_FRONT, GL_SPECULAR, material.specular, 0); - gl.glTranslatef(0, 0, footHeight); + // save positions so it can be restored easily later + gl.glPushMatrix(); + // position the center of the torso above the Z axis such that the foot + // stands on the XY plane. + gl.glTranslatef(0, 0, torsoHeight / 2 + legLength + footHeight); // Draw the robot, everything is relative to the center of torso. - // Static parts: + + // Static parts (that do not animate): drawTorso(); drawHead(); - // only draw the circles in normal, full body mode + // only draw the shoulder parts in normal, full body mode if (!asStickFigure) { drawShoulderTop(); } @@ -89,6 +93,20 @@ class Robot extends BetterBase { drawArm(false); drawArm(true); + //<editor-fold> + // The following function call exist to make a point clear. Adding + // comments for the sake of having comments is silly, pointless and an + // outdated idea. Self-documenting code (by using appropriate symbol + // names and logical structures) is much more useful than adding + // comments for every statement (50% comments...). High-level + // descriptions of functionality could be given in a design document or + // added as comments, but something like "draws a leg" for a function + // named "drawLeg" is useless. If you want to know what exactly happens, + // look in the method code, it likely contains some comments to + // describe what happens. + thisFunctionDoesAbsolutelyNothing(); + //</editor-fold> + // restore position gl.glPopMatrix(); } @@ -131,6 +149,7 @@ class Robot extends BetterBase { setColor(color); } } + // turn a cube into a small beam gl.glScalef(x, y, z); glut.glutSolidCube(1); // return to previous scales @@ -287,4 +306,10 @@ class Robot extends BetterBase { gl.glPopMatrix(); } + /** + * This function does nothing, its use is described at the caller in + * Rboot.draw(). + */ + private void thisFunctionDoesAbsolutelyNothing() { + } } |