Example #1
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();
  }
Example #2
0
 /**
  * Build a 4x4 matrix transform, according to the gluLookAt function.
  *
  * @param aEye
  * @param aLookAt
  * @param aUp
  */
 public void buildLookAtMatrix(JVector3d aEye, JVector3d aLookAt, JVector3d aUp) {
   buildLookAtMatrix(
       aEye.getX(),
       aEye.getY(),
       aEye.getZ(),
       aLookAt.getX(),
       aLookAt.getY(),
       aLookAt.getZ(),
       aUp.getX(),
       aUp.getY(),
       aUp.getZ());
 }
Example #3
0
 /**
  * Creates OpenGL translation matrix from a position vector passed as parameter.
  *
  * @param aPos
  */
 public void set(final JVector3d aPos) {
   m[0][0] = 1.0;
   m[0][1] = 0.0;
   m[0][2] = 0.0;
   m[0][3] = 0.0;
   m[1][0] = 0.0;
   m[1][1] = 1.0;
   m[1][2] = 0.0;
   m[1][3] = 0.0;
   m[2][0] = 0.0;
   m[2][1] = 0.0;
   m[2][2] = 1.0;
   m[2][3] = 0.0;
   m[3][0] = aPos.getX();
   m[3][1] = aPos.getY();
   m[3][2] = aPos.getZ();
   m[3][3] = 1.0;
 }
Example #4
0
 /**
  * Create an OpenGL translation matrix from a 3-vector and a 3x3 matrix passed as a parameter.
  *
  * @param aPos
  * @param aRot
  */
 public void set(final JVector3d aPos, final JMatrix3d aRot) {
   m[0][0] = aRot.m[0][0];
   m[0][1] = aRot.m[1][0];
   m[0][2] = aRot.m[2][0];
   m[0][3] = 0.0;
   m[1][0] = aRot.m[0][1];
   m[1][1] = aRot.m[1][1];
   m[1][2] = aRot.m[2][1];
   m[1][3] = 0.0;
   m[2][0] = aRot.m[0][2];
   m[2][1] = aRot.m[1][2];
   m[2][2] = aRot.m[2][2];
   m[2][3] = 0.0;
   m[3][0] = aPos.getX();
   m[3][1] = aPos.getY();
   m[3][2] = aPos.getZ();
   m[3][3] = 1.0;
 }
Example #5
0
  public static void jLookAt(GL2 gl, JVector3d eye, JVector3d at, JVector3d up) {
    // Define our look vector (z axis)
    JVector3d look = at.operatorSub(eye);
    look.normalize();

    // Define our new x axis
    JVector3d xaxis = JMaths.jCross(look, up);
    xaxis.normalize();

    // Define our new y axis as the cross of the x and z axes
    JVector3d upv = JMaths.jCross(xaxis, look);

    // Turn around the z axis
    look.mul(-1.0);

    // Put it all into a GL-friendly matrix
    double[] dm = new double[16];
    dm[0] = xaxis.getX();
    dm[1] = xaxis.getY();
    dm[2] = xaxis.getZ();
    dm[3] = 0.f;
    dm[4] = upv.getX();
    dm[5] = upv.getY();
    dm[6] = upv.getZ();
    dm[7] = 0.f;
    dm[8] = look.getX();
    dm[9] = look.getY();
    dm[10] = look.getZ();
    dm[11] = 0.f;
    dm[12] = eye.getX();
    dm[13] = eye.getY();
    dm[14] = eye.getZ();
    dm[15] = 1.f;

    // Push it onto the matrix stack
    gl.glMultMatrixd(dm, 0);
  }