/** Draws a cube. */
  private void drawCube() {
    // Pass in the position information
    mCubePositions.position(0);
    GLES20.glVertexAttribPointer(
        mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false, 0, mCubePositions);

    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // Pass in the color information
    mCubeColors.position(0);
    GLES20.glVertexAttribPointer(
        mColorHandle, mColorDataSize, GLES20.GL_FLOAT, false, 0, mCubeColors);

    GLES20.glEnableVertexAttribArray(mColorHandle);

    // Pass in the normal information
    mCubeNormals.position(0);
    GLES20.glVertexAttribPointer(
        mNormalHandle, mNormalDataSize, GLES20.GL_FLOAT, false, 0, mCubeNormals);

    GLES20.glEnableVertexAttribArray(mNormalHandle);

    // Pass in the texture coordinate information
    mCubeTextureCoordinates.position(0);
    GLES20.glVertexAttribPointer(
        mTextureCoordinateHandle,
        mTextureCoordinateDataSize,
        GLES20.GL_FLOAT,
        false,
        0,
        mCubeTextureCoordinates);

    GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);

    // This multiplies the view matrix by the model matrix, and stores the result in the MVP matrix
    // (which currently contains model * view).
    Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);

    // Pass in the modelview matrix.
    GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 0);

    // This multiplies the modelview matrix by the projection matrix, and stores the result in the
    // MVP matrix
    // (which now contains model * view * projection).
    Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);

    // Pass in the combined matrix.
    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);

    // Pass in the light position in eye space.
    GLES20.glUniform3f(
        mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]);

    // Draw the cube.
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, 36);
  }
示例#2
0
  private void renderLines() {
    if (phenixLineProgram != null) {
      if (!phenixLineProgram.use()) {
        return;
      }

      float angle =
          360.0f * getTimeDeltaByScale((long) (1 * 50000L / speedFactor / rotationSpeedFactor));
      Matrix.setRotateM(M_matrix, 0, angle, 0, 0, 1.0f);

      Matrix.multiplyMM(MVP_matrix, 0, V_matrix, 0, M_matrix, 0);
      Matrix.multiplyMM(MVP_matrix, 0, P_matrix, 0, MVP_matrix, 0);

      float delta = getTimeDeltaByScale((long) (1 * 25000L / speedFactor));

      lineVertices.bind(phenixLineProgram, "aPosition", null);

      GLES20.glUniformMatrix4fv(
          phenixLineProgram.getUniformLocation("uMVPMatrix"), 1, false, MVP_matrix, 0);

      GLES20.glUniform1f(phenixLineProgram.getUniformLocation("uDelta"), delta);
      GLES20.glUniform1f(
          phenixLineProgram.getUniformLocation("uBrightness"), brightness * brightnessFactor);
      GLES20.glUniform3f(
          phenixLineProgram.getUniformLocation("uColor"),
          linesColorRed,
          linesColorGreen,
          linesColorBlue);

      GLES20.glEnable(GLES20.GL_BLEND);
      GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE);
      GLES20.glLineWidth(lineWidth * lineWidthFactor);

      lineVertices.draw(GLES20.GL_LINES, 0, MOVING_LINE_COUNT);

      GLES20.glUniform1f(phenixLineProgram.getUniformLocation("uDelta"), 0.0f);

      lineVertices.draw(GLES20.GL_LINES, MOVING_LINE_COUNT, STALE_LINE_COUNT);

      GLES20.glDisable(GLES20.GL_BLEND);

      lineVertices.unbind(phenixLineProgram, "aPosition", null);
    }
  }
示例#3
0
 @Override
 public void glUniform3f(int location, float x, float y, float z) {
   GLES20.glUniform3f(location, x, y, z);
 }
示例#4
0
  private void drawPlane(
      final FloatBuffer aPlaneBuffer,
      final FloatBuffer aColorBuffer,
      final FloatBuffer aNormalBuffer,
      final FloatBuffer aTextureBuffer) {
    // Pass in the position information
    aPlaneBuffer.position(0);
    GLES20.glVertexAttribPointer(
        mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false, 0, aPlaneBuffer);

    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // Pass in the color information
    aColorBuffer.position(0);
    GLES20.glVertexAttribPointer(
        mColorHandle, mColorDataSize, GLES20.GL_FLOAT, false, 0, aColorBuffer);

    GLES20.glEnableVertexAttribArray(mColorHandle);

    // Pass in the normal information
    aNormalBuffer.position(0);
    GLES20.glVertexAttribPointer(
        mNormalHandle, mNormalDataSize, GLES20.GL_FLOAT, false, 0, aNormalBuffer);

    GLES20.glEnableVertexAttribArray(mNormalHandle);

    if (aTextureBuffer != null) {
      // Pass in the texture coordinate information
      aTextureBuffer.position(0);
      GLES20.glVertexAttribPointer(
          mTextureCoordinateHandle,
          mTextureCoordinateDataSize,
          GLES20.GL_FLOAT,
          false,
          0,
          aTextureBuffer);

      GLES20.glEnableVertexAttribArray(mTextureCoordinateHandle);
    }
    // This multiplies the view matrix by the model matrix, and stores the result in the MVP matrix
    // (which currently contains model * view).
    Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);

    // Pass in the modelview matrix.
    GLES20.glUniformMatrix4fv(mMVMatrixHandle, 1, false, mMVPMatrix, 0);

    // This multiplies the modelview matrix by the projection matrix, and stores the result in the
    // MVP matrix
    // (which now contains model * view * projection).
    Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);

    GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mMVPMatrix, 0);

    // mLightPosInEyeSpace[2] = 100;
    // Pass in the light position in eye space.
    GLES20.glUniform3f(
        mLightPosHandle, mLightPosInEyeSpace[0], mLightPosInEyeSpace[1], mLightPosInEyeSpace[2]);

    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    GLES20.glDisableVertexAttribArray(mTextureCoordinateHandle);
  }
