public void display(GLAutoDrawable drawable) {

    GL2 gl = drawable.getGL().getGL2();

    // Clear the drawing area
    gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
    // Reset the current matrix to the "identity"
    gl.glLoadIdentity();

    // Move the "drawing cursor" around
    gl.glTranslatef(-1.5f, 0.0f, -6.0f);

    // Drawing Using Triangles
    gl.glBegin(GL2.GL_TRIANGLES);
    gl.glColor3f(1.0f, 0.0f, 0.0f); // Set the current drawing color to red
    gl.glVertex3f(0.0f, 1.0f, 0.0f); // Top
    gl.glColor3f(0.0f, 1.0f, 0.0f); // Set the current drawing color to green
    gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
    gl.glColor3f(0.0f, 0.0f, 1.0f); // Set the current drawing color to blue
    gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
    // Finished Drawing The Triangle
    gl.glEnd();

    // Move the "drawing cursor" to another position
    gl.glTranslatef(3.0f, 0.0f, 0.0f);
    // Draw A Quad
    gl.glBegin(GL2.GL_QUADS);
    gl.glColor3f(0.5f, 0.5f, 1.0f); // Set the current drawing color to light blue
    gl.glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
    gl.glVertex3f(1.0f, 1.0f, 0.0f); // Top Right
    gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
    gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
    // Done Drawing The Quad
    gl.glEnd();
  }
Ejemplo n.º 2
0
  @SuppressWarnings("unused")
  private static void drawBox(GL2 gl) {
    gl.glDisable(GLLightingFunc.GL_LIGHTING);
    gl.glDisable(GL.GL_TEXTURE_2D);

    gl.glColor3f(1.0f, 1.0f, 1.0f);
    gl.glBegin(GL.GL_LINE_STRIP);
    gl.glVertex3f(-0.5f, -0.5f, 0.5f);
    gl.glVertex3f(0.5f, -0.5f, 0.5f);
    gl.glVertex3f(0.5f, 0.5f, 0.5f);
    gl.glVertex3f(-0.5f, 0.5f, 0.5f);
    gl.glVertex3f(-0.5f, -0.5f, 0.5f);
    gl.glVertex3f(-0.5f, -0.5f, -0.5f);
    gl.glVertex3f(0.5f, -0.5f, -0.5f);
    gl.glVertex3f(0.5f, 0.5f, -0.5f);
    gl.glVertex3f(-0.5f, 0.5f, -0.5f);
    gl.glVertex3f(-0.5f, -0.5f, -0.5f);
    gl.glEnd();
    gl.glBegin(GL.GL_LINE_STRIP);
    gl.glVertex3f(-0.5f, 0.5f, 0.5f);
    gl.glVertex3f(-0.5f, 0.5f, -0.5f);
    gl.glEnd();
    gl.glBegin(GL.GL_LINE_STRIP);
    gl.glVertex3f(0.5f, 0.5f, 0.5f);
    gl.glVertex3f(0.5f, 0.5f, -0.5f);
    gl.glEnd();
    gl.glBegin(GL.GL_LINE_STRIP);
    gl.glVertex3f(0.5f, -0.5f, 0.5f);
    gl.glVertex3f(0.5f, -0.5f, -0.5f);
    gl.glEnd();

    gl.glEnable(GL.GL_TEXTURE_2D);
    gl.glEnable(GLLightingFunc.GL_LIGHTING);
    gl.glEnable(GLLightingFunc.GL_LIGHT0);
  }
  /**
   * if the fill colour is non-null, fill the polygon with this colour if the line colour is
   * non-null, draw the outline with this colour
   *
   * @see ass1.spec.GameObject#drawSelf(javax.media.opengl.GL2)
   */
  @Override
  public void drawSelf(GL2 gl) {

    // First draw the filling by using a polygon and looping
    if (myFillColour != null) {
      gl.glColor4d(myFillColour[0], myFillColour[1], myFillColour[2], myFillColour[3]);
      gl.glBegin(GL2.GL_POLYGON);
      int numPoints = myPoints.length / 2;
      for (int i = 0; i < numPoints; i++) {
        gl.glVertex2d(myPoints[i * 2], myPoints[i * 2 + 1]);
      }
      gl.glEnd();
    }

    // Now draw the outline by using a line loop
    if (myLineColour != null) {
      gl.glColor4d(myLineColour[0], myLineColour[1], myLineColour[2], myLineColour[3]);
      gl.glBegin(GL2.GL_LINE_LOOP);
      int numPoints = myPoints.length / 2;
      for (int i = 0; i < numPoints; i++) {
        gl.glVertex2d(myPoints[i * 2], myPoints[i * 2 + 1]);
      }
      gl.glEnd();
    }
  }
