Esempio n. 1
0
  @Override
  public void onDrawFrame(GL10 glUnused) {
    GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);

    // Do a complete rotation every 10 seconds.
    long time = SystemClock.uptimeMillis() % 10000L;
    float angleInDegrees = (360.0f / 10000.0f) * ((int) time);

    //        Matrix.setIdentityM(mModelMatrix, 0);
    //        Matrix.translateM(mModelMatrix, 0, 0.0f, -1.0f, -50.0f);
    //        Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
    //        drawSphere(mSpherePositions);
    DrawFrame(glUnused);

    //        tdmodel.draw(glUnused);

    // Draw the triangle facing straight on.
    Matrix.setIdentityM(mModelMatrix, 0);
    Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
    drawTriangle(mTriangle1Vertices);

    // Draw one translated a bit down and rotated to be flat on the ground.
    Matrix.setIdentityM(mModelMatrix, 0);
    Matrix.translateM(mModelMatrix, 0, 0.0f, -1.0f, 0.0f);
    Matrix.rotateM(mModelMatrix, 0, 90.0f, 1.0f, 0.0f, 0.0f);
    Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
    drawTriangle(mTriangle2Vertices);

    // Draw one translated a bit to the right and rotated to be facing to the left.
    Matrix.setIdentityM(mModelMatrix, 0);
    Matrix.translateM(mModelMatrix, 0, 1.0f, 0.0f, 0.0f);
    Matrix.rotateM(mModelMatrix, 0, 90.0f, 0.0f, 1.0f, 0.0f);
    Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 0.0f, 0.0f, 1.0f);
    drawTriangle(mTriangle3Vertices);
  }
Esempio n. 2
0
  /**
   * OnDrawFrame is called whenever a new frame needs to be drawn. Normally, this is done at the
   * refresh rate of the screen.
   */
  @Override
  public void onDrawFrame(GL10 glUnused) {
    // Clear the rendering surface.
    glClear(GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    long time = SystemClock.uptimeMillis() % 10000L;
    float angleInDegrees = (360.0f / 10000.0f) * ((int) time);

    glUseProgram(program);

    // Assign the matrix

    Matrix.setIdentityM(modelMatrix, 0);
    Matrix.translateM(modelMatrix, 0, -4.0f, 0.0f, -7.0f);
    Matrix.scaleM(modelMatrix, 0, 0.5f, 2.0f, 2.0f);
    drawCube();
    Matrix.setIdentityM(modelMatrix, 0);
    Matrix.translateM(modelMatrix, 0, 0.0f, 0.0f, -7.0f);
    Matrix.rotateM(modelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
    drawCube();
    Matrix.setIdentityM(modelMatrix, 0);
    Matrix.translateM(modelMatrix, 0, 4.0f, 0.0f, -7.0f);
    Matrix.scaleM(modelMatrix, 0, 0.5f, 2.0f, 2.0f);
    drawCube();
    Matrix.setIdentityM(modelMatrix, 0);
    Matrix.translateM(modelMatrix, 0, 0.0f, 0.0f, -9.0f);
    Matrix.scaleM(modelMatrix, 0, 4.0f, 2.0f, 0.5f);
    drawCube();
  }
  @Override
  public void onDrawFrame(GL10 gl) {
    super.onDrawFrame(gl);
    // GL Draw code onwards
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    // Do a complete rotation every 10 seconds.
    long time = SystemClock.uptimeMillis() % 10000L;
    float angleInDegrees = (360.0f / 10000.0f) * ((int) time);

    // Set our per-vertex lighting program.
    GLES20.glUseProgram(mProgramHandle);

    // Set program handles for cube drawing.
    mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_MVPMatrix");
    mMVMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_MVMatrix");
    mLightPosHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_LightPos");
    mTextureUniformHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_Texture");
    mPositionHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Position");
    mColorHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Color");
    mNormalHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_Normal");
    mTextureCoordinateHandle = GLES20.glGetAttribLocation(mProgramHandle, "a_TexCoordinate");

    GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, getGLSurfaceTexture());
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    GLES20.glUniform1i(mTextureUniformHandle, 0);

    //        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, 0);
    //        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, glSurfaceTex);
    //        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

    //        // Set the active texture unit to texture unit 0.
    //        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
    //
    //        // Bind the texture to this unit.
    //        GLES20.glBindTexture(GLES11Ext.GL_TEXTURE_EXTERNAL_OES, glSurfaceTex);

    // Tell the texture uniform sampler to use this texture in the shader by binding to texture unit
    // 0.
    //        GLES20.glUniform1i(mTextureUniformHandle, 0);

    // Calculate position of the light. Rotate and then push into the distance.
    Matrix.setIdentityM(mLightModelMatrix, 0);
    Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, -4.0f);
    Matrix.rotateM(mLightModelMatrix, 0, angleInDegrees, 0.0f, 1.0f, 0.0f);
    Matrix.translateM(mLightModelMatrix, 0, 0.0f, 0.0f, 2.0f);

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

    Matrix.setIdentityM(mModelMatrix, 0);
    Matrix.translateM(mModelMatrix, 0, 0.0f, 0.0f, -3.3f);
    Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 1.0f, 0.0f);
    drawCube();

    // Draw a point to indicate the light.
    GLES20.glUseProgram(mPointProgramHandle);
    drawLight();
  }
