@Override
  public void onDrawFrame(GL10 unused) {

    GLES20.glClearColor(0f, 0f, 0f, 0f);
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    if (mShaderCompilerSupport[0] == false) {
      return;
    }

    GLES20.glDisable(GLES20.GL_DEPTH_TEST);
    GLES20.glEnable(GLES20.GL_BLEND);
    GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);

    float angle = (SystemClock.uptimeMillis() % 5000) / 5000f * 360;
    Matrix.setRotateM(mMatrixModel, 0, angle, 1, 2, 0);

    Matrix.multiplyMM(mMatrixModelViewProjection, 0, mMatrixView, 0, mMatrixModel, 0);
    Matrix.multiplyMM(
        mMatrixModelViewProjection, 0, mMatrixProjection, 0, mMatrixModelViewProjection, 0);

    mShaderSpline.useProgram();

    GLES20.glUniformMatrix4fv(
        mShaderSpline.getHandle("uModelViewProjectionM"), 1, false, mMatrixModelViewProjection, 0);

    GLES20.glVertexAttribPointer(
        mShaderSpline.getHandle("aPosition"), 2, GLES20.GL_FLOAT, false, 0, mBufferSpline);
    GLES20.glEnableVertexAttribArray(mShaderSpline.getHandle("aPosition"));

    for (float[] ctrl : mSplines) {
      GLES20.glUniform3fv(mShaderSpline.getHandle("uCtrl"), 4, ctrl, 0);
      GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, COUNT_VERTICES);
    }
  }
  @Override
  public void onDrawFrame(GL10 unused) {

    // Draw background color
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    // Set the camera position (View matrix)
    Matrix.setLookAtM(mVMatrix, 0, 0, 0, -5, 0f, 0f, 0f, 0f, 5.0f, 0.0f);

    // Calculate the projection and view transformation
    Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);

    // Draw square
    // mSquare.draw(mMVPMatrix);

    // Create a rotation for the triangle
    //        long time = SystemClock.uptimeMillis() % 4000L;
    //        float angle = 0.090f * ((int) time);
    // Matrix.setRotateM(mRotationMatrix, 0, mAngle, 1, 0, -1.0f);
    Matrix.setRotateM(xRotationMatrix, 0, -mAngle2, 1, 0, 0f);
    Matrix.setRotateM(yRotationMatrix, 0, -mAngle, 0, 1, 0f);
    Matrix.multiplyMM(mRotationMatrix, 0, xRotationMatrix, 0, yRotationMatrix, 0);

    // Combine the rotation matrix with the projection and camera view
    Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0);

    // Draw triangle
    // mTriangle.draw(mMVPMatrix);
    if (mMesh != null) {
      mMesh.draw(mMVPMatrix);
    }
  }
  public void onDrawFrame(GL10 gl) {
    // Redraw background color
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    Log.i("MyGLRenderer", "MyGLRenderer : onDrawFrame() - Starting to set camera position");

    float[] mViewMatrix = new float[16];
    // Set the camera position (View matrix)
    Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

    float[] mMVPMatrix = new float[16];
    // Calculate the projection and view transformation
    Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0);

    Log.i("MyGLRenderer", "MyGLRenderer : onDrawFrame() - Drawing ClientSide");

    float[] scratch = new float[16];

    // Create a rotation transformation for the triangle
    long time = SystemClock.uptimeMillis() % 4000L;
    float angle = 0.090f * ((int) time);
    Matrix.setRotateM(mRotationMatrix, 0, angle, 0, 0, -1.0f);

    // Combine the rotation matrix with the projection and camera view
    // Note that the mMVPMatrix factor *must be first* in order
    // for the matrix multiplication product to be correct.
    Matrix.multiplyMM(scratch, 0, mMVPMatrix, 0, mRotationMatrix, 0);

    // Draw triangle
    mTriangle.draw_ClientSide(scratch);
  }
  @Override
  public void onDrawEye(Eye eye) {
    if (resetCameraFlag) {
      float[] invertedEye = new float[16];
      Matrix.invertM(invertedEye, 0, eye.getEyeView(), 0);
      setUpCamera();
      Matrix.multiplyMM(mCameraMatrix, 0, invertedEye, 0, mCameraMatrix, 0);
      resetCameraFlag = false;
    }
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    if (lockCameraFlag) {
      mViewMatrix = mCameraMatrix.clone();
    } else {
      Matrix.multiplyMM(mViewMatrix, 0, eye.getEyeView(), 0, mCameraMatrix, 0);
    }

    Matrix.multiplyMV(mLightPosInWorldSpace, 0, mLightModelMatrix, 0, mLightPosInModelSpace, 0);
    Matrix.multiplyMV(mLightPosInEyeSpace, 0, mViewMatrix, 0, mLightPosInWorldSpace, 0);

    mProjectionMatrix = eye.getPerspective(Z_NEAR, Z_FAR);

    GLES20.glUseProgram(mProgramHandle);
    currentContent.draw(eye);

    if (drawRedPoint) {
      drawTargetingPoint();
    }
    Util.checkGLError("Error Draw Eye");
  }
  // @Override
  public void orbit(float horizAmount, float vertAmount) {
    xRotation += horizAmount;
    yRotation += vertAmount;

    Log.d("XROT", "X rotation: " + xRotation);
    Log.d("YROT", "Y rotation: " + yRotation);

    float[] newPos = Utilities.subtractVectors(position, target);
    float[] rotMatrix = new float[16];
    float[] rotatedPos = new float[4];

    if (newPos.length >= 4) newPos[3] = 1.0f;

    Matrix.setRotateM(rotMatrix, 0, horizAmount, 0.0f, 1.0f, 0.0f);
    Matrix.multiplyMV(rotatedPos, 0, rotMatrix, 0, newPos, 0);
    Matrix.multiplyMV(crossProd, 0, rotMatrix, 0, crossProd, 0);
    Matrix.multiplyMM(rotationMatrix, 0, rotMatrix, 0, rotationMatrix, 0);

    Matrix.setRotateM(rotMatrix, 0, vertAmount, crossProd[0], crossProd[1], crossProd[2]);
    Matrix.multiplyMV(rotatedPos, 0, rotMatrix, 0, rotatedPos, 0);
    Matrix.multiplyMM(rotationMatrix, 0, rotMatrix, 0, rotationMatrix, 0);

    position = Utilities.addVectors(rotatedPos, target);
    direction = Utilities.subtractVectors(target, position);
  }
  public void drawSphere(final FloatBuffer aSphereBuffer) {
    aSphereBuffer.position(mPositionOffset);
    GLES20.glVertexAttribPointer(
        mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false, 0, aSphereBuffer);

    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // Pass in the color information
    //        aTriangleBuffer.position(mColorOffset);
    //        GLES20.glVertexAttribPointer(mColorHandle, mColorDataSize, GLES20.GL_FLOAT, false,
    //        		mStrideBytes, aTriangleBuffer);
    //
    //        GLES20.glEnableVertexAttribArray(mColorHandle);

    // 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);

    // 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);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, sphereTriangles * 3);
  }
  /**
   * Method for painting any given object. Data must be 7 floats per face – we render one triangle
   * consisting of 3 vertices with each vertice having an rgba color float value.
   *
   * @param data The vertice data containing coordinates and colors to draw.
   */
  private void drawObject(final FloatBuffer data) {

    // Pass in the position information
    data.position(mPositionOffset);
    GLES20.glVertexAttribPointer(
        mPositionHandle, mPositionDataSize, GLES20.GL_FLOAT, false, mStrideBytes, data);

    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // Pass in the color information
    data.position(mColorOffset);
    GLES20.glVertexAttribPointer(
        mColorHandle, mColorDataSize, GLES20.GL_FLOAT, false, mStrideBytes, data);

    GLES20.glEnableVertexAttribArray(mColorHandle);

    // 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);

    // 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);
    // The (1+data.capacity() / 8) tells us how many vertices we need to
    // draw
    GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, (1 + data.capacity() / 8));
  }