Ejemplo n.º 4
0
  /**
   * Render the arrow as a line and a _head.
   *
   * @param gl OpenGL Context
   */
  public void render(GL2 gl) {
    // save Light Attributes and remove lighting to get "full" RGB colors
    // gl.glPushAttrib( GL2.GL_LIGHTING_BIT );
    gl.glPushAttrib(GL2.GL_ENABLE_BIT);
    gl.glDisable(GL2.GL_LIGHTING);

    if (_fg_verb) {
      System.out.println(
          "Arrow pos="
              + _pos.toString()
              + "  angZ1="
              + _angZ1
              + "  angY2="
              + _angY2
              + "  length="
              + _length);
      _fg_verb = false;
    }

    // save transformation matrix, then translate and scale.
    gl.glPushMatrix();
    gl.glTranslatef(_pos.x, _pos.y, _pos.z);
    gl.glRotatef(Matrix.rad2Deg(_angZ1), 0, 0, 1); // rotation around 0z
    gl.glRotatef(Matrix.rad2Deg(_angY2), 0, 1, 0); // rotation around 0y

    // draw line
    gl.glColor4f(_color_fg.x, _color_fg.y, _color_fg.z, _color_fg.w);
    gl.glLineWidth(1.0f);
    gl.glBegin(GL.GL_LINES);
    {
      gl.glVertex3f(0, 0, 0);
      gl.glVertex3f(_length, 0, 0);
    }
    gl.glEnd();

    // draw head
    gl.glPolygonMode(GL.GL_FRONT_AND_BACK, GL2GL3.GL_FILL);
    gl.glTranslatef(_length, 0, 0);
    gl.glBegin(GL.GL_TRIANGLES);
    {
      for (float[] face : _head_faces) {
        gl.glVertex3f(face[0], face[1], face[2]);
        gl.glVertex3f(face[3], face[4], face[5]);
        gl.glVertex3f(face[6], face[7], face[8]);
      }
    }
    gl.glEnd();

    // restore transformation matrix
    gl.glPopMatrix();
    // restore attributes
    gl.glPopAttrib();
  }
  private void drawStar(GL2 gl, GLAutoDrawable drawable, Float x, Float y, Float z) {
    // Pushing to matrix stack
    gl.glPushMatrix();

    // STAR
    // Moves the figure in the (x, y, z)-axis
    gl.glTranslatef(x, y, z);

    // BEGIN Star
    gl.glBegin(GL_LINE_LOOP);

    // Pushing to attribute stack
    gl.glPushAttrib(GL_ALL_ATTRIB_BITS);

    // Set color to GREEN
    gl.glColor3f(0.0f, 1.0f, 0.0f);

    // Draw the sides
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(0.2f, 0.2f, 0.0f);
    gl.glVertex3f(1.0f, 0.0f, 0.0f);
    gl.glVertex3f(0.2f, -0.2f, 0.0f);
    gl.glVertex3f(0.0f, -1.0f, 0.0f);
    gl.glVertex3f(-0.2f, -0.2f, 0.0f);
    gl.glVertex3f(-1.0f, 0.0f, 0.0f);
    gl.glVertex3f(-0.2f, 0.2f, 0.0f);

    // END Star
    gl.glEnd();

    // Popping state
    gl.glPopAttrib();
    gl.glPopMatrix();
  }
  private void drawSquare(GL2 gl, GLAutoDrawable drawable, Float x, Float y, Float z) {
    // Pushing to matrix stack
    gl.glPushMatrix();

    // SQUARE
    // Moves the figure in the (x, y, z)-axis
    gl.glTranslatef(x, y, z);

    // Makes so that square is filled in
    gl.glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);

    // BEGIN Square
    gl.glBegin(GL_QUADS);

    // Pushing to attribute stack
    gl.glPushAttrib(GL_ALL_ATTRIB_BITS);

    // Set color to BLUE
    gl.glColor3f(0.0f, 0.0f, 1.0f);

    // The Quad
    gl.glVertex3f(1.0f, 1.0f, 1.0f);
    gl.glVertex3f(-1.0f, 1.0f, 1.0f);
    gl.glVertex3f(-1.0f, -1.0f, 1.0f);
    gl.glVertex3f(1.0f, -1.0f, 1.0f);

    // END Square
    gl.glEnd();

    // Popping state
    gl.glPopAttrib();
    gl.glPopMatrix();
  }
Ejemplo n.º 7
0
  void drawCuboid(Part p) {
    gl.glBegin(GL2.GL_LINES);

    gl.glColor3d(1, 1, 1);

    for (double vx : new double[] {-p.w / 2, p.w / 2}) {
      for (double vz : new double[] {-p.w / 2, p.w / 2}) {
        // vertical lines
        gl.glVertex3d(vx, 0, vz);
        gl.glVertex3d(vx, p.h, vz);
      }

      for (double vy : new double[] {0, p.h}) {
        // hoizontal lines parallel to z axis
        gl.glVertex3d(vx, vy, -p.w / 2);
        gl.glVertex3d(vx, vy, p.w / 2);

        // hoizontal lines parallel to x axis
        gl.glVertex3d(-p.w / 2, vy, vx);
        gl.glVertex3d(p.w / 2, vy, vx);
      }
    }

    gl.glEnd();
  }
