Esempio n. 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);
 }
Esempio n. 2
0
  protected static void setup(GL pGL, int width, int height) {
    pGL.getGL2().glMatrixMode(GLMatrixFunc.GL_PROJECTION);
    pGL.getGL2().glLoadIdentity();

    // coordinate system origin at lower left with width and height same as the
    // window
    final GLU glu = new GLU();
    glu.gluOrtho2D(0.0f, width, 0.0f, height);

    pGL.getGL2().glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    pGL.getGL2().glLoadIdentity();

    pGL.glViewport(0, 0, width, height);
  }
Esempio n. 3
0
    public void error(int errnum) {
      String estring;

      estring = glu.gluErrorString(errnum);
      System.err.println("Tessellation Error: " + estring);
      System.exit(0);
    }
Esempio n. 4
0
 public void reshape(GLAutoDrawable drawable, int x, int y, int w, int h) {
   GL2 gl = drawable.getGL().getGL2();
   //
   gl.glViewport(0, 0, w, h);
   gl.glMatrixMode(GL2.GL_PROJECTION);
   gl.glLoadIdentity();
   glu.gluOrtho2D(0.0, (double) w, 0.0, (double) h);
 }
Esempio n. 5
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);
  }
Esempio n. 6
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();
  }
Esempio n. 7
0
 private void applyMovementAndRotation(final GL2 gl) {
   glu.gluLookAt(
       0.0 + cah.getCx(),
       0.0 + cah.getCy(),
       0.0 + cah.getCz(),
       5.0 * Math.sin(cah.getX()) + cah.getCx(),
       5.0 * Math.sin(cah.getY()) + cah.getCy(),
       5.0 * Math.cos(cah.getX()) + cah.getCz(),
       0.0,
       1.0,
       0.0);
 }
  @Override
  public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
    GL2 gl = drawable.getGL().getGL2();
    gl.glMatrixMode(GL_PROJECTION);
    gl.glLoadIdentity();
    glu.gluPerspective(30.0, (double) width / (double) height, 1.0, 300.0);

    // 視点位置と視線方向
    // glu.gluLookAt(3.0f, 4.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);//コメントアウト

    gl.glMatrixMode(GL_MODELVIEW);
  }
Esempio n. 9
0
  @Override
  public void reshape(GLAutoDrawable drawable, int x, int y, int width, int height) {
    final GL2 gl = drawable.getGL().getGL2();
    if (height <= 0) height = 1;

    final float h = (float) width / (float) height;
    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL2.GL_PROJECTION);
    gl.glLoadIdentity();

    glu.gluPerspective(FOV, h, 1.0, 4000.0);
    gl.glMatrixMode(GL2.GL_MODELVIEW);
    gl.glLoadIdentity();
  }