Esempio n. 4
0
  private void drawOneNode(int id, float[] rotationMatrix, Camera cam) {
    float[] color;
    float[] spriteMatrix = new float[16];

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

    switch (nodes[id].getState()) {
      case CORRECT:
        color = new float[] {0.0f, 0.8f, 0.0f, 1.0f};
        nodes[id].getSprite().setColor(color).setTexture(mCorrectNodeTextureHandle);
        break;
      case WRONG:
        color = new float[] {1.0f, 1.0f, 1.0f, 1.0f};
        nodes[id].getSprite().setColor(color).setTexture(mWrongNodeTextureHandle);
        break;
      case OPEN:
        color = new float[] {1.0f, 1.0f, 1.0f, 1.0f};
        nodes[id].getSprite().setColor(color).setTexture(mCorrectNodeTextureHandle);
        break;
      default: // when IDLE
        color = new float[] {0.7f, 0.7f, 0.7f, 1.0f};
        nodes[id].getSprite().setColor(color).setTexture(mCorrectNodeTextureHandle);
        break;
    }

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

    nodes[id]
        .getSprite()
        .setModelMatrix(spriteMatrix)
        .setOrientationMatrix(rotationMatrix)
        .draw(cam);

    NodeConnectionSocket[] sockets = nodes[id].getSockets();
    mSocketBatch.beginBatch(cam, rotationMatrix);

    for (int k = 0; k < sockets.length; k++) {
      Matrix.setIdentityM(spriteMatrix, 0);
      Matrix.translateM(
          spriteMatrix,
          0,
          modelMatrix,
          0,
          nodes[id].posX + sockets[k].posX,
          nodes[id].posY + sockets[k].posY,
          nodes[id].posZ + sockets[k].posZ);

      float diam = sockets[k].getRadius() * 2;

      mSocketBatch.batchElement(diam, diam, sockets[k].getSprite().getTexRgn(), spriteMatrix);
    }

    mSocketBatch.endBatch();
  }
Esempio n. 5
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);
    }
  }
Esempio n. 6
0
 /**
  * Set the absolute position of this camera
  *
  * @param x x coordinate
  * @param y y coordinate
  * @param z z coordinate
  */
 public void setPosition(float x, float y, float z) {
   synchronized (mViewMatrix) {
     // revert last position
     Matrix.translateM(mViewMatrix, 0, mPosition[0], mPosition[1], mPosition[2]);
     // set new position
     mPosition[0] = x;
     mPosition[1] = y;
     mPosition[2] = z;
     Matrix.translateM(mViewMatrix, 0, -mPosition[0], -mPosition[1], -mPosition[2]);
   }
 }
