Пример #1
0
  public boolean Draw(Matrix4 projectionMatrix, Matrix4 viewMatrix) {
    GLES20.glUseProgram(programID);

    Matrix4 mvp =
        Matrix4.Multiply(
            projectionMatrix, Matrix4.Multiply(viewMatrix, parent.transform.transformMatrix));

    float[] mvpArray = mvp.GetOneDimensionalArray();

    GLES20.glUniformMatrix4fv(mvpLocation, 1, false, mvpArray, 0);

    GLES20.glUniform1f(opacityLocation, opacity);

    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureID);

    GLES20.glUniform1i(textureSamplerLocation, 0);

    // Log.i(DEBUG_TAG,"Enabling " + vertexArrayList.size() + " attribs");

    for (GLVertexArrayObject element : vertexArrayList) {
      GLES20.glEnableVertexAttribArray(element.attributeNumber);
    }

    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, vertexArraySize);

    for (GLVertexArrayObject element : vertexArrayList) {
      GLES20.glDisableVertexAttribArray(element.attributeNumber);
    }
    return true;
  }
Пример #2
0
 public Matrix4 getProjectionMatrix() {
   if (renderViewEntity != null) {
     return projection.mul(
         renderViewEntity
             .getRotation()
             .conjugate()
             .toRotationMatrix()
             .mul(
                 new Matrix4()
                     .initTranslation(
                         -renderViewEntity.getPos().getX() - 0.5f,
                         -renderViewEntity.getPos().getY() - renderViewEntity.getEyeOffset(),
                         -renderViewEntity.getPos().getZ() - 0.5f)));
   }
   return projection;
 }
Пример #3
0
  /**
   * Updates the clipping plane's based on the given inverse combined projection and view matrix,
   * e.g. from an {@link OrthographicCamera} or {@link PerspectiveCamera}.
   *
   * @param inverseProjectionView the combined projection and view matrices.
   */
  public void update(Matrix4 inverseProjectionView) {
    System.arraycopy(
        clipSpacePlanePointsArray, 0, planePointsArray, 0, clipSpacePlanePointsArray.length);
    Matrix4.prj(inverseProjectionView.val, planePointsArray, 0, 8, 3);
    for (int i = 0, j = 0; i < 8; i++) {
      Vector3 v = planePoints[i];
      v.x = planePointsArray[j++];
      v.y = planePointsArray[j++];
      v.z = planePointsArray[j++];
    }

    planes[0].set(planePoints[1], planePoints[0], planePoints[2]);
    planes[1].set(planePoints[4], planePoints[5], planePoints[7]);
    planes[2].set(planePoints[0], planePoints[4], planePoints[3]);
    planes[3].set(planePoints[5], planePoints[1], planePoints[6]);
    planes[4].set(planePoints[2], planePoints[3], planePoints[6]);
    planes[5].set(planePoints[4], planePoints[0], planePoints[1]);
  }
 public boolean equals(final Matrix4 m2) {
   m2.toFloatArray(mTmp);
   if (m[0] != mTmp[0]
       || m[1] != mTmp[1]
       || m[2] != mTmp[2]
       || m[3] != mTmp[3]
       || m[4] != mTmp[4]
       || m[5] != mTmp[5]
       || m[6] != mTmp[6]
       || m[7] != mTmp[7]
       || m[8] != mTmp[8]
       || m[9] != mTmp[9]
       || m[10] != mTmp[10]
       || m[11] != mTmp[11]
       || m[12] != mTmp[12]
       || m[13] != mTmp[13]
       || m[14] != mTmp[14]
       || m[15] != mTmp[15]) return false;
   return true;
 }
 public Matrix4 subtract(final Matrix4 m2) {
   m2.toFloatArray(mTmp);
   return new Matrix4(
       m[0] - mTmp[0],
       m[1] - mTmp[1],
       m[2] - mTmp[2],
       m[3] - mTmp[3],
       m[4] - mTmp[4],
       m[5] - mTmp[5],
       m[6] - mTmp[6],
       m[7] - mTmp[7],
       m[8] - mTmp[8],
       m[9] - mTmp[9],
       m[10] - mTmp[10],
       m[11] - mTmp[11],
       m[12] - mTmp[12],
       m[13] - mTmp[13],
       m[14] - mTmp[14],
       m[15] - mTmp[15]);
 }
 public Matrix4 add(Matrix4 m2) {
   m2.toFloatArray(mTmp);
   return new Matrix4(
       m[0] + mTmp[0],
       m[1] + mTmp[1],
       m[2] + mTmp[2],
       m[3] + mTmp[3],
       m[4] + mTmp[4],
       m[5] + mTmp[5],
       m[6] + mTmp[6],
       m[7] + mTmp[7],
       m[8] + mTmp[8],
       m[9] + mTmp[9],
       m[10] + mTmp[10],
       m[11] + mTmp[11],
       m[12] + mTmp[12],
       m[13] + mTmp[13],
       m[14] + mTmp[14],
       m[15] + mTmp[15]);
 }
 public Matrix4 multiply(final Matrix4 m2) {
   m2.toFloatArray(mTmp);
   return new Matrix4(
       m[0] * mTmp[0] + m[1] * mTmp[4] + m[2] * mTmp[8] + m[3] * mTmp[12],
       m[0] * mTmp[1] + m[1] * mTmp[5] + m[2] * mTmp[9] + m[3] * mTmp[13],
       m[0] * mTmp[2] + m[1] * mTmp[6] + m[2] * mTmp[10] + m[3] * mTmp[14],
       m[0] * mTmp[3] + m[1] * mTmp[7] + m[2] * mTmp[11] + m[3] * mTmp[15],
       m[4] * mTmp[0] + m[5] * mTmp[4] + m[6] * mTmp[8] + m[7] * mTmp[12],
       m[4] * mTmp[1] + m[5] * mTmp[5] + m[6] * mTmp[9] + m[7] * mTmp[13],
       m[4] * mTmp[2] + m[5] * mTmp[6] + m[6] * mTmp[10] + m[7] * mTmp[14],
       m[4] * mTmp[3] + m[5] * mTmp[7] + m[6] * mTmp[11] + m[7] * mTmp[15],
       m[8] * mTmp[0] + m[9] * mTmp[4] + m[10] * mTmp[8] + m[11] * mTmp[12],
       m[8] * mTmp[1] + m[9] * mTmp[5] + m[10] * mTmp[9] + m[11] * mTmp[13],
       m[8] * mTmp[2] + m[9] * mTmp[6] + m[10] * mTmp[10] + m[11] * mTmp[14],
       m[8] * mTmp[3] + m[9] * mTmp[7] + m[10] * mTmp[11] + m[11] * mTmp[15],
       m[12] * mTmp[0] + m[13] * mTmp[4] + m[14] * mTmp[8] + m[15] * mTmp[12],
       m[12] * mTmp[1] + m[13] * mTmp[5] + m[14] * mTmp[9] + m[15] * mTmp[13],
       m[12] * mTmp[2] + m[13] * mTmp[6] + m[14] * mTmp[10] + m[15] * mTmp[14],
       m[12] * mTmp[3] + m[13] * mTmp[7] + m[14] * mTmp[11] + m[15] * mTmp[15]);
 }
