Example #1
0
  /**
   * レンダリング環境のセットアップ
   *
   * @param gcon
   */
  public void begin(GraphicContext gcon) {
    GraphicContextJogl gc = (GraphicContextJogl) gcon;
    GL gl = gc.getGL();

    if ((state_ & CLEAR) == CLEAR) {
      gl.glClearColor(r_, g_, b_, 1.0f); // カラープレーン初期値
      gl.glClearDepth(1.0); // デプスバッファの初期値
      gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
    }

    gl.glEnable(GL.GL_DEPTH_TEST); // デプスバッファをイネーブル
    gl.glDepthFunc(GL.GL_LESS); // デプスバッファの計算法指定
    gl.glDepthMask(true); // デプスバッファをリードライト
    gl.glEnable(GL.GL_LIGHTING);

    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glLoadIdentity();
    float right = (float) (near_ * Math.tan(fovx_ / 2));
    float left = -right;
    float top = right * aspect_;
    float bottom = -top;
    gl.glFrustum(left, right, bottom, top, near_, far_);

    buildViewMatrix();

    gc.setViewMatrix(viewMatrix_);
  }
Example #2
0
  // Method for handling window resizing
  public void projection(GL gl, int width, int height) {
    gl.glViewport(0, 0, width, height);

    double aspect = (double) width / height;
    double l, r, b, t, n;
    // Move near plane closer, but also shrink frustum so that
    // field-of-view stays the same -- this way not much stuff
    // gets clipped
    double zoom = 10;

    // Preserve aspect ratio
    if (aspect > 1) {
      r = aspect / zoom;
      t = 1 / zoom;
    } else {
      r = 1 / zoom;
      t = 1 / (zoom * aspect);
    }
    // Window has (0,0) in center
    l = -r;
    b = -t;

    // Set near plane location
    // (making this smaller reduces the field-of-view)
    n = 2;

    // Set the world projection
    gl.glMatrixMode(GL.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustum(l, r, b, t, n / zoom, 500);
    gl.glMatrixMode(GL.GL_MODELVIEW);
  }
Example #3
0
 public void reshape(GLAutoDrawable gLDrawable, int x, int y, int width, int height) {
   GL gl = gLDrawable.getGL();
   float h = (float) width / (float) height;
   gl.glMatrixMode(GL.GL_PROJECTION);
   gl.glLoadIdentity();
   gl.glFrustum(-h, h, -1, 1, 1, 600);
   gl.glMatrixMode(GL.GL_MODELVIEW);
   gl.glLoadIdentity();
   gl.glTranslatef(0.0f, 0.0f, -6f);
 }
Example #4
0
  public final void reshape(
      final GLAutoDrawable drawable, final int x, final int y, final int width, final int height) {
    Debug.print();
    final GL gl = drawable.getGL();

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

    gl.glFrustum(
        -1.0f, 1.0f, -1.0f, 1.0f, this.camera.getNearZClipping(), this.camera.getFarZClipping());

    gl.glViewport(x, y, width, height);
  }
Example #5
0
  /**
   * Draws the five sides of the hemicube into the provided drawable
   *
   * @param drawable
   * @param which
   * @param near
   * @param far
   * @param bCollect
   */
  public void drawHemiCube(
      GLAutoDrawable drawable, int which, double near, double far, boolean bCollect) {

    // TODO - PART 1 - DRAW HEMICUBE!

    GL gl = drawable.getGL();
    GLU glu = new GLU();

    /* Return the face based on which parameter */
    int[] vertices = scene.getObject().getFace(which);

    /* Find the center of the face */
    /* Center of the face is the average of the three vertices */

    /* Using returned list of vertex indices, find the vertices
     * corresponding to a particular face */
    Vertex v1 = scene.getObject().vertexList.get(vertices[0]);
    Vertex v2 = scene.getObject().vertexList.get(vertices[1]);
    Vertex v3 = scene.getObject().vertexList.get(vertices[2]);

    /* Locate center of face */
    /* Average of three vertices */
    Point3d centerPoint = new Point3d();
    centerPoint = new Point3d(v1.p);
    centerPoint.add(v2.p);
    centerPoint.add(v3.p);
    centerPoint.scale(0.33333);

    /* Set up camera frame */

    /* --- Surface normal --- */
    /* Declare points of vertex for face */
    Point3d p1 = new Point3d(v1.p);
    Point3d p2 = new Point3d(v2.p);
    Point3d p3 = new Point3d(v3.p);

    /* Declare vector u as p2-p1 */
    Point3d uVec = new Point3d(p2);
    uVec.sub(p1);
    Vector3d u = new Vector3d(uVec);

    /* Declare vector v as p3-p1 */
    Point3d vVec = new Point3d(p3);
    vVec.sub(p1);
    Vector3d v = new Vector3d(vVec);

    /* Make normal vector */
    Vector3d norm = new Vector3d();
    norm.cross(u, v);

    /* --- Vectors Orthonormal to Normal --- */
    Point3d vec1pt = new Point3d(p1);
    vec1pt.sub(p2);
    Vector3d vec1 = new Vector3d(vec1pt);
    vec1.cross(vec1, norm); // Cross surface normal with vec1 to get orthogonal vector

    Vector3d vec2 = new Vector3d();
    vec2.cross(
        norm,
        vec1); // Cross product of surface normal with new vector vec1 to get 2nd orthogonal vector

    /* Make unit vectors */
    norm.normalize();
    vec1.normalize();
    vec2.normalize();

    /* Set up the five different frustums, and stitch together using viewPort */
    /* Viewport to set up the view of the scene */

    /* ----- FRONT FACE ----- */
    gl.glPushMatrix();
    gl.glViewport(0, 0, drawable.getWidth(), drawable.getHeight() / 3);

    /* Set up frustums for this face */

    gl.glMatrixMode(gl.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustum(-near, near, -near, near, near, far);

    /* Position camera at center of specified patch (which) */
    gl.glMatrixMode(gl.GL_MODELVIEW);
    gl.glLoadIdentity();
    glu.gluLookAt(
        centerPoint.x,
        centerPoint.y,
        centerPoint.z,
        centerPoint.x + norm.x,
        centerPoint.y + norm.y,
        centerPoint.z + norm.z,
        centerPoint.x + vec1.x,
        centerPoint.y + vec1.y,
        centerPoint.z + vec1.z);

    /* Draw the frustum to screen */
    draw(drawable, scene.drawStyle.IDENT);
    gl.glPopMatrix();

    /* ----- BOTTOM FACE ----- */
    gl.glPushMatrix();
    gl.glViewport(0, drawable.getHeight() / 3, drawable.getWidth(), drawable.getHeight() / 6);

    gl.glMatrixMode(gl.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustum(-near, near, 0, near, near, far);

    /* Position camera at center of specified patch (which) */
    gl.glMatrixMode(gl.GL_MODELVIEW);
    gl.glLoadIdentity();
    glu.gluLookAt(
        centerPoint.x,
        centerPoint.y,
        centerPoint.z,
        centerPoint.x + (-vec1.x),
        centerPoint.y + (-vec1.y),
        centerPoint.z + (-vec1.z),
        centerPoint.x + norm.x,
        centerPoint.y + norm.y,
        centerPoint.z + norm.z);

    /* Draw the frustum to screen */
    draw(drawable, scene.drawStyle.IDENT);
    gl.glPopMatrix();

    /* ----- TOP FACE ----- */
    gl.glPushMatrix();
    gl.glViewport(
        0,
        (drawable.getHeight() / 3) + (drawable.getHeight() / 6),
        drawable.getWidth(),
        drawable.getHeight() / 6);

    gl.glMatrixMode(gl.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustum(-near, near, -near, 0, near, far);

    /* Position camera at center of specified patch (which) */
    gl.glMatrixMode(gl.GL_MODELVIEW);
    gl.glLoadIdentity();
    glu.gluLookAt(
        centerPoint.x,
        centerPoint.y,
        centerPoint.z,
        centerPoint.x + vec1.x,
        centerPoint.y + vec1.y,
        centerPoint.z + vec1.z,
        centerPoint.x - norm.x,
        centerPoint.y - norm.y,
        centerPoint.z - norm.z);

    /* Draw the frustum to screen */
    draw(drawable, scene.drawStyle.IDENT);
    gl.glPopMatrix();

    /* ----- LEFT FACE ----- */
    gl.glPushMatrix();
    gl.glViewport(
        0,
        (drawable.getHeight() / 3) + 2 * (drawable.getHeight() / 6),
        drawable.getWidth(),
        drawable.getHeight() / 6);

    gl.glMatrixMode(gl.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustum(0, near, -near, near, near, far);

    /* Position camera at center of specified patch (which) */
    gl.glMatrixMode(gl.GL_MODELVIEW);
    gl.glLoadIdentity();
    glu.gluLookAt(
        centerPoint.x,
        centerPoint.y,
        centerPoint.z,
        centerPoint.x + vec2.x,
        centerPoint.y + vec2.y,
        centerPoint.z + vec2.z,
        centerPoint.x + vec1.x,
        centerPoint.y + vec1.y,
        centerPoint.z + vec1.z);

    /* Draw the frustum to screen */
    draw(drawable, scene.drawStyle.IDENT);
    gl.glPopMatrix();

    /* ----- RIGHT FACE ----- */
    gl.glPushMatrix();
    gl.glViewport(
        0,
        (drawable.getHeight() / 3) + 3 * (drawable.getHeight() / 6),
        drawable.getWidth(),
        drawable.getHeight() / 6);

    gl.glMatrixMode(gl.GL_PROJECTION);
    gl.glLoadIdentity();
    gl.glFrustum(near, 0, -near, near, near, far);

    /* Position camera at center of specified patch (which) */
    gl.glMatrixMode(gl.GL_MODELVIEW);
    gl.glLoadIdentity();
    glu.gluLookAt(
        centerPoint.x,
        centerPoint.y,
        centerPoint.z,
        centerPoint.x + (-vec2.x),
        centerPoint.y + (-vec2.y),
        centerPoint.z + (-vec2.z),
        centerPoint.x + vec1.x,
        centerPoint.y + vec1.y,
        centerPoint.z + vec1.z);

    /* Draw the frustum to screen */
    draw(drawable, scene.drawStyle.IDENT);
    gl.glPopMatrix();

    /* ---- End Frustums ---- */

    // if collecting the form factors, then read back and process the data
    if (bCollect) {
      gl.glFlush();
      gl.glFinish();
      gl.glReadPixels(
          0, 0, divisions * 2, divisions * 6, GL.GL_RGBA, GL.GL_UNSIGNED_BYTE, pixelDataBuffer);
      collectData(which);
    }
  }