Пример #1
0
 public void glMultMatrixf(float[] m, int m_offset) {
   if (matrixMode == GL_MODELVIEW) {
     FloatUtil.multMatrixf(matrixMv, m, m_offset, matrixMv);
     modified |= DIRTY_MODELVIEW;
   } else if (matrixMode == GL_PROJECTION) {
     FloatUtil.multMatrixf(matrixP, m, m_offset, matrixP);
     modified |= DIRTY_PROJECTION;
   } else if (matrixMode == GL.GL_TEXTURE) {
     FloatUtil.multMatrixf(matrixTex, m, m_offset, matrixTex);
     modified |= DIRTY_TEXTURE;
   }
 }
Пример #2
0
 public final void glMultMatrixf(final FloatBuffer m) {
   if (matrixMode == GL_MODELVIEW) {
     FloatUtil.multMatrixf(matrixMv, m, matrixMv);
     modified |= DIRTY_MODELVIEW;
   } else if (matrixMode == GL_PROJECTION) {
     FloatUtil.multMatrixf(matrixP, m, matrixP);
     modified |= DIRTY_PROJECTION;
   } else if (matrixMode == GL.GL_TEXTURE) {
     FloatUtil.multMatrixf(matrixTex, m, matrixTex);
     modified |= DIRTY_TEXTURE;
   }
 }
Пример #3
0
  public final void glRotatef(final float angdeg, float x, float y, float z) {
    final float angrad = angdeg * (float) Math.PI / 180.0f;
    final float c = (float) Math.cos(angrad);
    final float ic = 1.0f - c;
    final float s = (float) Math.sin(angrad);

    vec3f[0] = x;
    vec3f[1] = y;
    vec3f[2] = z;
    FloatUtil.normalize(vec3f);
    x = vec3f[0];
    y = vec3f[1];
    z = vec3f[2];

    // Rotation matrix:
    //      xx(1-c)+c  xy(1-c)+zs xz(1-c)-ys 0
    //      xy(1-c)-zs yy(1-c)+c  yz(1-c)+xs 0
    //      xz(1-c)+ys yz(1-c)-xs zz(1-c)+c  0
    //      0          0          0          1
    final float xy = x * y;
    final float xz = x * z;
    final float xs = x * s;
    final float ys = y * s;
    final float yz = y * z;
    final float zs = z * s;
    matrixRot[0 * 4 + 0] = x * x * ic + c;
    matrixRot[0 * 4 + 1] = xy * ic + zs;
    matrixRot[0 * 4 + 2] = xz * ic - ys;

    matrixRot[1 * 4 + 0] = xy * ic - zs;
    matrixRot[1 * 4 + 1] = y * y * ic + c;
    matrixRot[1 * 4 + 2] = yz * ic + xs;

    matrixRot[2 * 4 + 0] = xz * ic + ys;
    matrixRot[2 * 4 + 1] = yz * ic - xs;
    matrixRot[2 * 4 + 2] = z * z * ic + c;

    glMultMatrixf(matrixRot, 0);
  }
Пример #4
0
  /**
   * Creates an instance of PMVMatrix.
   *
   * @param useBackingArray <code>true</code> for non direct NIO Buffers with guaranteed backing
   *     array, which allows faster access in Java computation.
   *     <p><code>false</code> for direct NIO buffers w/o a guaranteed backing array. In most Java
   *     implementations, direct NIO buffers have no backing array and hence the Java computation
   *     will be throttled down by direct IO get/put operations.
   *     <p>Depending on the application, ie. whether the Java computation or JNI invocation and
   *     hence native data transfer part is heavier, this flag shall be set to <code>true</code> or
   *     <code>false</code>.
   */
  public PMVMatrix(boolean useBackingArray) {
    this.usesBackingArray = useBackingArray;

    // I    Identity
    // T    Texture
    // P    Projection
    // Mv   ModelView
    // Mvi  Modelview-Inverse
    // Mvit Modelview-Inverse-Transpose
    if (useBackingArray) {
      matrixBufferArray = new float[6 * 16 + ProjectFloat.getRequiredFloatBufferSize()];
      matrixBuffer = null;
    } else {
      matrixBufferArray = null;
      matrixBuffer =
          Buffers.newDirectByteBuffer(
              (6 * 16 + ProjectFloat.getRequiredFloatBufferSize()) * Buffers.SIZEOF_FLOAT);
      matrixBuffer.mark();
    }

    matrixIdent = Buffers.slice2Float(matrixBuffer, matrixBufferArray, 0 * 16, 1 * 16); //  I
    matrixTex = Buffers.slice2Float(matrixBuffer, matrixBufferArray, 1 * 16, 1 * 16); //      T
    matrixPMvMvit =
        Buffers.slice2Float(
            matrixBuffer,
            matrixBufferArray,
            2 * 16,
            4 * 16); //          P  + Mv + Mvi + Mvit
    matrixPMvMvi =
        Buffers.slice2Float(
            matrixBuffer, matrixBufferArray, 2 * 16, 3 * 16); //          P  + Mv + Mvi
    matrixPMv =
        Buffers.slice2Float(matrixBuffer, matrixBufferArray, 2 * 16, 2 * 16); //          P  + Mv
    matrixP = Buffers.slice2Float(matrixBuffer, matrixBufferArray, 2 * 16, 1 * 16); //          P
    matrixMv =
        Buffers.slice2Float(matrixBuffer, matrixBufferArray, 3 * 16, 1 * 16); //               Mv
    matrixMvi =
        Buffers.slice2Float(
            matrixBuffer, matrixBufferArray, 4 * 16, 1 * 16); //                    Mvi
    matrixMvit =
        Buffers.slice2Float(
            matrixBuffer, matrixBufferArray, 5 * 16, 1 * 16); //                          Mvit

    projectFloat = new ProjectFloat(matrixBuffer, matrixBufferArray, 6 * 16);

    if (null != matrixBuffer) {
      matrixBuffer.reset();
    }
    FloatUtil.makeIdentityf(matrixIdent);

    vec3f = new float[3];
    matrixMult = new float[16];
    matrixTrans = new float[16];
    matrixRot = new float[16];
    matrixScale = new float[16];
    matrixOrtho = new float[16];
    matrixFrustum = new float[16];
    FloatUtil.makeIdentityf(matrixTrans, 0);
    FloatUtil.makeIdentityf(matrixRot, 0);
    FloatUtil.makeIdentityf(matrixScale, 0);
    FloatUtil.makeIdentityf(matrixOrtho, 0);
    FloatUtil.makeZero(matrixFrustum, 0);

    matrixPStack = new ArrayList<float[]>();
    matrixMvStack = new ArrayList<float[]>();

    // default values and mode
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glMatrixMode(GL.GL_TEXTURE);
    glLoadIdentity();
    setDirty();
    update();
  }