Ejemplo n.º 8
0
  /** Called back by the animator to perform rendering. */
  @Override
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2(); // get the OpenGL 2 graphics context
    gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // clear color and depth buffers
    gl.glLoadIdentity(); // reset the model-view matrix

    gl.glTranslatef(0.0f, 0.0f, -12.0f);
    gl.glRotatef(rotateAnleX, 1.0f, 0.0f, 0.0f);
    gl.glRotatef(rotateAnleY, 0.0f, 1.0f, 0.0f);
    gl.glRotatef(rotateAngleZ, 0.0f, 0.0f, 1.0f);

    // need to flip the image
    float textureHeight = textureTop - textureBottom;

    float x1, y1, x2, y2; // used to break the flag into tiny quads

    gl.glBegin(GL_QUADS);
    for (int x = 0; x < numPoints - 1; x++) {
      for (int y = 0; y < numPoints - 1; y++) {
        x1 = (float) x / 44.0f;
        y1 = (float) y / 44.0f;
        x2 = (float) (x + 1) / 44.0f;
        y2 = (float) (y + 1) / 44.0f;

        // Texture need to flip vertically
        gl.glTexCoord2f(x1, y1 * textureHeight + textureBottom);
        gl.glVertex3f(points[x][y][0], points[x][y][1], points[x][y][2]);

        gl.glTexCoord2f(x1, y2 * textureHeight + textureBottom);
        gl.glVertex3f(points[x][y + 1][0], points[x][y + 1][1], points[x][y + 1][2]);

        gl.glTexCoord2f(x2, y2 * textureHeight + textureBottom);
        gl.glVertex3f(points[x + 1][y + 1][0], points[x + 1][y + 1][1], points[x + 1][y + 1][2]);

        gl.glTexCoord2f(x2, y1 * textureHeight + textureBottom);
        gl.glVertex3f(points[x + 1][y][0], points[x + 1][y][1], points[x + 1][y][2]);
      }
    }
    gl.glEnd();

    if (wiggleCount == 2) { // Used To Slow Down The Wave (Every 2nd Frame Only)
      for (int y = 0; y < 45; y++) {
        float tempHold = points[0][y][2]; // Store current value One Left Side Of
        // Wave
        for (int x = 0; x < 44; x++) {
          // Current Wave Value Equals Value To The Right
          points[x][y][2] = points[x + 1][y][2];
        }
        points[44][y][2] = tempHold; // Last Value Becomes The Far Left Stored
        // Value
      }
      wiggleCount = 0; // Set Counter Back To Zero
    }
    wiggleCount++;

    // update the rotational position after each refresh
    rotateAnleX += roateSpeedX;
    rotateAnleY += rotateSpeedY;
    rotateAngleZ += rotateSpeedZ;
  }
Ejemplo n.º 9
0
  /**
   * Draws the outline of a 2D circle centered on the specified point and contained in the XY plane
   * (z=0). Uses an efficient parametric algorithm to avoid expensive calls to triginometric
   * functions. Verticies are evenly spaced in parameter space.
   *
   * <p>Reference: Rogers, D.F., Adams, J.A., _Mathematical_Elements_For_Computer_Graphics_,
   * McGraw-Hill, 1976, pg 103, 216.
   *
   * @param gl Reference to the graphics context we are rendering into.
   * @param x X Coordinate of the center of the circle.
   * @param y Y Coordinate of the center of the circle.
   * @param radius The radius of the cirlce.
   * @param numVerts The number of verticies to use.
   */
  public static final void drawCircled(GL2 gl, double x, double y, double radius, int numVerts) {

    //  Calculate the parametric increment.
    double p = 2 * Math.PI / (numVerts - 1);
    double c1 = Math.cos(p);
    double s1 = Math.sin(p);

    //  Calculate the initial point.
    double xm1 = x + radius;
    double ym1 = y;

    //  Begin rendering the circle.
    gl.glBegin(GL2.GL_LINE_LOOP);
    for (int m = 0; m < numVerts; ++m) {
      double xm1mx = xm1 - x;
      double ym1mx = ym1 - y;
      double x1 = x + xm1mx * c1 - ym1mx * s1;
      double y1 = y + xm1mx * s1 + ym1mx * c1;

      //  Draw the next line segment.
      gl.glVertex3d(x1, y1, 0);

      //  Prepare for the next loop.
      xm1 = x1;
      ym1 = y1;
    }
    gl.glEnd();
  }
