Beispiel #1
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());
 }
Beispiel #2
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);
  }
Beispiel #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;
 }
Beispiel #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;
 }