Esempio n. 7
0
 @Override
 public void draw(SchminceRenderer renderer, SBlock block) {
   float[] vpMatrix = renderer.getVPMatrix();
   Matrix.translateM(vpMatrix, 0, block.X, block.Y, 0);
   Matrix.scaleM(vpMatrix, 0, 0.5f, 0.5f, 1f);
   renderer.getGlib().getDrawer(itemType).draw(vpMatrix);
 }
 public void setRotation(float angleX, float angleY) {
     setIdentityM(mModelMatrix, 0);
     rotateM(mModelMatrix, 0, mRotationX + angleX, 1f, 0f, 0f);
     rotateM(mModelMatrix, 0, mRotationY + angleY, 0f, 1f, 0f);
     translateM(mModelMatrix, 0, 0f, 0f, mPositionZ);
     scaleM(mModelMatrix, 0, mScale, mScale, mScale);
 }
 /*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);
 }
Esempio n. 10
0
  public void setSize(int width, int height) {
    Utils.assertTrue(width >= 0 && height >= 0);

    if (mTargetTexture == null) {
      mScreenWidth = width;
      mScreenHeight = height;
    }
    mAlpha = 1.0f;

    GL11 gl = mGL;
    gl.glViewport(0, 0, width, height);
    gl.glMatrixMode(GL11.GL_PROJECTION);
    gl.glLoadIdentity();
    GLU.gluOrtho2D(gl, 0, width, 0, height);

    gl.glMatrixMode(GL11.GL_MODELVIEW);
    gl.glLoadIdentity();

    float matrix[] = mMatrixValues;
    Matrix.setIdentityM(matrix, 0);
    // to match the graphic coordinate system in android, we flip it vertically.
    if (mTargetTexture == null) {
      Matrix.translateM(matrix, 0, 0, height, 0);
      Matrix.scaleM(matrix, 0, 1, -1, 1);
    }
  }
Esempio n. 11
0
 /**
  * Translate the cameras position with the given coordinates
  *
  * @param x translation x coordinate
  * @param y translation y coordinate
  * @param z translation z coordinate
  */
 public void translate(float x, float y, float z) {
   synchronized (mViewMatrix) {
     mPosition[0] -= x;
     mPosition[1] -= y;
     mPosition[2] -= z;
     Matrix.translateM(mViewMatrix, 0, -x, -y, -z);
   }
 }
Esempio n. 12
0
 /**
  * Sets the cameras rotation matrix. This is similar to setting the model view matrix but it keeps
  * the cameras current position.
  *
  * @param rotM rotation matrix to set
  */
 public void setRotationViewMatrix(float[] rotM) {
   synchronized (mViewMatrix) {
     for (int i = 0; i < 16; i++) {
       mViewMatrix[i] = rotM[i];
     }
     Matrix.translateM(mViewMatrix, 0, -mPosition[0], -mPosition[1], -mPosition[2]);
   }
 }
Esempio n. 13
0
  private void drawActionName(final MVP mvp, final float contentSize) {
    final float[] nameModel = mvp.peekCopy(MVP.Type.MODEL);

    // Move to the left edge of the menu item
    Matrix.translateM(nameModel, Constants.NO_OFFSET, -0.45f, 0.0f, 0.0f);

    // Shrink the content text to the correct size
    float nameWidth = (1.0f / aspectRatio);
    Matrix.scaleM(nameModel, Constants.NO_OFFSET, nameWidth, 1.0f, 1.0f);

    // Align the left edge of the text with the left edge of the menu item
    Matrix.translateM(nameModel, Constants.NO_OFFSET, text.getWidth() / 2.0f, 0.0f, 0.0f);

    // Perform the text draw
    mvp.push(MVP.Type.MODEL, nameModel);
    text.render(mvp);
    mvp.pop(MVP.Type.MODEL);
  }
  private void updateViewMatrices() {
    setIdentityM(viewMatrix, 0);
    rotateM(viewMatrix, 0, -yRotation, 1f, 0f, 0f);
    rotateM(viewMatrix, 0, -xRotation, 0f, 1f, 0f);
    System.arraycopy(viewMatrix, 0, viewMatrixForSkybox, 0, viewMatrix.length);

    // We want the translation to apply to the regular view matrix, and not
    // the skybox.
    translateM(viewMatrix, 0, 0, -1.5f, -5f);
  }
Esempio n. 15
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);
  }