Ejemplo n.º 10
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    //
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);

    if (derefMethod == DRAWARRAY) {
      gl.glDrawArrays(GL2.GL_TRIANGLES, 0, 6);
    } else if (derefMethod == ARRAYELEMENT) {
      gl.glBegin(GL2.GL_TRIANGLES);
      gl.glArrayElement(2);
      gl.glArrayElement(3);
      gl.glArrayElement(5);
      gl.glEnd();
    } else if (derefMethod == DRAWELEMENTS) {
      int indices[] = new int[] {0, 1, 3, 4};
      if (indicesBuf == null) {
        indicesBuf = GLBuffers.newDirectIntBuffer(indices.length);
        indicesBuf.put(indices);
      }
      indicesBuf.rewind();
      gl.glDrawElements(GL2.GL_POLYGON, 4, GL2.GL_UNSIGNED_INT, indicesBuf);
    }
    gl.glFlush();

    // gl calls from C example's mouse routine are moved here
    if (setupMethod == INTERLEAVED) setupInterleave(gl);
    else if (setupMethod == POINTER) setupPointers(gl);
  }
Ejemplo n.º 11
0
  private void drawSheet() {
    boolean flag = true;
    float[] n = {0.0f, 1.0f, 0.0f};
    for (int i = -10; i < 11; i++) {
      for (int j = -10; j < 11; j++) {
        if (flag) {
          gl.glMaterialfv(GL.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, whiteMaterial);
        } else {
          gl.glMaterialfv(GL.GL_FRONT, GL2.GL_AMBIENT_AND_DIFFUSE, blackMaterial);
        }
        flag = !flag;
        gl.glBegin(GL2.GL_QUADS);

        gl.glNormal3fv(n, 0);
        gl.glVertex3d(i, 0, j);
        gl.glNormal3fv(n, 0);
        gl.glVertex3d(i, 0, j - 1);
        gl.glNormal3fv(n, 0);
        gl.glVertex3d(i - 1, 0, j - 1);
        gl.glNormal3fv(n, 0);
        gl.glVertex3d(i - 1, 0, j);
        gl.glEnd();
      }
    }
  }
Ejemplo n.º 12
0
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();

    // need a valid GL context for this ..

    /** OpenGL .. texture.updateSubImage(textureData, 0, 20, 20, 20, 20, 100, 100); */

    // Now draw one quad with the texture
    if (null != texture) {
      texture.enable();
      texture.bind();
      gl.glTexEnvi(GL2.GL_TEXTURE_ENV, GL2.GL_TEXTURE_ENV_MODE, GL2.GL_REPLACE);
      TextureCoords coords = texture.getImageTexCoords();
      gl.glBegin(GL2.GL_QUADS);
      gl.glTexCoord2f(coords.left(), coords.bottom());
      gl.glVertex3f(0, 0, 0);
      gl.glTexCoord2f(coords.right(), coords.bottom());
      gl.glVertex3f(1, 0, 0);
      gl.glTexCoord2f(coords.right(), coords.top());
      gl.glVertex3f(1, 1, 0);
      gl.glTexCoord2f(coords.left(), coords.top());
      gl.glVertex3f(0, 1, 0);
      gl.glEnd();
      texture.disable();
    }
  }
Ejemplo n.º 13
0
  /**
   * Draws a filled 2D circle centered on the specified point and contained in the XY plane (z=0).
   * Uses an efficient parametric algorithm to avoid expensive calls to triginometric functions.
   * Verticies are evenly spaced in parameter space.
   *
   * <p>Reference: Rogers, D.F., Adams, J.A., _Mathematical_Elements_For_Computer_Graphics_,
   * McGraw-Hill, 1976, pg 103, 216.
   *
   * @param gl Reference to the graphics context we are rendering into.
   * @param x X Coordinate of the center of the circle.
   * @param y Y Coordinate of the center of the circle.
   * @param radius The radius of the cirlce.
   * @param numVerts The number of verticies to use.
   */
  public static final void drawCircleFill(GL2 gl, float x, float y, float radius, int numVerts) {

    //  Calculate the parametric increment.
    double p = 2 * Math.PI / (numVerts - 1);
    float c1 = (float) Math.cos(p);
    float s1 = (float) Math.sin(p);

    //  Calculate the initial point.
    float xm1 = x + radius;
    float ym1 = y;

    //  Begin rendering the circle.
    gl.glBegin(GL2.GL_TRIANGLE_FAN);
    gl.glVertex3f(x, y, 0.0f); // origin
    for (int m = 0; m < numVerts; ++m) {
      float xm1mx = xm1 - x;
      float ym1mx = ym1 - y;
      float x1 = x + xm1mx * c1 - ym1mx * s1;
      float y1 = y + xm1mx * s1 + ym1mx * c1;

      //  Draw the next line segment.
      gl.glVertex3f(x1, y1, 0);

      //  Prepare for the next loop.
      xm1 = x1;
      ym1 = y1;
    }
    gl.glEnd();
  }