Exemple #8
0
  @Override
  public void draw(
      float[] mMVPMatrix, float[] mRotationMatrix, float[] mvMatrix, float[] mProjMatrix) {
    if (visible && canvasSurfaceCreated()) {

      if (!initialized) {
        if (!initObject()) {
          return;
        }
      }

      // Add program to OpenGL environment
      GLES20.glUseProgram(programHandle);

      GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

      GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, textureDataHandle);

      GLES20.glUniform1i(textureUniformHandle, 0);

      // Enable a handle to the triangle vertices
      // Prepare the triangle coordinate data
      vBuffer.position(0);
      GLES20.glVertexAttribPointer(
          positionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vBuffer);
      GLES20.glEnableVertexAttribArray(positionHandle);

      // Pass in the texture coordinate information
      textureBuffer.position(0);
      GLES20.glVertexAttribPointer(
          textureCoordinateHandle,
          COORDS_PER_TEXTURE,
          GLES20.GL_FLOAT,
          false,
          (COORDS_PER_TEXTURE * 4),
          textureBuffer);
      GLES20.glEnableVertexAttribArray(textureCoordinateHandle);

      Matrix.multiplyMM(mMVPMatrix, 0, mvMatrix, 0, mModelMatrix, 0);

      // Apply the projection and view transformation
      GLES20.glUniformMatrix4fv(mModelMatrixHandle, 1, false, mMVPMatrix, 0);
      GLES20Renderer.checkGLError("glUniformMatrix4fv");

      Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mMVPMatrix, 0);

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

      // Draw the square
      GLES20.glDrawElements(
          GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, drawBuffer);

      // Disable vertex array
      // GLES20.glDisableVertexAttribArray(positionHandle);
    }
  }
  /** 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);
  }
Exemple #10
0
  public void Compute(float time) {
    int i, n = animations.size();
    for (i = 0; i < n; i++) {
      Animation anim = animations.get(i);
      Object3D obj = anim.object;
      float[] result = new float[16];

      Matrix.setIdentityM(result, 0);

      if (anim.position != null && anim.position.length > 0) {
        AnimKey key = findVec(anim.position, time);
        float[] pos = key.data;
        Matrix.translateM(result, 0, pos[0], pos[1], pos[2]);
      }

      if (anim.rotation != null && anim.rotation.length > 0) {
        // All rotations that are prior to the target time should be applied sequentially
        for (int j = anim.rotation.length - 1; j > 0; j--) {
          if (time >= anim.rotation[j].time) // rotation in the past, apply as is
          applyRot(result, anim.rotation[j].data, 1);
          else if (time > anim.rotation[j - 1].time) {
            // rotation between key frames, apply part of it
            float local =
                (time - anim.rotation[j - 1].time)
                    / (anim.rotation[j].time - anim.rotation[j - 1].time);
            applyRot(result, anim.rotation[j].data, local);
          }
          // otherwise, it's a rotation in the future, skip it
        }

        // Always apply the first rotation
        applyRot(result, anim.rotation[0].data, 1);
      }

      if (anim.scaling != null && anim.scaling.length > 0) {
        AnimKey key = findVec(anim.scaling, time);
        float[] scale = key.data;
        Matrix.scaleM(result, 0, scale[0], scale[1], scale[2]);
      }

      if (anim.parent != null) Matrix.multiplyMM(anim.result, 0, anim.parent.result, 0, result, 0);
      else Matrix.translateM(anim.result, 0, result, 0, 0, 0, 0);

      if (obj != null && obj.trMatrix != null) {
        float[] pivot = new float[16];
        Matrix.setIdentityM(pivot, 0);
        Matrix.translateM(pivot, 0, -anim.pivot[0], -anim.pivot[1], -anim.pivot[2]);
        Matrix.multiplyMM(result, 0, pivot, 0, obj.trMatrix, 0);
      } else {
        Matrix.setIdentityM(result, 0);
        Matrix.translateM(result, 0, -anim.pivot[0], -anim.pivot[1], -anim.pivot[2]);
      }
      Matrix.multiplyMM(anim.world, 0, anim.result, 0, result, 0);
    }
  }
  @Override
  public void onDrawEye(Eye eyeTransform) {
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    checkGLError("colorParam");

    GLES20.glUseProgram(mProgram);
    GLES20.glDrawElements(
        GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, drawListBuffer);

    checkGLError("befor activeTex");
    GLES20.glActiveTexture(GLES20.GL_TEXTURE1);
    checkGLError("after activeTex");
    GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture);
    checkGLError("bind Text");

    checkGLError("mPostionHandle");
    mPositionHandle = GLES20.glGetAttribLocation(mProgram, "position");
    GLES20.glEnableVertexAttribArray(mPositionHandle);
    GLES20.glVertexAttribPointer(
        mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);

    checkGLError("mTexture Handle");
    mTextureCoordHandle = GLES20.glGetAttribLocation(mProgram, "inputTextureCoordinate");
    GLES20.glEnableVertexAttribArray(mTextureCoordHandle);
    GLES20.glVertexAttribPointer(
        mTextureCoordHandle,
        COORDS_PER_VERTEX,
        GLES20.GL_FLOAT,
        false,
        vertexStride,
        textureVerticesBuffer);
    checkGLError("after mTexture Handle");

    mColorHandle = GLES20.glGetAttribLocation(mProgram, "s_texture");
    checkGLError("mColor Handel");

    GLES20.glDrawElements(
        GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, drawListBuffer);

    checkGLError("Disable");
    GLES20.glDisableVertexAttribArray(mPositionHandle);
    GLES20.glDisableVertexAttribArray(mTextureCoordHandle);

    checkGLError("before Cube 2");
    Matrix.multiplyMM(mView, 0, eyeTransform.getEyeView(), 0, mCamera, 0);
    Matrix.multiplyMV(lightPosInEyeSpace, 0, mView, 0, LIGHT_POS_IN_WORLD_SPACE, 0);

    checkGLError("before Cube");
    float[] perspective = eyeTransform.getPerspective(Z_NEAR, Z_FAR);
    Matrix.multiplyMM(modelView, 0, mView, 0, mModelCube, 0);
    Matrix.multiplyMM(modelViewProjection, 0, perspective, 0, modelView, 0);
    drawCube();
  }
  @Override
  public void onDrawFrame(GL10 unused) {
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    float[] parScratch = new float[16];
    float[] bogieScratch = new float[16];
    float[] birdieScratch = new float[16];
    float[] shadowScratch1 = new float[16];
    float[] shadowScratch2 = new float[16];

    // Set the camera position (View matrix)
    Matrix.setLookAtM(mViewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

    // Calculate the projection and view transformation
    Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0);

    float parAngle = -1 * (360 * parPercent);
    float birdieAngle = -1 * (360 * birdiePercent);
    float startingAngle = -90;

    // System.out.println("par angle = " + Float.toString(parAngle));
    // System.out.println("birdie angle = " + Float.toString(birdieAngle));
    // System.out.println("bogie angle = " + Float.toString(-1 * (360 * bogiePercent)));

    // Create a rotation transformation;
    if (angle > -450) {
      // rotates birdie sector to starting angle from angle 0
      if (angle > startingAngle) {
        Matrix.setRotateM(mRotationMatrixBirdie, 0, angle, 0, 0, -1.0f);
      }
      if (angle > startingAngle + birdieAngle) {
        Matrix.setRotateM(mRotationMatrixPar, 0, angle, 0, 0, -1.0f);
      }
      if (angle > startingAngle + birdieAngle + parAngle) {
        Matrix.setRotateM(mRotationMatrixBogie, 0, angle, 0, 0, -1.0f);
      }
      angle -= 2;
    }

    // Combine the rotation matrix with the projection and camera view
    // Note that the mMVPMatrix factor *must be first* in order
    // for the matrix multiplication product to be correct.
    Matrix.multiplyMM(shadowScratch1, 0, mMVPMatrix, 0, mRotationMatrixShadow, 0);
    Matrix.multiplyMM(bogieScratch, 0, mMVPMatrix, 0, mRotationMatrixBogie, 0);
    Matrix.multiplyMM(parScratch, 0, mMVPMatrix, 0, mRotationMatrixPar, 0);
    Matrix.multiplyMM(birdieScratch, 0, mMVPMatrix, 0, mRotationMatrixBirdie, 0);

    shadowPieWheel.draw(mMVPMatrix);
    wheelBG.draw(mMVPMatrix);
    bogiePieWheel.draw(bogieScratch);
    parPieWheel.draw(parScratch);
    birdiePieWheel.draw(birdieScratch);
    wheelHole.draw(mMVPMatrix);
  }
  @Override
  public void onDrawFrame(GL10 glUnused) {
    GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);

    Matrix.setIdentityM(mModelMatrix, 0);
    Matrix.rotateM(mModelMatrix, 0, 90, 1.0f, 0.0f, 0.0f);
    Matrix.multiplyMM(mMVMatrix, 0, mViewMatrix, 0, mModelMatrix, 0);
    Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVMatrix, 0);
    mPrism.render(mMVPMatrix, mMVMatrix);
    mCylinder.render(mMVPMatrix, mMVMatrix);
    mSphere.render(mMVPMatrix, mMVMatrix);
  }
 /*Called after the surface has been created or the size has changed*/
 @Override
 public void onSurfaceChanged(GL10 glUnused, int width, int height) {
   // set the viewPort to fill the entire surface
   // This tells OpenGL the size of the surface it has available for rendering
   glViewport(0, 0, width, height);
   /*final float aspectRatio = width > height ?
           (float) width / (float) height :
           (float) height / (float) width;
   if (width > height) {
       // Landscape
       orthoM(projectionMatrix, 0, -aspectRatio, aspectRatio, -1f, 1f, -1f, 1f);
   } else {
       // Portrait or square
       orthoM(projectionMatrix, 0, -1f, 1f, -aspectRatio, aspectRatio, -1f, 1f);
   }*/
   // field of vision of 45 degrees, frustrum begins at z=-1, ends at z=-10
   MatrixHelper.perspectiveM(projectionMatrix, 45, (float) width / (float) height, 1f, 10f);
   setIdentityM(modelMatrix, 0);
   //        translateM(modelMatrix, 0, 0f, 0f, -2f); //move 2 units along the negative z-axis
   // We push the table farther, because once we rotate it the bottom end will be closer to us
   translateM(modelMatrix, 0, 0f, 0f, -2.5f);
   rotateM(modelMatrix, 0, -60f, 1f, 0f, 0f);
   // Whenever we multiply two matrices, we need a temporary area to store the
   // result.If we try to write the result directly, the results are undefined !
   final float[] temp = new float[16];
   multiplyMM(temp, 0, projectionMatrix, 0, modelMatrix, 0);
   System.arraycopy(temp, 0, projectionMatrix, 0, temp.length);
 }
  /**
   * Draws a frame for an eye. The transformation for that eye (from the camera) is passed in as a
   * parameter.
   *
   * @param transform The transformations to apply to render this eye.
   */
  @Override
  public void onDrawEye(EyeTransform transform) {
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    GLES20.glUseProgram(mProgram);

    GLES20.glActiveTexture(GL_TEXTURE_EXTERNAL_OES);
    GLES20.glBindTexture(GL_TEXTURE_EXTERNAL_OES, texture);

    mPositionHandle = GLES20.glGetAttribLocation(mProgram, "position");
    GLES20.glEnableVertexAttribArray(mPositionHandle);
    GLES20.glVertexAttribPointer(
        mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, vertexStride, vertexBuffer);

    mTextureCoordHandle = GLES20.glGetAttribLocation(mProgram, "inputTextureCoordinate");
    GLES20.glEnableVertexAttribArray(mTextureCoordHandle);
    GLES20.glVertexAttribPointer(
        mTextureCoordHandle,
        COORDS_PER_VERTEX,
        GLES20.GL_FLOAT,
        false,
        vertexStride,
        textureVerticesBuffer);

    GLES20.glDrawElements(
        GLES20.GL_TRIANGLES, drawOrder.length, GLES20.GL_UNSIGNED_SHORT, drawListBuffer);

    // Disable vertex array
    GLES20.glDisableVertexAttribArray(mPositionHandle);
    GLES20.glDisableVertexAttribArray(mTextureCoordHandle);

    Matrix.multiplyMM(mView, 0, transform.getEyeView(), 0, mCamera, 0);
  }
    public void draw(float[] viewProjMatrix) {
        glUseProgram(mProgram);

        multiplyMM(mMVPMatrix, 0, viewProjMatrix, 0, mModelMatrix, 0);
        int handle = glGetUniformLocation(mProgram, Constants.U_MVP_MATRIX);
        glUniformMatrix4fv(handle, 1, false, mMVPMatrix, 0);

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, mTextureA);
        handle = glGetUniformLocation(mProgram, Constants.U_TEX_UNIT_0);
        glUniform1i(handle, 0);

        glActiveTexture(GL_TEXTURE1);
        glBindTexture(GL_TEXTURE_2D, mTextureB);
        handle = glGetUniformLocation(mProgram, Constants.U_TEX_UNIT_1);
        glUniform1i(handle, 1);

        handle = glGetUniformLocation(mProgram, Constants.U_MIX_FACTOR);
        glUniform1f(handle, calcMixFactor());

        handle = glGetUniformLocation(mProgram, Constants.U_BACK_COLOR);
        glUniform3fv(handle, 1, mBackColor, 0);

        mMesh.draw(mProgram);
    }
  /**
   * Rendering of a single frame. Here we update and render the detected trackable list.
   *
   * @param gl Unused context.
   */
  @Override
  public void onDrawFrame(GL10 gl) {
    if (MainInterface.DEBUG_FRAME_LOGGING) log.pushTimer(this, "opengl frame");

    // Clear:
    GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);

    // If new markerlist, get:
    if (mainInterface.getListUpdateStatus()) {
      this.toRender = mainInterface.getList();
      if (toRender == null) {
        log.log(TAG, "Error getting list!");
        toRender = new ArrayList<Trackable>();
      } else log.debug(TAG, "Updated list – found " + this.toRender.size() + " " + "trackables.");
    }
    // ------------------------ RENDER ------------------------
    if (!toRender.isEmpty()) {
      for (Trackable trackable : toRender) {
        // Reset model matrix to identity
        Matrix.setIdentityM(mModelMatrix, 0);
        Matrix.multiplyMM(mModelMatrix, 0, trackable.getTRANSLATION(), 0, mModelMatrix, 0);
        drawObject(trackable.getFloatbuffer());
      }
    }
    if (MainInterface.DEBUG_FRAME_LOGGING) {
      log.debug(TAG, "OpenGL rendered frame in " + log.popTimer(this).time + "ms.");
    }
  }
  void draw(Model m) {
    GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    int oldProgram = GLES20.GL_CURRENT_PROGRAM;
    GLES20.glUseProgram(program);
    GLES20.glEnableVertexAttribArray(aVertexHandle);
    GLES20.glEnableVertexAttribArray(aNormalHandle);

    GLES20.glVertexAttribPointer(aVertexHandle, 3, GLES20.GL_FLOAT, false, 0, m.vertexBuffer);
    GLES20.glVertexAttribPointer(aNormalHandle, 3, GLES20.GL_FLOAT, false, 0, m.normalBuffer);
    float[] modelViewMatrix = new float[16];
    Matrix.multiplyMM(modelViewMatrix, 0, modelMatrix, 0, viewMatrix, 0);
    GLES20.glUniformMatrix4fv(uMVMatrixHandle, 1, false, modelViewMatrix, 0);
    GLES20.glUniformMatrix4fv(uPMatrixHandle, 1, false, projectionMatrix, 0);

    // GLES20.glDrawArrays(mode, first, count)
    // if(m.indexBuffer != null)
    GLES20.glDrawElements(
        GLES20.GL_TRIANGLES, m.num_indices, GLES20.GL_UNSIGNED_SHORT, m.indexBuffer);
    // else
    //	GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, m.num_indices);

    GLES20.glDisableVertexAttribArray(aNormalHandle);
    GLES20.glDisableVertexAttribArray(aVertexHandle);
    GLES20.glUseProgram(oldProgram);
  }