Esempio n. 16
0
  protected void applyTransforms() {
    Matrix.setIdentityM(mWorldMatrix, 0);
    Matrix.translateM(mWorldMatrix, 0, mTransDir.getX(), mTransDir.getY(), mTransDir.getZ());
    if (mRotAxes != null) {
      Matrix.rotateM(mWorldMatrix, 0, mRotAngle, mRotAxes.getX(), mRotAxes.getY(), mRotAxes.getZ());
    }
    Matrix.scaleM(mWorldMatrix, 0, mScaleFac.getX(), mScaleFac.getY(), mScaleFac.getZ());

    mDirty = false;
  }
Esempio n. 17
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();
  }
Esempio n. 18
0
 /**
  * Translate the cameras position with the given coordinates
  *
  * @param vector3f an array of size three, containing x,y and z coordinates
  */
 public void translate(float[] vector3f) {
   if (vector3f == null || vector3f.length != 3) {
     return;
   }
   synchronized (mViewMatrix) {
     mPosition[0] -= vector3f[0];
     mPosition[1] -= vector3f[1];
     mPosition[2] -= vector3f[2];
     Matrix.translateM(mViewMatrix, 0, -vector3f[0], -vector3f[1], -vector3f[2]);
   }
 }
Esempio n. 19
0
  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();
  }
Esempio n. 20
0
  private void drawIcon(final MVP mvp, final SimpleTexturedShader shader) {
    final Device device = injector.getInstance(Device.class);
    final float[] iconModel = mvp.peekCopy(MVP.Type.MODEL);

    // Move to the right edge of the entire menu item
    Matrix.translateM(iconModel, Constants.NO_OFFSET, 0.5f, 0.0f, 0.0f);

    // Scale the icon to be 1:1 square to the menu item height
    Matrix.scaleM(
        iconModel, Constants.NO_OFFSET, 1.0f / aspectRatio / device.getAspectRatio(), 1.0f, 1.0f);

    // Align the right edge of the icon to the right edge of the menu item
    Matrix.translateM(iconModel, Constants.NO_OFFSET, -0.5f, 0.0f, 0.0f);

    // Shrink the icon size down to fit in the margins
    final float contentSize = 0.5f;
    Matrix.scaleM(iconModel, Constants.NO_OFFSET, contentSize, contentSize, 1.0f);

    // Perform the icon draw
    shader.setMVPMatrix(mvp.collapseM(iconModel));
    shader.setTexture(action.getIconTexture());
    shader.draw();
  }
  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);
  }
  @Override
  public void onSurfaceCreated(EGLConfig eglConfig) {
    Matrix.setIdentityM(mLightModelMatrix, 0);
    Matrix.translateM(mLightModelMatrix, 0, -2.0f, 1.0f, -2.0f);

    GLES20.glClearColor(0.5f, 0.5f, 0.5f, 1.0f);

    GLES20.glEnable(GLES20.GL_DEPTH_TEST);

    setUpCamera();

    mProgramHandle = Util.createProgram();
    mMVMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_MVMatrix");
    mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_MVPMatrix");
    mLightPosHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_LightPos");
    mTextureHandle = GLES20.glGetUniformLocation(mProgramHandle, "u_Texture");

    mLightProgramHandle = Util.createLightProgram();
    mLightMVPMatrixHandle = GLES20.glGetUniformLocation(mLightProgramHandle, "u_MVPMatrix");

    screenWidth = getCardboardView().getWidth();
    screenHeight = getCardboardView().getHeight();
  }
Esempio n. 23
0
 public static void translate(float x, float y, float z) // 设置沿xyz轴移动
     {
   Matrix.translateM(currMatrix, 0, x, y, z);
 }
Esempio n. 24
0
 private void positionObjectInScene(float x, float y, float z) {
   setIdentityM(modelMatrix, 0);
   translateM(modelMatrix, 0, x, y, z);
   multiplyMM(modelViewProjectionMatrix, 0, viewProjectionMatrix, 0, modelMatrix, 0);
 }
Esempio n. 25
0
 public void translate(float[] delta) {
   Matrix.translateM(viewMatrix, 0, delta[0], delta[1], delta[2]);
 }
Esempio n. 26
0
 public void translate(float x, float y, float z) {
   Matrix.translateM(mMatrixValues, 0, x, y, z);
 }