Ejemplo n.º 14
0
  private void buildFont(GL2 gl) { // Build Our Font Display List

    base = gl.glGenLists(256); // Creating 256 Display Lists

    for (int loop1 = 0; loop1 < 256; loop1++) { // Loop Through All 256
      // Lists

      float cx = (float) (loop1 % 16) / 16.0f; // X Position Of Current
      // Character
      float cy = (float) (loop1 / 16) / 16.0f; // Y Position Of Current
      // Character

      gl.glNewList(base + loop1, GL2.GL_COMPILE); // Start Building A List
      gl.glBegin(GL2.GL_QUADS); // Use A Quad For Each Character
      gl.glTexCoord2f(cx, 1.0f - cy - 0.0625f); // Texture Coord (Bottom
      // Left)
      gl.glVertex2d(0, 16); // Vertex Coord (Bottom Left)
      gl.glTexCoord2f(cx + 0.0625f, 1.0f - cy - 0.0625f); // Texture Coord
      // (Bottom
      // Right)
      gl.glVertex2i(16, 16); // Vertex Coord (Bottom Right)
      gl.glTexCoord2f(cx + 0.0625f, 1.0f - cy - 0.001f); // Texture Coord
      // (Top Right)
      gl.glVertex2i(16, 0); // Vertex Coord (Top Right)
      gl.glTexCoord2f(cx, 1.0f - cy - 0.001f); // Texture Coord (Top Left)
      gl.glVertex2i(0, 0); // Vertex Coord (Top Left)
      gl.glEnd(); // Done Building Our Quad (Character)
      gl.glTranslated(14, 0, 0); // Move To The Right Of The Character
      gl.glEndList(); // Done Building The Display List
    } // Loop Until All 256 Are Built
  }
Ejemplo n.º 15
0
  @Override
  public void display(GLAutoDrawable gLDrawable) {
    final GL2 gl = gLDrawable.getGL().getGL2();
    gl.glClear(GL.GL_COLOR_BUFFER_BIT);
    gl.glClear(GL.GL_DEPTH_BUFFER_BIT);
    gl.glLoadIdentity();
    gl.glTranslatef(0.0f, 0.0f, -5.0f);

    // rotate about the three axes
    gl.glRotatef(rotateT, 1.0f, 0.0f, 0.0f);
    gl.glRotatef(rotateT, 0.0f, 1.0f, 0.0f);
    gl.glRotatef(rotateT, 0.0f, 0.0f, 1.0f);

    // Draw A Quad
    gl.glBegin(GL2.GL_QUADS);
    gl.glColor3f(0.0f, 1.0f, 1.0f); // set the color of the quad
    gl.glVertex3f(-1.0f, 1.0f, 0.0f); // Top Left
    gl.glVertex3f(1.0f, 1.0f, 0.0f); // Top Right
    gl.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
    gl.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
    // Done Drawing The Quad
    gl.glEnd();

    // increasing rotation for the next iteration
    rotateT += 0.2f;
  }
  @Override
  public void draw(GL2 gl, Object obj) {
    if (!(Force.class.isAssignableFrom(obj.getClass()))) return;

    Force force = (Force) obj;

    gl.glLineWidth(2.5f);
    gl.glColor3f(1.0f, 0f, 0f);
    gl.glBegin(GL.GL_LINES);
    gl.glVertex3d(
        force.getPointApplication().getX(),
        force.getPointApplication().getY(),
        force.getPointApplication().getZ());

    Vector3D finalPoint = force.getPointApplication().add(force.getForce());
    gl.glVertex3d(finalPoint.getX(), finalPoint.getY(), finalPoint.getZ());
    gl.glEnd();

    gl.glTranslated(
        force.getPointApplication().getX(),
        force.getPointApplication().getY(),
        force.getPointApplication().getZ());
    gl.glColor3f(1.0f, 0.0f, 0.0f);
    GLU glu = new GLU();
    GLUquadric q = glu.gluNewQuadric();
    glu.gluQuadricDrawStyle(q, GLU.GLU_FILL);
    glu.gluSphere(q, Force.originRadius, 5, 5);
    glu.gluDeleteQuadric(q);
  }
Ejemplo n.º 17
0
 @Override
 public void paint(GL2 gl) {
   gl.glColor3fv(color, 0);
   gl.glBegin(GL2.GL_LINES);
   gl.glVertex2d(x, y0);
   gl.glVertex2d(x, y1);
   gl.glEnd();
 }
Ejemplo n.º 18
0
  public static void rect(GL2 gl, float x, float y, float w, float h) {

    gl.glBegin(GL2.GL_QUADS);
    gl.glVertex2f(x, y);
    gl.glVertex2f(x + w, y);
    gl.glVertex2f(x + w, y + h);
    gl.glVertex2f(x, y + h);
    gl.glEnd();
  }