Пример #8
0
 /**
  * Rotates this vector by the given angle in radians around the given axis.
  *
  * @param axis the axis
  * @param radians the angle in radians
  * @return This vector for chaining
  */
 public Vector3 rotateRad(final Vector3 axis, float radians) {
   tmpMat.setToRotationRad(axis, radians);
   return this.mul(tmpMat);
 }
Пример #9
0
 /**
  * Rotates this vector by the given angle in degrees around the given axis.
  *
  * @param axis the axis
  * @param degrees the angle in degrees
  * @return This vector for chaining
  */
 public Vector3 rotate(final Vector3 axis, float degrees) {
   tmpMat.setToRotation(axis, degrees);
   return this.mul(tmpMat);
 }
Пример #10
0
 /**
  * Rotates this vector by the given angle in radians around the given axis.
  *
  * @param radians the angle in radians
  * @param axisX the x-component of the axis
  * @param axisY the y-component of the axis
  * @param axisZ the z-component of the axis
  * @return This vector for chaining
  */
 public Vector3 rotateRad(float radians, float axisX, float axisY, float axisZ) {
   return this.mul(tmpMat.setToRotationRad(axisX, axisY, axisZ, radians));
 }
Пример #11
0
 /**
  * Rotates this vector by the given angle in degrees around the given axis.
  *
  * @param degrees the angle in degrees
  * @param axisX the x-component of the axis
  * @param axisY the y-component of the axis
  * @param axisZ the z-component of the axis
  * @return This vector for chaining
  */
 public Vector3 rotate(float degrees, float axisX, float axisY, float axisZ) {
   return this.mul(tmpMat.setToRotation(axisX, axisY, axisZ, degrees));
 }
 public Matrix4(Matrix4 other) {
   this();
   other.toFloatArray(mTmp);
   set(mTmp);
 }
Пример #13
0
 /**
  * Rotates this vector by the given angle around the given axis.
  *
  * @param axis
  * @param angle the angle
  * @return This vector for chaining
  */
 public Vector3 rotate(final Vector3 axis, float angle) {
   tmpMat.setToRotation(axis, angle);
   return this.mul(tmpMat);
 }
Пример #14
0
 /**
  * Rotates this vector by the given angle around the given axis.
  *
  * @param axisX the x-component of the axis
  * @param axisY the y-component of the axis
  * @param axisZ the z-component of the axis
  * @return This vector for chaining
  */
 public Vector3 rotate(float angle, float axisX, float axisY, float axisZ) {
   return this.mul(tmpMat.setToRotation(axisX, axisY, axisZ, angle));
 }
Пример #15
0
 public Vector3 unprojectVector(Vector3 vector, Camera camera) {
   camera.projectionMatrix.getInverse(camera.projectionMatrix);
   viewProjectionMatrix.multiplyMatrices(camera.matrixWorld, camera.projectionMatrixInverse);
   return vector.applyProjection(viewProjectionMatrix);
 }