Esempio n. 27
0
  @Override
  public void onDrawFrame(GL10 glUnused) {
    GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);

    // Set our per-vertex lighting program.
    GLES20.glUseProgram(mPerVertexProgramHandle);

    // Set program handles for cube drawing.
    mMVPMatrixHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_MVPMatrix");
    mMVMatrixHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_MVMatrix");
    mLightPosHandle = GLES20.glGetUniformLocation(mPerVertexProgramHandle, "u_LightPos");
    mPositionHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Position");
    mColorHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Color");
    mNormalHandle = GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_Normal");
    mTextureCoordinateHandle =
        GLES20.glGetAttribLocation(mPerVertexProgramHandle, "a_TexCoordinate");

    // Set the active texture unit to texture unit 0.
    GLES20.glEnable(GLES20.GL_TEXTURE_2D);
    // Bind the texture to this unit.
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureArray.get(0));
    drawPlane(this.mGroundVertices, this.mGroundColors, this.mGroundNormals, mGroundTextures);
    // bind the next texture
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureArray.get(1));
    drawPlane(this.mOceanVertices, this.mOceanColors, this.mOceanNormals, mOceanTextures);
    // bind the next texture
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureArray.get(3));
    drawCube();

    // Get changes in finger positions and add to total for moving and rotating
    totalDiffX += diffX;
    totalDiffY += diffY;
    angleX += dx;
    angleY += dy;
    // to prevent the user from looking more than straight up and less and straight down.
    if (Math.abs(angleY) > 1.5f) {
      angleY -= dy;
    }

    // move the model matrix by finger distance changes for pinch zoom movement.
    Matrix.translateM(mModelMatrix, 0, this.diffX, this.diffY, 0);

    // rotate camera based on finger movements
    this.mCamera.look.x = (float) Math.cos(angleX);
    this.mCamera.look.y = (float) Math.sin(angleX);
    this.mCamera.look.z = (float) Math.tan(angleY);
    updateLookAt();

    // reset variables so that movement stops after finger movement stops
    this.dx = 0;
    this.dy = 0;
    this.diffX = 0;
    this.diffY = 0;

    // update the lookAt coordinates
    updateLookAt();
    // redraw each object in the array.
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureArray.get(2));
    synchronized (this.objects) {
      for (Prim p : this.objects) {
        p.draw(
            this.mPositionHandle,
            this.mColorHandle,
            this.mNormalHandle,
            this.mTextureCoordinateHandle);
      }
    }
    GLES20.glDisable(GLES20.GL_TEXTURE_2D);
  }