Ejemplo n.º 19
0
  /*Begin Other Methods*/
  @Override
  public void draw(GL2 gl) {
    super.draw(gl);

    gl.glBegin(GL2.GL_POLYGON);
    for (Point2D<Double> point : this.__points) {
      gl.glVertex3d(point.getX(), point.getY(), 0);
    }
    gl.glEnd();
  }
Ejemplo n.º 20
0
  /**
   * This method is a temporary helper method for draving the light for debuging purposes. Except it
   * to decome deprecated in the future.
   */
  public void renderLight(GL2 gl) {
    gl.glDisable(GLLightingFunc.GL_LIGHTING);
    ShaderProgram.unuseCurrent(gl);
    switch (type) {
      case Directional:
        gl.glBegin(GL2.GL_LINES);
        gl.glColor3f(0.0f, 0.0f, 0.0f);
        gl.glVertex3f(0.0f, 0.0f, 0.0f);
        gl.glColor3f(1.0f, 1.0f, 1.0f);
        gl.glVertex3f(position.x, position.y, position.z);
        gl.glEnd();
        break;
      case Point:
        gl.glBegin(GL2.GL_POINTS);
        gl.glColor3f(1.0f, 1.0f, 1.0f);
        gl.glVertex3f(position.x, position.y, position.z);
        gl.glEnd();
        break;
      case Spot:
        Vector3f p = position, d = new Vector3f();
        d.set(direction);
        d.scale(4);

        gl.glBegin(GL2.GL_LINES);
        gl.glColor3f(1.0f, 1.0f, 1.0f);
        gl.glVertex3f(p.x, p.y, p.z);
        gl.glColor3f(0.2f, 0.2f, 0.2f);
        gl.glVertex3f(p.x + d.x, p.y + d.y, p.z + d.z);

        /* Spot wireframe
        d.normalize();
        //d.
        d.cross(d, new Vector3f(0.0f, 1.0f, 0.0f));
        gl.glColor3f(1.0f, 1.0f, 1.0f);
        gl.glVertex3f(p.x, p.y, p.z);
        gl.glColor3f(0.4f, 0.2f, 0.2f);
        gl.glVertex3f(p.x+d.x, p.y+d.y, p.z+d.z);
        */
        gl.glEnd();
    }
    gl.glEnable(GLLightingFunc.GL_LIGHTING);
  }
  // Support Methods
  private void drawPyramid(GL2 gl, GLAutoDrawable drawable, Float x, Float y, Float z) {
    // Pushing to matrix stack
    gl.glPushMatrix();

    // PYRAMID
    // Moves the figure in the (x, y, z)-axis
    gl.glTranslatef(x, y, z);

    // Rotates the pyramid, just for "fun"
    gl.glRotatef(-55.0f, 0.0f, 1.0f, 0.0f);

    // Makes only the outlines
    gl.glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);

    // BEGIN Pyramid
    gl.glBegin(GL_TRIANGLES);

    // Pushing current color to stack
    gl.glPushAttrib(GL_ALL_ATTRIB_BITS);

    // Set color to RED
    gl.glColor3f(1.0f, 0.0f, 0.0f);

    // Front triangle
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(-1.0f, -1.0f, 1.0f);
    gl.glVertex3f(1.0f, -1.0f, 1.0f);

    // Right triangle
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(1.0f, -1.0f, 1.0f);
    gl.glVertex3f(1.0f, -1.0f, -1.0f);

    // Left triangle
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(-1.0f, -1.0f, -1.0f);
    gl.glVertex3f(-1.0f, -1.0f, 1.0f);

    // Back triangle
    gl.glVertex3f(0.0f, 1.0f, 0.0f);
    gl.glVertex3f(1.0f, -1.0f, -1.0f);
    gl.glVertex3f(-1.0f, -1.0f, -1.0f);

    // END Pyramid
    gl.glEnd();

    // Popping state
    gl.glPopAttrib();
    gl.glPopMatrix();
  }
