/**
   * Draw the object and all of its descendants recursively.
   *
   * <p>TODO: Complete this method
   *
   * @param gl
   */
  public void draw(GL2 gl) {

    // don't draw if it is not showing
    if (!amShowing) {
      return;
    }

    // TODO: draw the object and all its children recursively
    // setting the model transform appropriately

    // Call drawSelf() to draw the object itself
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    {
      gl.glPushMatrix();
      {
        gl.glTranslated(myTranslation[0], myTranslation[1], 0);
        gl.glScaled(myScale, myScale, 1);
        gl.glRotated(myRotation, 0, 0, 1);
        drawSelf(gl);
        for (GameObject child : myChildren) {
          child.draw(gl);
        }
      }
      gl.glPopMatrix();
    }
  }
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();

    gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_AMBIENT_AND_DIFFUSE, color, 0);
    gl.glRotated(rotateX.getValue(), 1, 0, 0);
    gl.glRotated(rotateY.getValue(), 0, 1, 0);
    gl.glRotated(rotateZ.getValue(), 0, 0, 1);
    gl.glPushMatrix();
    gl.glTranslated(translateX.getValue(), translateY.getValue(), translateZ.getValue());
    gl.glPushMatrix();
    gl.glRotated(90, 1, 0, 0);
    gl.glTranslated(0, 0, -height / 2);
    glut.glutSolidCylinder(radius, height, 32, 2);
    gl.glPopMatrix();
    super.display(drawable);
    gl.glPopMatrix();
  }
  void drawPart(Part part, double x, double y, double z, double r) {
    gl.glPushMatrix();
    gl.glTranslated(x, y, z);

    // TODO
    gl.glTranslated(0, part.h - part.w / 2, 0);
    gl.glRotated(r, 1, 0, 0);
    gl.glTranslated(0, part.w / 2 - part.h, 0);

    drawCuboid(part);
    gl.glPopMatrix();
  }
Exemple #4
0
 /**
  * Draws this robot on the screen.
  *
  * @param gl The instance of GL2 responsible for drawing the robot on the screen.
  * @param glut An instance of GLUT to optionally aid in drawing the robot body.
  * @param stickFigure If true, the robot must draw itself as a stick figure rather than a solid
  *     body.
  * @param tAnim Time since the start of the animation in seconds.
  * @param lighting The Lighting instance responsible for calculating the lighting in this scene.
  *     Can be used to set the color of bodies before drawing them.
  */
 public void draw(GL2 gl, GLUT glut, boolean stickFigure, float tAnim, Lighting lighting) {
   lighting.setMaterial(gl, getMaterial());
   gl.glPushMatrix();
   {
     gl.glTranslated(position.x(), position.y(), position.z());
     final double rotationDotY =
         direction.dot(Vector.Y) / (direction.length() * Vector.Y.length());
     final double rotationDotX =
         direction.dot(Vector.X) / (direction.length() * Vector.X.length());
     final double rotationAngle = Math.toDegrees(Math.acos(rotationDotY));
     gl.glRotated(
         (rotationDotX > 0d) ? (-rotationAngle) : (rotationAngle),
         Vector.Z.x(),
         Vector.Z.y(),
         Vector.Z.z());
     final double elevationDot =
         direction.dot(Vector.Z) / (direction.length() * Vector.Z.length());
     final double elevationAngle = Math.toDegrees(Math.asin(elevationDot));
     gl.glRotated(elevationAngle, Vector.X.x(), Vector.X.y(), Vector.X.z());
     robotBody.draw(gl, glut, stickFigure, tAnim);
   }
   gl.glPopMatrix();
 }