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);
 }
示例#2
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);
  }
  @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();
  }
 public Vector3 getDirection() {
   Matrix.setIdentityM(matrix, 0);
   Matrix.rotateM(matrix, 0, yaw, 0, 1, 0);
   Matrix.rotateM(matrix, 0, pitch, 1, 0, 0);
   Matrix.multiplyMV(outVex, 0, matrix, 0, inVex, 0);
   direction.set(outVex[0], outVex[1], outVex[2]);
   return direction;
 }
  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);
  }
 /*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);
 }
示例#7
0
  public void drawAll(Camera cam) {
    float[] rotationMatrix = new float[16];
    boolean typeSwitchDirty = false;

    OrderUnit[] renderOrder = buildCompleteDrawOrder(cam.getPos());

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

    for (int i = 0; i < renderOrder.length; i++) {
      if (renderOrder[i].getType() == OrderUnit.ORDERUNITTYPE.Node) {
        if (!typeSwitchDirty) {
          mConnectionsBatch.endBatch();
          mDottedBatch.endBatch();
        }

        drawOneNode(renderOrder[i].getId(), rotationMatrix, cam);
        typeSwitchDirty = true;
      } else {
        if (typeSwitchDirty) {
          mConnectionsBatch.beginBatch(cam, modelMatrix);
          mDottedBatch.beginBatch(cam, modelMatrix);
          typeSwitchDirty = false;
        }

        Line3D currentLine = connections[renderOrder[i].getId()].getLine();
        if (currentLine.isDotted()) mDottedBatch.batchElement(currentLine);
        else mConnectionsBatch.batchElement(currentLine);
      }
    }
  }
示例#8
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();
  }
示例#9
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();
  }
示例#10
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;
  }
示例#11
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();
  }
示例#12
0
  // XXX Find out whether or not using Matrix operations is better than a home-grown solution.
  // Perhaps run a test to see how long matrix ops really take.
  // TODO: Try to multiply multiple points in one M x V operation in Primitive.
  // This function belongs in Element, not Point.
  // XXX This rotates about the origin.
  public Float3 rotate(float a, float x, float y, float z) {

    float[] v = new float[] {this.x, this.y, this.z, 1};

    float[] m = new float[16];
    Matrix.setIdentityM(m, 0);
    Matrix.rotateM(m, 0, a, x, y, z);
    Matrix.multiplyMV(v, 0, m, 0, v, 0);

    return new Float3(v[0], v[1], v[2]);
  }
  @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);
  }
示例#14
0
  @Override
  public void onNewFrame(HeadTransform headTransform) {

    Matrix.rotateM(mModelCube, 0, TIME_DELTA, 0.5f, 0.5f, 1.0f);

    // Build the camera matrix and apply it to the ModelView.
    Matrix.setLookAtM(mCamera, 0, 0.0f, 0.0f, CAMERA_Z, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f);

    headTransform.getHeadView(headView, 0);

    checkGLError("onReadyToDraw");

    float[] mtx = new float[16];
    GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);
    surface.updateTexImage();
    surface.getTransformMatrix(mtx);
    mHeadTransform = headTransform;
    headTransform.getHeadView(headView, 0);
  }
    @Override
    public void onSensorChanged(final SensorEvent event) {

      if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
        synchronized (mRotationMatrix) {
          SensorManager.getRotationMatrixFromVector(mRotationMatrix, event.values);

          final int mScreenRotation =
              mActivity.getWindowManager().getDefaultDisplay().getRotation();

          switch (mScreenRotation) {
            case Surface.ROTATION_90:
              // x => y   &&    y => -x
              SensorManager.remapCoordinateSystem(
                  mRotationMatrix, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, mTmpMatrix);
              System.arraycopy(mTmpMatrix, 0, mRotationMatrix, 0, mTmpMatrix.length);
              break;
            case Surface.ROTATION_270:
              // x => -y   &&    y => x
              SensorManager.remapCoordinateSystem(
                  mRotationMatrix, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_X, mTmpMatrix);
              System.arraycopy(mTmpMatrix, 0, mRotationMatrix, 0, mTmpMatrix.length);
              break;
            default:
              break;
          }

          // Rotation of 90 degrees about x axis
          Matrix.rotateM(mRotationMatrix, 0, 90, 1, 0, 0);

          // we just got a new value. Update 'new' flag.
          mHasNewValue = true;
        }

        // finally, throw the event to listeners.
        mNotifyListeners(event);
      }
    }
 public void camMove(float ay, float az) {
   float[] matCamTemp = new float[16];
   float[] matZ = new float[16];
   Matrix.setRotateM(matZ, 0, az, 0.0f, 0.0f, 1.0f);
   Matrix.multiplyMM(matCamTemp, 0, matZ, 0, matCam, 0);
   matCopy(matCamTemp, matCam);
   Matrix.rotateM(matCam, 0, ay, 0.0f, 1.0f, 0.0f);
   if (Math.abs(Math.atan2(matCam[2], matCam[10])) > ANGLE_Y_LIMIT) {
     matCopy(matCamTemp, matCam);
   }
   Matrix.setLookAtM(
       mViewMatrix,
       0,
       matCam[0] * len,
       matCam[1] * len,
       matCam[2] * len,
       0.0f,
       0.0f,
       0.0f,
       0.0f,
       0.0f,
       1.0f);
 }
示例#17
0
  @Override
  public void draw(Camera cam) {
    Matrix.setIdentityM(modelMatrix, 0);
    Matrix.rotateM(modelMatrix, 0, angle, 0.0f, 1.0f, 0.0f);

    Camera updCam = new Camera(cam);
    updCam.setPos(
        cam.getPos()
            .rotate(
                -angle, 0.0f, 1.0f, 0.0f)); // camera position is changed WITHOUT updating matrices

    computeNodeSocketsPositions(updCam.getPos());
    // TODO: redo enable/disable switch when performance optimizations are done
    // GLES20.glDisable(GLES20.GL_DEPTH_TEST);
    // GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    drawConnections(updCam);
    // GLES20.glDisable(GLES20.GL_DEPTH_TEST);

    // GLES20.glEnable(GLES20.GL_DEPTH_TEST);
    drawNodes(updCam);

    // GLES20.glEnable(GLES20.GL_DEPTH_TEST);
  }
示例#18
0
 private void applyRot(float[] result, float[] data, float t) {
   if (Math.abs(data[3]) > 1.0e-7 && Math.hypot(Math.hypot(data[0], data[1]), data[2]) > 1.0e-7)
     Matrix.rotateM(result, 0, (float) (data[3] * t * 180 / Math.PI), data[0], data[1], data[2]);
 }
  // 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();
  }
示例#20
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();
    }
  }
示例#21
0
  @Override
  public void onDrawFrame(GL10 glUnused) {
    GLES20.glClear(GLES20.GL_DEPTH_BUFFER_BIT | GLES20.GL_COLOR_BUFFER_BIT);

    GLES20.glUseProgram(mProgramHandle);

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

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

    // Draw the triangle facing straight on.
    Matrix.setIdentityM(mModelMatrix, 0);
    //	        Matrix.rotateM(mModelMatrix, 0, xAngle, 0.0f, 1.0f, 0.0f);
    //			Matrix.rotateM(mModelMatrix, 0, -yAngle, 1.0f, 0.0f, 0.0f);
    Matrix.rotateM(mModelMatrix, 0, xAngle, 1.0f, 0.0f, 0.0f);
    Matrix.rotateM(mModelMatrix, 0, yAngle, 0.0f, 1.0f, 0.0f);
    Matrix.rotateM(mModelMatrix, 0, zAngle, 0.0f, 0.0f, 1.0f);
    //	        Matrix.rotateM(mModelMatrix, 0, angleInDegrees, 1.0f, 1.0f, 1.0f);

    // Set the active texture unit to texture unit 0.
    GLES20.glActiveTexture(GLES20.GL_TEXTURE0);

    // Bind the texture to this unit.
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle0);

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

    draw(mcubeVertices, 0);

    // Set the active texture unit to texture unit 0.
    GLES20.glActiveTexture(GLES20.GL_TEXTURE1);

    // Bind the texture to this unit.
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle1);

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

    draw(mcubeVertices, 1);

    // Set the active texture unit to texture unit 0.
    GLES20.glActiveTexture(GLES20.GL_TEXTURE2);

    // Bind the texture to this unit.
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle2);

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

    draw(mcubeVertices, 2);

    // Set the active texture unit to texture unit 0.
    GLES20.glActiveTexture(GLES20.GL_TEXTURE3);

    // Bind the texture to this unit.
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle3);

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

    draw(mcubeVertices, 3);

    // Set the active texture unit to texture unit 0.
    GLES20.glActiveTexture(GLES20.GL_TEXTURE4);

    // Bind the texture to this unit.
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle4);

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

    draw(mcubeVertices, 4);

    // Set the active texture unit to texture unit 0.
    GLES20.glActiveTexture(GLES20.GL_TEXTURE5);

    // Bind the texture to this unit.
    GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextureDataHandle5);

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

    draw(mcubeVertices, 5);
  }
示例#22
0
 public static void rotate(float angle, float x, float y, float z) // 设置绕xyz轴移动
     {
   Matrix.rotateM(currMatrix, 0, angle, x, y, z);
 }