Ejemplo n.º 22
0
  @Override
  public void render(GL2 gl, float trajectory) {
    //		flat = true;

    gl.glPushMatrix();
    {
      gl.glTranslatef(c.x, c.y, c.z);
      gl.glRotatef(trajectory, 0, -1, 0);
      gl.glRotatef((flat) ? -90 : 0, 1, 0, 0);
      gl.glRotatef(rotation, 0, 0, 1);

      Vec3 scale = new Vec3(0.75f, 2.0f, 0);
      if (miniature) scale = scale.multiply(0.5f);
      scale = scale.multiply(0.8f);

      gl.glScalef(scale.x, scale.y, scale.z);
      gl.glTranslatef(0, 0.2f, 0);

      gl.glDepthMask(false);
      gl.glDisable(GL_LIGHTING);
      gl.glEnable(GL_BLEND);
      gl.glEnable(GL_TEXTURE_2D);

      gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE);

      whiteSpark.bind(gl);

      gl.glColor3f(colors[color][0], colors[color][1], colors[color][2]);

      gl.glBegin(GL_QUADS);
      {
        gl.glTexCoord2f(1.0f, 1.0f);
        gl.glVertex3f(-0.5f, -0.5f, 0.0f);
        gl.glTexCoord2f(1.0f, 0.0f);
        gl.glVertex3f(-0.5f, 0.5f, 0.0f);
        gl.glTexCoord2f(0.0f, 0.0f);
        gl.glVertex3f(0.5f, 0.5f, 0.0f);
        gl.glTexCoord2f(0.0f, 1.0f);
        gl.glVertex3f(0.5f, -0.5f, 0.0f);
      }
      gl.glEnd();

      gl.glDisable(GL_BLEND);
      gl.glEnable(GL_LIGHTING);
      gl.glDepthMask(true);

      gl.glColor3f(1, 1, 1);
    }
    gl.glPopMatrix();
  }
  @Override
  public void draw(IBNAView view, ICoordinateMapper cm, GL2 gl, Rectangle clip, IResources r) {
    if (Boolean.TRUE.equals(t.get(IHasSelected.SELECTED_KEY))) {
      List<Point> localPoints = BNAUtils.worldToLocal(cm, t.getPoints());

      gl.glLineWidth(1f);

      gl.glColor3f(1f, 1f, 1f);
      gl.glBegin(GL2.GL_LINE_STRIP);
      for (Point p : localPoints) {
        gl.glVertex2f(p.x + 0.5f, p.y + 0.5f);
      }
      gl.glEnd();

      gl.glColor3f(0f, 0f, 0f);
      gl.glLineStipple(1, (short) (0x0f0f0f0f >> t.getRotatingOffset() % 8));
      gl.glBegin(GL2.GL_LINE_STRIP);
      for (Point p : localPoints) {
        gl.glVertex2f(p.x + 0.5f, p.y + 0.5f);
      }
      gl.glEnd();
    }
  }
Ejemplo n.º 24
0
 public void drawSquare(GL2 gl, float x, float y, float w, float h) {
   gl.glBegin(GL_QUADS);
   {
     gl.glTexCoord2f(0, 0);
     gl.glVertex2f(x, y);
     gl.glTexCoord2f(1, 0);
     gl.glVertex2f(x + w, y);
     gl.glTexCoord2f(1, 1);
     gl.glVertex2f(x + w, y + h);
     gl.glTexCoord2f(0, 1);
     gl.glVertex2f(x, y + h);
   }
   gl.glEnd();
 }
Ejemplo n.º 25
0
  /**
   * Draws the outline of a 2D inclinded elliptical arc starting at "angle" and extending to angle +
   * sweep, centered on the specified point, and contained in the XY plane (z=0). Note that "angle"
   * is defined differently than it is for gluPartialDisk()! Uses an efficient parametric algorithm
   * to avoid expensive calls to triginometric functions. Verticies are evenly spaced in parameter
   * space. If "a" and "b" are equal, a circular arc will be rendered.
   *
   * <p>Reference: Rogers, D.F., Adams, J.A., _Mathematical_Elements_For_Computer_Graphics_,
   * McGraw-Hill, 1976, pg 104, 216.
   *
   * @param gl Reference to the graphics context we are rendering into.
   * @param x X Coordinate of the center of the ellipse defining the arc.
   * @param y Y Coordinate of the center of the ellipse defining the arc.
   * @param a Length of the semi-major axis of the ellipse defining the arc, oriented along the X
   *     axis.
   * @param b Length of the semi-minor axis of the ellipse defining the arc, oriented along the Y
   *     axis.
   * @param inc Inclination angle of the major axis in degrees.
   * @param angle The initial angle to begin the arc in degrees. 0 is along the + major axis (+X for
   *     zero inc), 90 is along the + minor axis (+Y for zero inc), 180 along the - major axis and
   *     270 degrees is along the - minor axis.
   * @param sweep The number of degrees to sweep the arc through.
   * @param numVerts The number of verticies to use.
   */
  public static final void drawArc(
      GL2 gl,
      float x,
      float y,
      float a,
      float b,
      float inc,
      float angle,
      float sweep,
      int numVerts) {

    //  Calculate the sine and cosine of the inclination angle.
    double p = inc * Math.PI / 180;
    float c1 = (float) Math.cos(p);
    float s1 = (float) Math.sin(p);

    //  Calculate the parametric increment.
    p = sweep * Math.PI / 180 / (numVerts - 1);

    //  Calculate the sine and cosine of the parametric increment.
    float c2 = (float) Math.cos(p);
    float s2 = (float) Math.sin(p);

    //  Initialize the accumulation variables.
    p = angle * Math.PI / 180;
    float c3 = (float) Math.cos(p);
    float s3 = (float) Math.sin(p);

    //  Begin rendering the arc.
    gl.glBegin(GL2.GL_LINE_STRIP);
    for (int m = 0; m < numVerts; ++m) {
      //  Calculate increments in X & Y.
      float x1 = a * c3;
      float y1 = b * s3;

      //  Calculate new X & Y.
      float xm = x + x1 * c1 - y1 * s1;
      float ym = y + x1 * s1 + y1 * c1;

      //  Draw the next line segment.
      gl.glVertex3f(xm, ym, 0);

      //  Calculate new angle values.
      float t1 = c3 * c2 - s3 * s2;
      s3 = s3 * c2 + c3 * s2;
      c3 = t1;
    }
    gl.glEnd();
  }