Esempio n. 10
0
  @Override
  public void reshape(
      final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
    final GL2ES1 gl = drawable.getGL().getGL2ES1();

    gl.glMatrixMode(GLMatrixFunc.GL_PROJECTION);
    gl.glLoadIdentity();

    // coordinate system origin at lower left with width and height same as the window
    glu.gluOrtho2D(0.0f, width, 0.0f, height);

    gl.glMatrixMode(GLMatrixFunc.GL_MODELVIEW);
    gl.glLoadIdentity();

    gl.glViewport(0, 0, width, height);
  }
  @Override
  public void display(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    gl.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // GL_DEPTH_BUFFER_BITを追加
    gl.glLoadIdentity();

    // 視点位置と視線方向
    glu.gluLookAt(3.0f, 4.0f, 5.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

    // 光源の位置設定
    //		gl.glLightfv(GL_LIGHT0, GL_POSITION, light0pos, 0);
    //		gl.glLightfv(GL_LIGHT1, GL_POSITION, light1pos, 0);

    // 図形の回転
    gl.glTranslatef(0.5f, 0.5f, 0.5f);
    gl.glRotatef(r, 0.0f, 1.0f, 0.0f);
    gl.glTranslatef(-0.5f, -0.5f, -0.5f);
    // 図形の色 (赤)
    //		gl.glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE, red, 0);//追加
    //		gl.glColor3f(0.0f, 0.0f, 0.0f);

    // 図形の描画
    gl.glBegin(GL_QUADS);
    for (int j = 0; j < 6; ++j) {
      //			gl.glColor3fv(color[j], 0); //追加
      //			gl.glNormal3fv(normal[j], 0);
      for (int i = 0; i < 4; ++i) {
        gl.glNormal3fv(vertex[face[j][i]], 0);
        gl.glVertex3fv(vertex[face[j][i]], 0);
      }
    }
    gl.glEnd();

    // 一周回ったら回転角を 0 に戻す
    if (r++ >= 360.0f) r = 0;
    System.out.println("anim:" + animator.isAnimating() + ", r:" + r);
    if (willAnimatorPause) {
      animator.pause();
      System.out.println("animoator paused:");
      willAnimatorPause = false;
    }
  }
Esempio n. 12
0
  public void init(GLAutoDrawable drawable) {
    GL2 gl = drawable.getGL().getGL2();
    glu = new GLU();
    /*
     * jogl specific addition for tessellation
     */
    tessellCallBack tessCallback = new tessellCallBack(gl, glu);
    //
    double rect[][] =
        new double[][] { // [4][3] in C; reverse here
          {50.0, 50.0, 0.0}, {200.0, 50.0, 0.0}, {200.0, 200.0, 0.0}, {50.0, 200.0, 0.0}
        };
    double tri[][] =
        new double[][] { // [3][3]
          {75.0, 75.0, 0.0}, {125.0, 175.0, 0.0}, {175.0, 75.0, 0.0}
        };
    double star[][] =
        new double[][] { // [5][6]; 6x5 in java
          {250.0, 50.0, 0.0, 1.0, 0.0, 1.0},
          {325.0, 200.0, 0.0, 1.0, 1.0, 0.0},
          {400.0, 50.0, 0.0, 0.0, 1.0, 1.0},
          {250.0, 150.0, 0.0, 1.0, 0.0, 0.0},
          {400.0, 150.0, 0.0, 0.0, 1.0, 0.0}
        };

    gl.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

    startList = gl.glGenLists(2);

    GLUtessellator tobj = glu.gluNewTess();

    glu.gluTessCallback(tobj, GLU.GLU_TESS_VERTEX, tessCallback); // glVertex3dv);
    glu.gluTessCallback(tobj, GLU.GLU_TESS_BEGIN, tessCallback); // beginCallback);
    glu.gluTessCallback(tobj, GLU.GLU_TESS_END, tessCallback); // endCallback);
    glu.gluTessCallback(tobj, GLU.GLU_TESS_ERROR, tessCallback); // errorCallback);

    /* rectangle with triangular hole inside */
    gl.glNewList(startList, GL2.GL_COMPILE);
    gl.glShadeModel(GL2.GL_FLAT);
    glu.gluTessBeginPolygon(tobj, null);
    glu.gluTessBeginContour(tobj);
    glu.gluTessVertex(tobj, rect[0], 0, rect[0]);
    glu.gluTessVertex(tobj, rect[1], 0, rect[1]);
    glu.gluTessVertex(tobj, rect[2], 0, rect[2]);
    glu.gluTessVertex(tobj, rect[3], 0, rect[3]);
    glu.gluTessEndContour(tobj);
    glu.gluTessBeginContour(tobj);
    glu.gluTessVertex(tobj, tri[0], 0, tri[0]);
    glu.gluTessVertex(tobj, tri[1], 0, tri[1]);
    glu.gluTessVertex(tobj, tri[2], 0, tri[2]);
    glu.gluTessEndContour(tobj);
    glu.gluTessEndPolygon(tobj);
    gl.glEndList();

    glu.gluTessCallback(tobj, GLU.GLU_TESS_VERTEX, tessCallback); // vertexCallback);
    glu.gluTessCallback(tobj, GLU.GLU_TESS_BEGIN, tessCallback); // beginCallback);
    glu.gluTessCallback(tobj, GLU.GLU_TESS_END, tessCallback); // endCallback);
    glu.gluTessCallback(tobj, GLU.GLU_TESS_ERROR, tessCallback); // errorCallback);
    glu.gluTessCallback(tobj, GLU.GLU_TESS_COMBINE, tessCallback); // combineCallback);

    /* smooth shaded, self-intersecting star */
    gl.glNewList(startList + 1, GL2.GL_COMPILE);
    gl.glShadeModel(GL2.GL_SMOOTH);
    glu.gluTessProperty(
        tobj, //
        GLU.GLU_TESS_WINDING_RULE, //
        GLU.GLU_TESS_WINDING_POSITIVE);
    glu.gluTessBeginPolygon(tobj, null);
    glu.gluTessBeginContour(tobj);
    glu.gluTessVertex(tobj, star[0], 0, star[0]);
    glu.gluTessVertex(tobj, star[1], 0, star[1]);
    glu.gluTessVertex(tobj, star[2], 0, star[2]);
    glu.gluTessVertex(tobj, star[3], 0, star[3]);
    glu.gluTessVertex(tobj, star[4], 0, star[4]);
    glu.gluTessEndContour(tobj);
    glu.gluTessEndPolygon(tobj);
    gl.glEndList();
    glu.gluDeleteTess(tobj);
  }
Esempio n. 13
0
  @Override
  public void display(GLAutoDrawable drawable) {
    GL2 gl2 = drawable.getGL().getGL2();
    GLU glu = GLU.createGLU();

    gl2.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);
    gl2.glEnable(GL2.GL_DEPTH_TEST);
    gl2.glDisable(GL2.GL_CULL_FACE);

    gl2.glMatrixMode(GL2.GL_PROJECTION);
    gl2.glLoadIdentity();
    glu.gluPerspective(60, drawable.getSurfaceWidth() / drawable.getSurfaceHeight(), 0.1f, 100);

    gl2.glMatrixMode(GL2.GL_MODELVIEW);
    gl2.glLoadIdentity();

    camera_.apply(gl2, glu);
    light_.apply(gl2, glu);

    terrain_.draw(gl2, glu);

    Runnable triangle =
        () -> {
          gl2.glBegin(GL2.GL_TRIANGLES);
          {
            gl2.glColor3f(1, 1, 1);
            gl2.glNormal3f(0, 0, 1);
            gl2.glVertex3f(0, 1, 0);
            gl2.glColor3f(1, 0, 0);
            gl2.glNormal3f(0, 0, 1);
            gl2.glVertex3f(-0.87f, -0.5f, 0);
            gl2.glColor3f(0, 0, 1);
            gl2.glNormal3f(0, 0, 1);
            gl2.glVertex3f(0.87f, -0.5f, 0);

            gl2.glColor3f(1, 1, 1);
            gl2.glNormal3f(0.71898836f, 0.4170133f, -0.5560177f);
            gl2.glVertex3f(0, 1, 0);
            gl2.glColor3f(0, 0, 1);
            gl2.glNormal3f(0.71898836f, 0.4170133f, -0.5560177f);
            gl2.glVertex3f(0.87f, -0.5f, 0);
            gl2.glColor3f(0, 1, 0);
            gl2.glNormal3f(0.71898836f, 0.4170133f, -0.5560177f);
            gl2.glVertex3f(0, 0, -0.75f);

            gl2.glColor3f(1, 0, 0);
            gl2.glNormal3f(-0.7189883f, 0.41701326f, -0.5560177f);
            gl2.glVertex3f(-0.87f, -0.5f, 0);
            gl2.glColor3f(1, 1, 1);
            gl2.glNormal3f(-0.7189883f, 0.41701326f, -0.5560177f);
            gl2.glVertex3f(0, 1, 0);
            gl2.glColor3f(0, 1, 0);
            gl2.glNormal3f(-0.7189883f, 0.41701326f, -0.5560177f);
            gl2.glVertex3f(0, 0, -0.75f);

            gl2.glColor3f(0, 0, 1);
            gl2.glNormal3f(0, -1.305f, -0.87f);
            gl2.glVertex3f(0.87f, -0.5f, 0);
            gl2.glColor3f(1, 0, 0);
            gl2.glNormal3f(0, -1.305f, -0.87f);
            gl2.glVertex3f(-0.87f, -0.5f, 0);
            gl2.glColor3f(0, 1, 0);
            gl2.glNormal3f(0, -1.305f, -0.87f);
            gl2.glVertex3f(0, 0, -0.75f);
          }
          gl2.glEnd();
        };

    gl2.glPushMatrix();
    {
      gl2.glPushMatrix();
      gl2.glTranslatef(0, 0, 0);
      gl2.glRotatef(angle__, 0, 1, 0);
      triangle.run();
      gl2.glPopMatrix();

      gl2.glPushMatrix();
      gl2.glTranslatef(0, 3.2f, 0);
      gl2.glRotatef(angle__ + 30, 0, 1, 0);
      triangle.run();
      gl2.glPopMatrix();

      gl2.glPushMatrix();
      gl2.glTranslatef(3.2f, 0, 0);
      gl2.glRotatef(angle__ + 60, 0, 1, 0);
      triangle.run();
      gl2.glPopMatrix();
    }
    gl2.glPopMatrix();
    angle__ += 1;

    gl2.glPushMatrix();
    gl2.glTranslatef(0.05f, -1.5f, 5);
    gl2.glScalef(0.05f, 0.05f, 0.05f);
    for (Face face : glock3__.faces) {
      gl2.glBegin(GL2.GL_POLYGON);
      for (FaceVertex vertex : face.vertices) {
        gl2.glColor3f(1, 1, 1);
        gl2.glNormal3f(vertex.n.x, vertex.n.y, vertex.n.z);
        gl2.glVertex3f(vertex.v.x, vertex.v.y, vertex.v.z);
      }
      gl2.glEnd();
    }
    gl2.glPopMatrix();
  }