Exemple #19
0
  @Override
  public void onDrawFrame(GL10 gl) {
    // TODO Auto-generated method stub
    // Draw background color
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);
    // Draw triangle
    mTriangle.draw();

    // 设置相机的位置(视口矩阵)
    // Matrix.setLookAtM(mVMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);

    // 计算投影和视口变换
    // Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);

    // 绘制形状
    // mTriangle.draw(mMVPMatrix);

    // Create a rotation for the triangle
    // long time = SystemClock.uptimeMillis() % 4000L;
    // float angle = 0.090f * ((int) time);
    Matrix.setRotateM(mRotationMatrix, 0, mAngle, 0, 0, -1.0f);

    // 把旋转矩阵合并到投影和相机矩阵
    Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0);

    // 画三角形
    mTriangle.draw(mMVPMatrix);
  }
 public void rotate(float angle, float x, float y, float z) {
   if (angle == 0) return;
   float[] temp = mTempMatrix;
   Matrix.setRotateM(temp, 0, angle, x, y, z);
   Matrix.multiplyMM(temp, 16, mMatrixValues, 0, temp, 0);
   System.arraycopy(temp, 16, mMatrixValues, 0, 16);
 }
 @Override
 public void onSurfaceChanged(GL10 unused, int width, int height) {
   float aspect = (float) width / height;
   Matrix.perspectiveM(mMatrixProjection, 0, 60f, aspect, .1f, 10f);
   Matrix.setLookAtM(mMatrixView, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0);
   Matrix.multiplyMM(mMatrixModelViewProjection, 0, mMatrixProjection, 0, mMatrixView, 0);
   mLastRenderTime = -1;
 }
  private void drawTargetingPoint() {
    GLES20.glUseProgram(mLightProgramHandle);

    GLES20.glVertexAttrib3f(Util.ATTRIBUTE_POSITION, 0.0f, 0.0f, 0.0f);

    GLES20.glDisableVertexAttribArray(Util.ATTRIBUTE_POSITION);

    float[] MVPMatrix = new float[16];

    Matrix.setIdentityM(mPointModelMatrix, 0);
    Matrix.translateM(mPointModelMatrix, 0, 0.0f, 0.0f, 2.0f);

    Matrix.multiplyMM(MVPMatrix, 0, mCameraMatrix, 0, mPointModelMatrix, 0);
    Matrix.multiplyMM(MVPMatrix, 0, mProjectionMatrix, 0, MVPMatrix, 0);
    GLES20.glUniformMatrix4fv(mLightMVPMatrixHandle, 1, false, MVPMatrix, 0);

    GLES20.glDrawArrays(GLES20.GL_POINTS, 0, 1);
  }
  private void draw(final FloatBuffer acubeBuffer, final int i) {

    // Pass in the position information. each vertex needs 3 values and each
    // face of the
    // cube needs 4 vertices. so total 3*4 = 12
    acubeBuffer.position(12 * i);
    GLES20.glVertexAttribPointer(mPositionHandle, 3, GLES20.GL_FLOAT, false, 0, acubeBuffer);

    GLES20.glEnableVertexAttribArray(mPositionHandle);

    // Pass in the color information. every vertex colr is defined by 4 values and each cube face
    // has 4 vertices so 4*4 = 16
    mCubeColors.position(16 * i);
    GLES20.glVertexAttribPointer(mColorHandle, 4, GLES20.GL_FLOAT, false, 0, mCubeColors);

    GLES20.glEnableVertexAttribArray(mColorHandle);

    // Pass in the texture coordinate information. every vertex needs 2
    // values to define texture
    // for each face of the cube we need 4 textures . so 4*2=8
    mCubeTextureCoordinates.position(8 * i);
    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);

    // 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);
    // *each face of the cube is drawn using 2 triangles. so 2*3=6 lines
    GLES20.glDrawElements(GLES20.GL_TRIANGLES, 6, GLES20.GL_UNSIGNED_SHORT, indexBuffer);
  }
