Exemple #1
0
  public void draw(GL2 gl) {
    GLUT glut = new GLUT();

    // Color
    gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, new float[] {1, 1, 1, 1}, 0);
    gl.glMaterialfv(GL2.GL_FRONT, GL2.GL_EMISSION, new float[] {0, 0, 0, 1}, 0);

    gl.glPushMatrix();
    gl.glTranslated(x, y, z);
    glut.glutSolidCylinder(0.05, 0.5, 12, 1);

    gl.glTranslated(0, 0, 0.5);
    gl.glRotated(horizontalDir * 180 / Math.PI + 180, 0, 0, 1);
    gl.glRotated(verticalDir * 180 / Math.PI, 0, 1, 0);

    ModelTurret.draw(gl);

    gl.glPopMatrix();
  }
Exemple #2
0
    /**
     * Draws the body.
     *
     * <p>Only coded for polygons.
     *
     * @param gl the OpenGL graphics context
     */
    public void render(GL2 gl) {
      // save the original transform
      gl.glPushMatrix();

      // transform the coordinate system from world coordinates to local coordinates
      gl.glTranslated(this.transform.getTranslationX(), this.transform.getTranslationY(), 0.0);
      // rotate about the z-axis
      gl.glRotated(Math.toDegrees(this.transform.getRotation()), 0.0, 0.0, 1.0);

      // loop over all the body fixtures for this body
      for (BodyFixture fixture : this.fixtures) {
        // get the shape on the fixture
        Convex convex = fixture.getShape();
        // check the shape type
        if (convex instanceof Polygon) {
          // since Triangle, Rectangle, and Polygon are all of
          // type Polygon in addition to their main type
          Polygon p = (Polygon) convex;

          // set the color
          gl.glColor4fv(this.color, 0);

          // fill the shape
          gl.glBegin(GL2.GL_POLYGON);
          for (Vector2 v : p.getVertices()) {
            gl.glVertex3d(v.x, v.y, 0.0);
          }
          gl.glEnd();

          // set the color
          gl.glColor4f(this.color[0] * 0.8f, this.color[1] * 0.8f, this.color[2] * 0.8f, 1.0f);

          // draw the shape
          gl.glBegin(GL.GL_LINE_LOOP);
          for (Vector2 v : p.getVertices()) {
            gl.glVertex3d(v.x, v.y, 0.0);
          }
          gl.glEnd();
        }
        // circles and other curved shapes require a little more work, so to keep
        // this example short we only include polygon shapes; see the RenderUtilities
        // in the Sandbox application
      }

      // set the original transform
      gl.glPopMatrix();
    }