示例#5
0
  public void move() {
    Vec3 cross = VecMath.Normalize(VecMath.CrossProduct(phone_n, init_phone_n));
    Vec3 ny = new Vec3(0, 0, 1);
    Vec3 cross2 = VecMath.CrossProduct(init_phone_n, ny);
    float ang2 = (float) Math.asin(VecMath.Norm(cross2) / (VecMath.Norm(init_phone_n)));
    ;
    Mat4 rotmat2 = VecMath.ArbRotate(cross2, ang2);
    // Mat4 rotmat = VecMath.ArbRotate(cross, MainActivity.phone_ang);
    float phone_ang = MainActivity.phone_ang;
    Mat4 rotmat = VecMath.ArbRotate(cross, MainActivity.phone_ang);

    if (Math.abs(init_phone_n.z) > Math.abs(init_phone_n.y))
      rotmat =
          VecMath.ArbRotate(
              VecMath.MultVec3(VecMath.Rx(-(float) Math.PI / 2), VecMath.Normalize(cross)),
              MainActivity.phone_ang);

    Mat4 rotmatf = VecMath.Mult(rotmat, rotmat2);

    float nx = VecMath.MultVec3(rotmat, new Vec3(0, 1, 0)).x;
    // float nx = -VecMath.MultVec3(rotmat, VecMath.Normalize(init_phone_n)).x;
    // float nx = VecMath.MultVec3(rotmat, new Vec3(1,0,0)).x;
    float nz = VecMath.MultVec3(rotmat, new Vec3(0, 1, 0)).z;
    // float nz = -VecMath.MultVec3(rotmat, VecMath.Normalize(init_phone_n)).z;

    // float phone_ang = MainActivity.phone_ang;
    // float nx = VecMath.DotProduct(VecMath.Normalize(init_phone_n), new Vec3(0,0,0));
    // Vec3 init_n = VecMath.Normalize(init_phone_n);
    // float nx = phone_n.x * init_n.y;
    // float nz = phone_n.z * init_n.y;

    // Vec3 normn = VecMath.Normalize(init_phone_n);

    // Vec3 world_n = new Vec3(init_phone_n.x - phone_n.x, init_phone_n.y-phone_n.y, init_phone_n.z
    // - phone_n.z);
    // Vec3 xy = new Vec3(world_n.x, world_n.y, 0);
    // Vec3 xz = new Vec3((phone_n.x-init_phone_n.x), 0, (phone_n.z-init_phone_n.z));
    // Vec3 y = new Vec3(0,init_phone_n.y,0);
    // Vec3 x = new Vec3(init_phone_n.x,0,0);

    GLES20.glUniform3f(
        GLES20.glGetUniformLocation(Shader.program, "spaceship_pos"), pos.x, pos.y, pos.z);
    GLES20.glUniform3f(
        GLES20.glGetUniformLocation(Shader.program, "spaceship_fin_pos0"),
        fin_pos[0].x,
        fin_pos[0].y,
        fin_pos[0].z);
    GLES20.glUniform3f(
        GLES20.glGetUniformLocation(Shader.program, "spaceship_speed"), speed.x, speed.y, speed.z);
    GLES20.glUniform3f(
        GLES20.glGetUniformLocation(Shader.program, "spaceship_speedf"), speed.x, speed.y, speed.z);

    float ang = MainActivity.phone_ang;

    if (isthrusting && fuel > 0.0f) {

      if (fuel > 0.0f) fuel -= .3;
      GLES20.glUniform1f(GLES20.glGetUniformLocation(Shader.program, "fuel"), fuel);

      acc.x = thrust * nx; // /5.0f;
      acc.y = thrust * (float) Math.cos(ang) + gravity;
      acc.z = thrust * nz; // /5.0f;

    } else acc.y = gravity;

    speed.x += acc.x;
    speed.y += acc.y;
    speed.z += acc.z;

    pos.x += speed.x;
    pos.y += speed.y;
    pos.z += speed.z;

    T = VecMath.T(pos);

    speed.x *= 0.97f;
    speed.z *= 0.97f;
  }