Exemple #24
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);
    }
  }
Exemple #25
0
  public void draw(float[] vpMatrix, GLCubeShader shader) {
    float[] mvpMatrix = new float[16];

    float[] moduleMatrix = new float[16];
    Matrix.setIdentityM(moduleMatrix, 0);
    Matrix.translateM(moduleMatrix, 0, mCenter[0], mCenter[1], mCenter[2]);
    Matrix.multiplyMM(mvpMatrix, 0, vpMatrix, 0, moduleMatrix, 0);

    shader.draw(mvpMatrix, mColor);
  }
Exemple #26
0
  public void drawNodesBatched(Camera cam) {
    int cur;
    TextureRegion texRgn = new TextureRegion();
    float[] color;
    float[] spriteMatrix = new float[16];
    float[] rotationMatrix = new float[16];
    float[] convMatrix = new float[16];

    Matrix.multiplyMM(
        convMatrix,
        0,
        cam.getViewM(),
        0,
        modelMatrix,
        0); // multiply view matrix by model to calc distances from cam
    NodeOrderUnit[] renderOrder = this.buildDrawOrder(convMatrix);

    Matrix.setIdentityM(rotationMatrix, 0);
    Matrix.rotateM(rotationMatrix, 0, -angle, 0.0f, 1.0f, 0.0f);

    mNodeBatch.beginBatch(cam, rotationMatrix);
    // batch.beginBatch(cam);

    for (int i = 0; i < renderOrder.length; i++) {

      cur = renderOrder[i].getId();

      /*if (nodes[cur].isSelected()) color = new float[] {0.1f, 0.1f, 0.7f, 1.0f};
      else color = new float[] {1.0f, 1.0f, 1.0f, 1.0f};*/
      switch (nodes[cur].getState()) {
        case CORRECT:
          color = new float[] {0.0f, 0.8f, 0.0f, 1.0f};
          break;
        case WRONG:
          color = new float[] {0.8f, 0.0f, 0.0f, 1.0f};
          break;
        case OPEN:
          color = new float[] {1.0f, 1.0f, 1.0f, 1.0f};
          break;
        default: // when IDLE
          color = new float[] {0.7f, 0.7f, 0.7f, 1.0f};
          break;
      }

      Matrix.setIdentityM(spriteMatrix, 0);
      Matrix.translateM(
          spriteMatrix, 0, modelMatrix, 0, nodes[cur].posX, nodes[cur].posY, nodes[cur].posZ);

      float diam = nodes[cur].getRadius() * 2;

      mNodeBatch.batchElement(diam, diam, color, texRgn, spriteMatrix);
    }

    mNodeBatch.endBatch();
  }