Esempio n. 28
0
 public void setPan(float pX, float pY) {
   Matrix.setIdentityM(mViewMatrix, 0);
   Matrix.translateM(mViewMatrix, 0, pX, pY, 0.0f);
 }
  // The render function.
  private void renderFrame() {
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

    State state = mRenderer.begin();
    mRenderer.drawVideoBackground();

    GLES20.glEnable(GLES20.GL_DEPTH_TEST);

    // handle face culling, we need to detect if we are using reflection
    // to determine the direction of the culling
    GLES20.glEnable(GLES20.GL_CULL_FACE);
    GLES20.glCullFace(GLES20.GL_BACK);
    if (Renderer.getInstance().getVideoBackgroundConfig().getReflection()
        == VIDEO_BACKGROUND_REFLECTION.VIDEO_BACKGROUND_REFLECTION_ON)
      GLES20.glFrontFace(GLES20.GL_CW); // Front camera
    else GLES20.glFrontFace(GLES20.GL_CCW); // Back camera

    // did we find any trackables this frame?
    for (int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++) {
      TrackableResult result = state.getTrackableResult(tIdx);
      Trackable trackable = result.getTrackable();
      printUserData(trackable);
      Matrix44F modelViewMatrix_Vuforia = Tool.convertPose2GLMatrix(result.getPose());
      float[] modelViewMatrix = modelViewMatrix_Vuforia.getData();

      int textureIndex = trackable.getName().equalsIgnoreCase("cat") ? 0 : 1;
      textureIndex = trackable.getName().equals("city") ? 1 : textureIndex;
      textureIndex = trackable.getName().equalsIgnoreCase("tree") ? 2 : textureIndex;

      // Part B

      Calendar calendar = Calendar.getInstance();
      int day = calendar.get(Calendar.DAY_OF_WEEK);

      if (day != Calendar.SATURDAY && day != Calendar.SUNDAY) {

        textureIndex =
            trackable.getName().equalsIgnoreCase("b11_013")
                ? ImageTargets.orderImages.indexOf("b11_013") + 3
                : textureIndex;
        textureIndex =
            trackable.getName().equalsIgnoreCase("b11_014")
                ? ImageTargets.orderImages.indexOf("b11_014") + 3
                : textureIndex;
        textureIndex =
            trackable.getName().equalsIgnoreCase("b11_015")
                ? ImageTargets.orderImages.indexOf("b11_015") + 3
                : textureIndex;
        textureIndex =
            trackable.getName().equalsIgnoreCase("berkaer_003")
                ? ImageTargets.orderImages.indexOf("berkaer_003") + 3
                : textureIndex;
        textureIndex =
            trackable.getName().equalsIgnoreCase("p_013")
                ? ImageTargets.orderImages.indexOf("p_013") + 3
                : textureIndex;

      } else {
        textureIndex = trackable.getName().equalsIgnoreCase("b11_013") ? 3 : textureIndex;
        textureIndex = trackable.getName().equalsIgnoreCase("b11_014") ? 3 : textureIndex;
        textureIndex = trackable.getName().equalsIgnoreCase("b11_015") ? 3 : textureIndex;
        textureIndex = trackable.getName().equalsIgnoreCase("berkaer_003") ? 3 : textureIndex;
        textureIndex = trackable.getName().equalsIgnoreCase("p_013") ? 3 : textureIndex;
      }

      // deal with the modelview and projection matrices
      float[] modelViewProjection = new float[16];

      boolean partA =
          trackable.getName().equalsIgnoreCase("cat")
              || trackable.getName().equalsIgnoreCase("city")
              || trackable.getName().equalsIgnoreCase("tree");

      if (!mActivity.isExtendedTrackingActive()) {
        if (partA) {
          Matrix.translateM(modelViewMatrix, 0, 0.0f, 0.0f, OBJECT_SCALE_FLOAT);
          Matrix.scaleM(
              modelViewMatrix, 0, OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT);
        } else {
          Matrix.translateM(
              modelViewMatrix, 0, OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT);
          Matrix.scaleM(
              modelViewMatrix, 0, OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT);
        }

      } else {
        Matrix.rotateM(modelViewMatrix, 0, 90.0f, 1.0f, 0, 0);
        Matrix.scaleM(modelViewMatrix, 0, kBuildingScale, kBuildingScale, kBuildingScale);
      }

      Matrix.multiplyMM(
          modelViewProjection,
          0,
          vuforiaAppSession.getProjectionMatrix().getData(),
          0,
          modelViewMatrix,
          0);

      // activate the shader program and bind the vertex/normal/tex coords
      GLES20.glUseProgram(shaderProgramID);

      if (!mActivity.isExtendedTrackingActive()) {

        if (partA) {
          GLES20.glVertexAttribPointer(
              vertexHandle, 3, GLES20.GL_FLOAT, false, 0, mTeapot.getVertices());
          GLES20.glVertexAttribPointer(
              normalHandle, 3, GLES20.GL_FLOAT, false, 0, mTeapot.getNormals());
          GLES20.glVertexAttribPointer(
              textureCoordHandle, 2, GLES20.GL_FLOAT, false, 0, mTeapot.getTexCoords());
        } else {

          Log.d("Object", "Name:" + trackable.getName());
          // To replace the Teapot for a plane Image

          GLES20.glVertexAttribPointer(
              vertexHandle, 3, GLES20.GL_FLOAT, false, 0, mTextPlane.getVertices());
          GLES20.glVertexAttribPointer(
              normalHandle, 3, GLES20.GL_FLOAT, false, 0, mTextPlane.getNormals());
          GLES20.glVertexAttribPointer(
              textureCoordHandle, 2, GLES20.GL_FLOAT, false, 0, mTextPlane.getTexCoords());
        }

        GLES20.glEnableVertexAttribArray(vertexHandle);
        GLES20.glEnableVertexAttribArray(normalHandle);
        GLES20.glEnableVertexAttribArray(textureCoordHandle);

        // activate texture 0, bind it, and pass to shader
        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures.get(textureIndex).mTextureID[0]);

        GLES20.glUniform1i(texSampler2DHandle, 0);

        // pass the model view matrix to the shader
        GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, modelViewProjection, 0);

        if (partA) {
          // Finally draw the teapot
          GLES20.glDrawElements(
              GLES20.GL_TRIANGLES,
              mTeapot.getNumObjectIndex(),
              GLES20.GL_UNSIGNED_SHORT,
              mTeapot.getIndices());

        } else {
          // Draw the plane text
          GLES20.glDrawElements(
              GLES20.GL_TRIANGLES,
              mTextPlane.getNumObjectIndex(),
              GLES20.GL_UNSIGNED_SHORT,
              mTextPlane.getIndices());
        }

        // disable the enabled arrays
        GLES20.glDisableVertexAttribArray(vertexHandle);
        GLES20.glDisableVertexAttribArray(normalHandle);
        GLES20.glDisableVertexAttribArray(textureCoordHandle);
      } else {
        GLES20.glDisable(GLES20.GL_CULL_FACE);
        GLES20.glVertexAttribPointer(
            vertexHandle, 3, GLES20.GL_FLOAT, false, 0, mBuildingsModel.getVertices());
        GLES20.glVertexAttribPointer(
            normalHandle, 3, GLES20.GL_FLOAT, false, 0, mBuildingsModel.getNormals());
        GLES20.glVertexAttribPointer(
            textureCoordHandle, 2, GLES20.GL_FLOAT, false, 0, mBuildingsModel.getTexCoords());

        GLES20.glEnableVertexAttribArray(vertexHandle);
        GLES20.glEnableVertexAttribArray(normalHandle);
        GLES20.glEnableVertexAttribArray(textureCoordHandle);

        GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
        GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures.get(3).mTextureID[0]);
        GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false, modelViewProjection, 0);
        GLES20.glUniform1i(texSampler2DHandle, 0);
        GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0, mBuildingsModel.getNumObjectVertex());

        SampleUtils.checkGLError("Renderer DrawBuildings");
      }

      SampleUtils.checkGLError("Render Frame");
    }

    GLES20.glDisable(GLES20.GL_DEPTH_TEST);

    mRenderer.end();
  }