Esempio n. 14
0
  private TessOutput tesselateString(String s) {
    GlyphVector gv = _font.createGlyphVector(_frc, s);

    Shape shape = gv.getOutline();
    //
    AffineTransform at = new AffineTransform();
    at.scale(1, -1);
    PathIterator pIt = shape.getPathIterator(at, _font.getSize() / 200.0);

    // Create a GLU tesselator
    GLUtessellator tess = GLU.gluNewTess();
    CharTesselator tessAdapt = new CharTesselator();

    GLU.gluTessCallback(tess, GLU.GLU_TESS_VERTEX, tessAdapt);
    GLU.gluTessCallback(tess, GLU.GLU_TESS_BEGIN, tessAdapt);
    GLU.gluTessCallback(tess, GLU.GLU_TESS_END, tessAdapt);
    GLU.gluTessCallback(tess, GLU.GLU_TESS_COMBINE, tessAdapt);
    GLU.gluTessCallback(tess, GLU.GLU_TESS_ERROR, tessAdapt);

    int winding = pIt.getWindingRule();

    if (winding == PathIterator.WIND_EVEN_ODD)
      GLU.gluTessProperty(tess, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_ODD);
    else if (winding == PathIterator.WIND_NON_ZERO)
      GLU.gluTessProperty(tess, GLU.GLU_TESS_WINDING_RULE, GLU.GLU_TESS_WINDING_NONZERO);
    else assert (false); // PathIterator should only return these two winding rules

    GLU.gluBeginPolygon(tess);
    GLU.gluTessNormal(tess, 0, 0, 1);
    double[] first = null;
    double[] v;
    while (!pIt.isDone()) {
      v = new double[3];
      int type = pIt.currentSegment(v);
      v[2] = 0.0;
      if (type == PathIterator.SEG_MOVETO) {
        first = v;
        GLU.gluNextContour(tess, GLU.GLU_UNKNOWN);
        GLU.gluTessVertex(tess, v, 0, v);
      } else if (type == PathIterator.SEG_LINETO) {
        GLU.gluTessVertex(tess, v, 0, v);
      } else if (type == PathIterator.SEG_CLOSE) {
        assert (first != null); // If this is true, there is an error in the AWT path iterator
        GLU.gluTessVertex(tess, first, 0, first);
        first = null;
      } else {
        assert (false); // The path itertor should not return other path types here
      }
      pIt.next();
    }
    GLU.gluEndPolygon(tess);

    int numVerts = tessAdapt.getVerts().size();
    double[] verts = new double[numVerts];
    int count = 0;
    for (double d : tessAdapt.getVerts()) {
      verts[count++] = d;
    }

    TessOutput ret = new TessOutput();
    ret.verts = verts;
    ret.bounds = gv.getVisualBounds();

    ret.advances = new double[s.length()];
    for (int i = 0; i < s.length(); ++i) {
      ret.advances[i] = gv.getGlyphMetrics(i).getAdvance();
    }
    return ret;
  }
Esempio n. 15
0
 @Override
 public void error(int errNum) {
   @SuppressWarnings("unused")
   String errorString = GLU.createGLU().gluErrorString(errNum);
   assert (false); // TODO: Handle this properly?
 }