Exemple #27
0
 @Override
 protected void doRender() {
   GLES20.glBindBuffer(34962, this.mVertexBuffers[0]);
   GLES20.glVertexAttribPointer(this.mVertexInGLSL, 3, 5126, false, 0, 0);
   GLES20.glBindBuffer(34962, 0);
   GLES20.glUniform4f(
       this.mSimpleColorInGLSL, this.mColor[0], this.mColor[1], this.mColor[2], this.mAlpha);
   if (ExtendedGlSurfaceView.isGlErrorOccured()) {
     CameraLogger.e(TAG, "clearAndResetSurface():[Texture binder Error]");
   }
   float[] arrf = new float[16];
   Matrix.setIdentityM(arrf, 0);
   Matrix.multiplyMM(arrf, 0, this.mSequencedLocalMatrix, 0, arrf, 0);
   Matrix.multiplyMM(arrf, 0, this.mGlobalMatrix, 0, arrf, 0);
   GLES20.glUniformMatrix4fv(this.mMvpMatrixInGLSL, 1, false, arrf, 0);
   GLES20.glDrawArrays(5, 0, 4);
   if (ExtendedGlSurfaceView.isGlErrorOccured()) {
     CameraLogger.e(TAG, "clearAndResetSurface():[Draw frame Error]");
   }
 }
  protected BaseRenderer(Context context) {
    this.context = context;

    /* *** set default ViewProjection Matrix*** */
    Matrix.setIdentityM(modelMatrix, 0);
    Matrix.translateM(modelMatrix, 0, xP, yP, zP);
    float[] viewMatrix = new float[16];
    float[] projectionMatrix = new float[16];
    MatrixHelper.perspectiveM(projectionMatrix, 45, 1f, 1f, 10f);
    Matrix.setLookAtM(viewMatrix, 0, 0, 0, 3.0f, 0.0f, 0.0f, 0.0f, 0, 1.0f, 0);
    Matrix.multiplyMM(viewProjectionMatrix, 0, projectionMatrix, 0, viewMatrix, 0);
    setModelViewProjectionMatrix();
  }
  public void onDrawFrame(GL10 gl) {
    // TODO Auto-generated method stub
    loopStart = System.currentTimeMillis();
    try {
      if (loopRunTime < ZxCEngine.GAME_THREAD_FPS_SLEEP) {
        Thread.sleep(ZxCEngine.GAME_THREAD_FPS_SLEEP - loopRunTime);
      }
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
    // gl.glLoadIdentity();
    loopEnd = System.currentTimeMillis();
    loopRunTime = ((loopEnd - loopStart));
    // Draw background color

    // GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT);

    // Set the camera position (View matrix)
    Matrix.setLookAtM(mVMatrix, 0, 0, 0, -10, 0f, 0f, 0f, 0f, 10.0f, 10.0f);

    // Calculate the projection and view transformation
    Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);

    // Draw square
    mSquare.draw(mMVPMatrix);
    // personaje.draw(mMVPMatrix);
    // Create a rotation for the triangle
    //        long time = SystemClock.uptimeMillis() % 4000L;
    //        float angle = 0.090f * ((int) time);
    Matrix.setRotateM(mRotationMatrix, 0, mAngle, 0, 0, -1.0f);

    // Combine the rotation matrix with the projection and camera view
    Matrix.multiplyMM(mMVPMatrix, 0, mRotationMatrix, 0, mMVPMatrix, 0);

    // Draw triangle
    // mTriangle.draw(mMVPMatrix);
  }
  private void drawLight() {
    final int pointMVPMatrixHandle =
        GLES20.glGetUniformLocation(mPointProgramHandle, "u_MVPMatrix");
    final int pointPositionHandle = GLES20.glGetAttribLocation(mPointProgramHandle, "a_Position");

    // Pass in the position.
    GLES20.glVertexAttrib3f(
        pointPositionHandle,
        mLightPosInModelSpace[0],
        mLightPosInModelSpace[1],
        mLightPosInModelSpace[2]);

    // Since we are not using a buffer object, disable vertex arrays for this attribute.
    GLES20.glDisableVertexAttribArray(pointPositionHandle);

    // Pass in the transformation matrix.
    Matrix.multiplyMM(mMVPMatrix, 0, mViewMatrix, 0, mLightModelMatrix, 0);
    Matrix.multiplyMM(mMVPMatrix, 0, mProjectionMatrix, 0, mMVPMatrix, 0);
    GLES20.glUniformMatrix4fv(pointMVPMatrixHandle, 1, false, mMVPMatrix, 0);

    // Draw the point.
    GLES20.glDrawArrays(GLES20.GL_POINTS, 0, 1);
  }