Esempio n. 30
0
  public void drawNodes(Camera cam) {
    int cur;
    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);

    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};
          nodes[cur].getSprite().setColor(color).setTexture(mCorrectNodeTextureHandle);
          break;
        case WRONG:
          color = new float[] {1.0f, 1.0f, 1.0f, 1.0f};
          nodes[cur].getSprite().setColor(color).setTexture(mWrongNodeTextureHandle);
          break;
        case OPEN:
          color = new float[] {1.0f, 1.0f, 1.0f, 1.0f};
          nodes[cur].getSprite().setColor(color).setTexture(mCorrectNodeTextureHandle);
          break;
        default: // when IDLE
          color = new float[] {0.7f, 0.7f, 0.7f, 1.0f};
          nodes[cur].getSprite().setColor(color).setTexture(mCorrectNodeTextureHandle);
          break;
      }

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

      nodes[cur]
          .getSprite()
          .setModelMatrix(spriteMatrix)
          .setOrientationMatrix(rotationMatrix)
          .draw(cam);

      NodeConnectionSocket[] sockets = nodes[cur].getSockets();
      mSocketBatch.beginBatch(cam, rotationMatrix);

      for (int k = 0; k < sockets.length; k++) {
        Matrix.setIdentityM(spriteMatrix, 0);
        Matrix.translateM(
            spriteMatrix,
            0,
            modelMatrix,
            0,
            nodes[cur].posX + sockets[k].posX,
            nodes[cur].posY + sockets[k].posY,
            nodes[cur].posZ + sockets[k].posZ);

        // sockets[k].getPosV().print("Debug", "Node " + i + " socket " + k);

        float diam = sockets[k].getRadius() * 2;

        mSocketBatch.batchElement(diam, diam, sockets[k].getSprite().getTexRgn(), spriteMatrix);
      }

      mSocketBatch.endBatch();
    }
  }