Ejemplo n.º 26
0
    /**
     * Render all particles to the OpenGL context
     *
     * @param gl
     */
    protected void render(GL2 gl) {
      gl.glBegin(GL2.GL_QUADS);

      for (int i = 0; i < (range.getGlobalSize(0) * 3); i += 3) {
        gl.glTexCoord2f(0, 1);
        gl.glVertex3f(xyz[i + 0], xyz[i + 1] + 1, xyz[i + 2]);
        gl.glTexCoord2f(0, 0);
        gl.glVertex3f(xyz[i + 0], xyz[i + 1], xyz[i + 2]);
        gl.glTexCoord2f(1, 0);
        gl.glVertex3f(xyz[i + 0] + 1, xyz[i + 1], xyz[i + 2]);
        gl.glTexCoord2f(1, 1);
        gl.glVertex3f(xyz[i + 0] + 1, xyz[i + 1] + 1, xyz[i + 2]);
      }
      gl.glEnd();
    }
Ejemplo n.º 27
0
  /**
   * Draws a centered grid with given dimensions
   *
   * @param gl OpenGL context
   * @param h grid height
   * @param v grid width
   */
  public static void drawGrid(GL2 gl, int h, int v) {
    gl.glBegin(GL_LINES);
    gl.glColor3d(.3, .3, .3);

    for (int x = -h / 2; x <= h / 2; x++) {
      gl.glVertex3i(x, 0, -v / 2);
      gl.glVertex3i(x, 0, v / 2);
    }
    for (int z = -v / 2; z <= v / 2; z++) {
      gl.glVertex3i(-h / 2, 0, z);
      gl.glVertex3i(h / 2, 0, z);
    }

    gl.glEnd();
  }
Ejemplo n.º 28
0
  @Override
  protected void updateGeometry(GL2 gl) {
    float width = scene.view.obstacle.edgeWidth;
    if (scene.view.renderer.fixedWidthEdges) width /= camera.getScale();
    for (int i = 0; i < scene.cspace.obstacle.e.length; i++)
      new ArcGeometry(scene.cspace.obstacle.e[i]).draw(gl, width, scene.view.obstacle.edgeDetail);

    if (scene.view.obstacle.originVisible) {
      gl.glBegin(GL2.GL_LINES);
      gl.glVertex2f(-0.1f, 0);
      gl.glVertex2f(0.1f, 0);
      gl.glVertex2f(0, -0.1f);
      gl.glVertex2f(0, 0.1f);
      gl.glEnd();
    }
  }
Ejemplo n.º 29
0
  @Override
  public void draw(GL2 gl) {
    // Arbres triangles
    gl.glBegin(GL_TRIANGLES);

    gl.glColor3f(30.0f / 256.0f, 109.0f / 256.0f, 54.0f / 256.0f);
    gl.glVertex3f(0.0f, hauteurArbre, 0.0f);
    gl.glVertex3f(-largeurArbre, 0.0f, 0.0f);
    gl.glVertex3f(largeurArbre, 0.0f, 0.0f);
    gl.glColor3f(47.0f / 256.0f, 135.0f / 256.0f, 74.0f / 256.0f);
    gl.glVertex3f(0.0f, hauteurArbre, 0.0f);
    gl.glVertex3f(0.0f, 0.0f, -largeurArbre);
    gl.glVertex3f(0.0f, 0.0f, largeurArbre);

    gl.glEnd();
  }
Ejemplo n.º 30
0
  public static void drawCoordinateSystem(GL2 gl) {
    gl.glBegin(GL_LINES);
    gl.glColor3d(1, 0, 0);

    gl.glVertex3i(0, 0, 0);
    gl.glVertex3i(1, 0, 0);

    gl.glColor3d(1, 1, 0);

    gl.glVertex3i(0, 0, 0);
    gl.glVertex3i(0, 1, 0);

    gl.glColor3d(0, 1, 0);

    gl.glVertex3i(0, 0, 0);
    gl.glVertex3i(0, 0, 1);
    gl.glEnd();
  }