Пример #1
0
 private void setQuadParams() {
   quad = glu.gluNewQuadric();
   glu.gluQuadricDrawStyle(quad, GLU.GLU_FILL);
   glu.gluQuadricNormals(quad, GLU.GLU_FLAT);
   glu.gluQuadricOrientation(quad, GLU.GLU_OUTSIDE);
   glu.gluQuadricTexture(quad, true);
 }
Пример #2
0
  /**
   * //! Draw a pretty arrow on the z-axis using a cone and a cylinder (using GLUT)
   *
   * @param aArrowStart
   * @param aArrowTip
   * @param aWidth
   */
  public static void jDrawArrow(
      final JVector3d aArrowStart, final JVector3d aArrowTip, final double aWidth) {

    GL2 gl = GLContext.getCurrent().getGL().getGL2();

    gl.glPushMatrix();

    // We don't really care about the up vector, but it can't
    // be parallel to the arrow...
    JVector3d up = new JVector3d(0, 1, 0);
    // JVector3d arrow = aArrowTip-aArrowStart;
    JVector3d arrow = new JVector3d(0, 0, 0);
    arrow.normalize();
    double d = Math.abs(JMaths.jDot(up, arrow));
    if (d > .9) {
      up = new JVector3d(1, 0, 0);
    }

    JMatrixGL.jLookAt(gl, aArrowStart, aArrowTip, up);

    double distance = JMaths.jDistance(aArrowTip, aArrowStart);

    // This flips the z axis around
    gl.glRotatef(180, 1, 0, 0);

    // create a new OpenGL quadratic object
    GLUquadric quadObj;
    quadObj = glu.gluNewQuadric();

    // set rendering style
    glu.gluQuadricDrawStyle(quadObj, GLU.GLU_FILL);

    // set normal-rendering mode
    glu.gluQuadricNormals(quadObj, GLU.GLU_SMOOTH);

    // render a cylinder and a cone
    gl.glRotatef(180, 1, 0, 0);
    glu.gluDisk(quadObj, 0, aWidth, 10, 10);
    gl.glRotatef(180, 1, 0, 0);

    glu.gluCylinder(quadObj, aWidth, aWidth, distance * ARROW_CYLINDER_PORTION, 10, 10);
    gl.glTranslated(0, 0, ARROW_CYLINDER_PORTION * distance);

    gl.glRotatef(180, 1, 0, 0);
    glu.gluDisk(quadObj, 0, aWidth * 2.0, 10, 10);
    gl.glRotatef(180, 1, 0, 0);

    glu.gluCylinder(quadObj, aWidth * 2.0, 0.0, distance * ARRROW_CONE_PORTION, 10, 10);

    // delete our quadric object
    glu.gluDeleteQuadric(quadObj);

    gl.glPopMatrix();
  }
Пример #3
0
  /**
   * Render a sphere given a radius.
   *
   * @param aRadius
   * @param aNumSlices
   * @param aNumStacks
   */
  public static void jDrawSphere(final double aRadius, final int aNumSlices, final int aNumStacks) {
    // allocate a new OpenGL quadric object for rendering a sphere
    GLUquadric quadObj;
    quadObj = glu.gluNewQuadric();

    // set rendering style
    glu.gluQuadricDrawStyle(quadObj, GLU.GLU_FILL);

    // set normal-rendering mode
    glu.gluQuadricNormals(quadObj, GLU.GLU_SMOOTH);

    // render a sphere
    glu.gluSphere(quadObj, aRadius, aNumSlices, aNumStacks);

    // delete our quadric object
    glu.gluDeleteQuadric(quadObj);
  }