Java Code Examples for android.opengl.Matrix#setRotateM()

The following examples show how to use android.opengl.Matrix#setRotateM() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DetailFilterActivity.java    From GSYVideoPlayer with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {
    float[] transform = new float[16];
    //旋转到正常角度
    Matrix.setRotateM(transform, 0, 180f, 0.0f, 0, 1.0f);
    //调整大小比例
    Matrix.scaleM(transform, 0, mCustomBitmapIconEffect.getScaleW(), mCustomBitmapIconEffect.getScaleH(), 1);
    if (moveBitmap) {
        //调整位置
        Matrix.translateM(transform, 0, mCustomBitmapIconEffect.getPositionX(), mCustomBitmapIconEffect.getPositionY(), 0f);
    } else {
        float maxX = mCustomBitmapIconEffect.getMaxPositionX();
        float minX = mCustomBitmapIconEffect.getMinPositionX();
        float maxY = mCustomBitmapIconEffect.getMaxPositionY();
        float minY = mCustomBitmapIconEffect.getMinPositionY();
        float x = (float) Math.random() * (maxX - minX) + minX;
        float y = (float) Math.random() * (maxY - minY) + minY;
        //调整位置
        Matrix.translateM(transform, 0, x, y, 0f);
        mGSYVideoGLViewCustomRender.setCurrentMVPMatrix(transform);
    }
}
 
Example 2
Source File: GLParticles.java    From Tanks with MIT License 6 votes vote down vote up
private static void build(FloatBuffer buffer, float size, float angleVariance)
{
  int limit = buffer.limit() / packSize;
  float[] matrix = new float[16];
  Random rnd = new Random();
  Vector3 vec = new Vector3();

  buffer.position(0);
  for (int i = 0; i < limit; i++)
  {
    vec.setFrom(0, 0, rnd.nextFloat() * 0.3f + 0.7f);

    Matrix.setRotateM(matrix, 0, angleVariance
      , rnd.nextFloat() - 0.5f
      , rnd.nextFloat() - 0.5f
      , rnd.nextFloat() - 0.5f);

    Matrix.multiplyMV(vec.getRaw(), 0, matrix, 0, vec.getRaw(), 0);

    buffer.put(size * vec.getX());
    buffer.put(size * vec.getY());
    buffer.put(size * vec.getZ());
    buffer.put(0);
  }
}
 
Example 3
Source File: ProgramLandmarks.java    From PLDroidShortVideo with Apache License 2.0 6 votes vote down vote up
public void refresh(float[] landmarksData, int width, int height, int orientation, int cameraType) {
    if (mWidth != width || mHeight != height || mOrientation != orientation || mCameraType != cameraType) {
        float[] orthoMtx = new float[16];
        float[] rotateMtx = new float[16];
        Matrix.orthoM(orthoMtx, 0, 0, width, 0, height, -1, 1);
        Matrix.setRotateM(rotateMtx, 0, 360 - orientation, 0.0f, 0.0f, 1.0f);
        if (cameraType == Camera.CameraInfo.CAMERA_FACING_BACK) {
            Matrix.rotateM(rotateMtx, 0, 180, 1.0f, 0.0f, 0.0f);
        }
        Matrix.multiplyMM(mvpMtx, 0, rotateMtx, 0, orthoMtx, 0);

        mWidth = width;
        mHeight = height;
        mOrientation = orientation;
        mCameraType = cameraType;
    }

    updateVertexArray(Arrays.copyOf(landmarksData, landmarksData.length));
}
 
Example 4
Source File: GSYVideoGLViewCustomRender.java    From GSYVideoPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void onSurfaceChanged(GL10 glUnused, int width, int height) {
    super.onSurfaceChanged(glUnused, width, height);
    //旋转到正常角度
    Matrix.setRotateM(mMVPMatrix, 0, 180f, 0.0f, 0, 1.0f);
    //调整大小比例
    Matrix.scaleM(mMVPMatrix, 0, mBitmapEffect.getScaleW(), mBitmapEffect.getScaleH(), 1);
    //调整位置
    Matrix.translateM(mMVPMatrix, 0, mBitmapEffect.getPositionX(), mBitmapEffect.getPositionY(), 0f);
}
 
Example 5
Source File: GLES20Canvas.java    From android-openGL-canvas with Apache License 2.0 5 votes vote down vote up
@Override
public void rotate(float angle, float x, float y, float z) {
    if (angle == 0f) {
        return;
    }
    float[] temp = mTempMatrix;
    Matrix.setRotateM(temp, 0, angle, x, y, z);
    float[] matrix = mMatrices;
    int index = mCurrentMatrixIndex;
    Matrix.multiplyMM(temp, MATRIX_SIZE, matrix, index, temp, 0);
    System.arraycopy(temp, MATRIX_SIZE, matrix, index, MATRIX_SIZE);
}
 
Example 6
Source File: MyGLRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
@Override
public void onDrawFrame(GL10 unused) {
    float[] scratch = new float[16];

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

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

    // Draw square
    mSquare.draw(mMVPMatrix);

    // Create a rotation for the triangle

    // Use the following code to generate constant rotation.
    // Leave this code out when using TouchEvents.
    // 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
    // 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(scratch);
}
 
Example 7
Source File: GLES20Canvas.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void rotate(float angle, float x, float y, float z) {
    if (angle == 0f) {
        return;
    }
    float[] temp = mTempMatrix;
    Matrix.setRotateM(temp, 0, angle, x, y, z);
    float[] matrix = mMatrices;
    int index = mCurrentMatrixIndex;
    Matrix.multiplyMM(temp, MATRIX_SIZE, matrix, index, temp, 0);
    System.arraycopy(temp, MATRIX_SIZE, matrix, index, MATRIX_SIZE);
}
 
Example 8
Source File: RandomParticlesSource.java    From Tanks with MIT License 5 votes vote down vote up
private Vector3 setVector(Vector3 cached)
{
  cached.setFrom(0, 0, random.nextFloat() * 0.8f + 0.2f);

  Matrix.setRotateM(matrix, 0, angleVariance
    , random.nextFloat() - 0.5f
    , random.nextFloat() - 0.5f
    , random.nextFloat() - 0.5f);

  Matrix.multiplyMV(cached.getRaw(), 0, matrix, 0, cached.getRaw(), 0);
  return cached;
}
 
Example 9
Source File: FrameRotationQueue.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private static void getRotationMatrixFromAngleAxis(float[] matrix, float[] angleAxis) {
  // Convert coordinates to OpenGL coordinates.
  // CAMM motion metadata: +x right, +y down, and +z forward.
  // OpenGL: +x right, +y up, -z forwards
  float x = angleAxis[0];
  float y = -angleAxis[1];
  float z = -angleAxis[2];
  float angleRad = Matrix.length(x, y, z);
  if (angleRad != 0) {
    float angleDeg = (float) Math.toDegrees(angleRad);
    Matrix.setRotateM(matrix, 0, angleDeg, x / angleRad, y / angleRad, z / angleRad);
  } else {
    Matrix.setIdentityM(matrix, 0);
  }
}
 
Example 10
Source File: DetailFilterActivity.java    From GSYVideoPlayer with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    float[] transform = new float[16];
    switch (percentageType) {
        case 1:
            //给予x变化
            Matrix.setRotateM(transform, 0, 360 * percentage / 100, 1.0f, 0, 0.0f);
            break;
        case 2:
            //给予y变化
            Matrix.setRotateM(transform, 0, 360 * percentage / 100, 0.0f, 1.0f, 0.0f);
            break;
        case 3:
            //给予z变化
            Matrix.setRotateM(transform, 0, 360 * percentage / 100, 0.0f, 0, 1.0f);
            break;
        case 4:
            Matrix.setRotateM(transform, 0, 360, 0.0f, 0, 1.0f);
            break;
    }
    //设置渲染transform
    detailPlayer.setMatrixGL(transform);
    percentage++;
    if (percentage > 100) {
        percentage = 1;
    }
}
 
Example 11
Source File: MyGLRenderer.java    From recordablesurfaceview with Apache License 2.0 5 votes vote down vote up
@Override
public void onDrawFrame(GL10 unused) {
    float[] scratch = new float[16];

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

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

    // Draw square
    mSquare.draw(mMVPMatrix);

    // Create a rotation for the triangle

    // Use the following code to generate constant rotation.
    // Leave this code out when using TouchEvents.
    // 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
    // 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(scratch);
}
 
Example 12
Source File: GLCanvasImpl.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void rotate(final float angle, final float x, final float y, final float z) {
    if (angle == 0) {
        return;
    }
    final 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);
}
 
Example 13
Source File: RotationFilterRender.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 5 votes vote down vote up
public void setRotation(int rotation) {
  this.rotation = rotation;
  //Set rotation
  Matrix.setRotateM(rotationMatrix, 0, rotation, 0, 0, 1.0f);
  //Translation
  //Matrix.translateM(rotationMatrix, 0, 0f, 0f, 0f);
  // Combine the rotation matrix with the projection and camera view
  Matrix.multiplyMM(MVPMatrix, 0, rotationMatrix, 0, MVPMatrix, 0);
}
 
Example 14
Source File: RendererCommon.java    From VideoCRE with MIT License 5 votes vote down vote up
/**
 * Returns texture matrix that will have the effect of rotating the frame |rotationDegree|
 * clockwise when rendered.
 */
public static float[] rotateTextureMatrix(float[] textureMatrix, float rotationDegree) {
  final float[] rotationMatrix = new float[16];
  Matrix.setRotateM(rotationMatrix, 0, rotationDegree, 0, 0, 1);
  adjustOrigin(rotationMatrix);
  return multiplyMatrices(textureMatrix, rotationMatrix);
}
 
Example 15
Source File: MatrixStack.java    From PanoramaGL with Apache License 2.0 4 votes vote down vote up
public void glRotatef(float angle, float x, float y, float z) {
    Matrix.setRotateM(mTemp, 0, angle, x, y, z);
    System.arraycopy(mMatrix, mTop, mTemp, MATRIX_SIZE, MATRIX_SIZE);
    Matrix.multiplyMM(mMatrix, mTop, mTemp, MATRIX_SIZE, mTemp, 0);
}
 
Example 16
Source File: GLMatrixStack.java    From tilt-game-android with MIT License 4 votes vote down vote up
public void glRotatef(final float pAngle, final float pX, final float pY, final float pZ) {
	Matrix.setRotateM(this.mTemp, 0, pAngle, pX, pY, pZ);
	System.arraycopy(this.mMatrixStack, this.mMatrixStackOffset, this.mTemp, GLMatrixStack.GLMATRIX_SIZE, GLMatrixStack.GLMATRIX_SIZE);
	Matrix.multiplyMM(this.mMatrixStack, this.mMatrixStackOffset, this.mTemp, GLMatrixStack.GLMATRIX_SIZE, this.mTemp, 0);
}
 
Example 17
Source File: MyGLRenderer.java    From poly-sample-android with Apache License 2.0 4 votes vote down vote up
@Override
public void onDrawFrame(GL10 unused) {
  // Update the spin animation.
  long now = System.currentTimeMillis();
  float deltaT = Math.min((now - lastFrameTime) * 0.001f, 0.1f);
  lastFrameTime = now;
  angleDegrees += deltaT * MODEL_ROTATION_SPEED_DPS;

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

  // Make a model matrix that rotates the model about the Y axis so it appears to spin.
  Matrix.setRotateM(modelMatrix, 0, angleDegrees, 0, 1, 0);

  // Set the camera position (View matrix)
  Matrix.setLookAtM(viewMatrix, 0,
      // Camera position.
      EYE_X, EYE_Y, EYE_Z,
      // Point that the camera is looking at.
      TARGET_X, TARGET_Y, TARGET_Z,
      // The vector that defines which way is up.
      UP_X, UP_Y, UP_Z);

  // Calculate the MVP matrix (model-view-projection) by multiplying the model, view, and
  // projection matrices together.
  Matrix.multiplyMM(tmpMatrix, 0, viewMatrix, 0, modelMatrix, 0);  // V * M
  Matrix.multiplyMM(mvpMatrix, 0, projMatrix, 0, tmpMatrix, 0);  // P * V * M

  // objectToRender is volatile, so we capture it in a local variable.
  RawObject obj = objectToRender;

  if (readyToRender) {
    // We're ready to render, so just render using our existing VBOs and IBO.
    myShader.render(mvpMatrix, indexCount, ibo, positionsVbo, colorsVbo);
  } else if (obj != null) {
    // The object is ready, but we haven't consumed it yet. We need to create the VBOs and IBO
    // to render the object.
    indexCount = obj.indexCount;
    ibo = MyGLUtils.createIbo(obj.indices);
    positionsVbo = MyGLUtils.createVbo(obj.positions);
    colorsVbo = MyGLUtils.createVbo(obj.colors);
    // Now we're ready to render the object.
    readyToRender = true;
    Log.d(TAG, "VBOs/IBO created. Now ready to render object.");
  }
}
 
Example 18
Source File: MatrixStack.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
public void glRotatef(float angle, float x, float y, float z) {
    Matrix.setRotateM(mTemp, 0, angle, x, y, z);
    System.arraycopy(mMatrix, mTop, mTemp, MATRIX_SIZE, MATRIX_SIZE);
    Matrix.multiplyMM(mMatrix, mTop, mTemp, MATRIX_SIZE, mTemp, 0);
}
 
Example 19
Source File: GLMatrixStack.java    From 30-android-libraries-in-30-days with Apache License 2.0 4 votes vote down vote up
public void glRotatef(final float pAngle, final float pX, final float pY, final float pZ) {
	Matrix.setRotateM(this.mTemp, 0, pAngle, pX, pY, pZ);
	System.arraycopy(this.mMatrixStack, this.mMatrixStackOffset, this.mTemp, GLMatrixStack.GLMATRIX_SIZE, GLMatrixStack.GLMATRIX_SIZE);
	Matrix.multiplyMM(this.mMatrixStack, this.mMatrixStackOffset, this.mTemp, GLMatrixStack.GLMATRIX_SIZE, this.mTemp, 0);
}
 
Example 20
Source File: MatrixStack.java    From panoramagl with Apache License 2.0 4 votes vote down vote up
public void glRotatef(float angle, float x, float y, float z) {
    Matrix.setRotateM(mTemp, 0, angle, x, y, z);
    System.arraycopy(mMatrix, mTop, mTemp, MATRIX_SIZE, MATRIX_SIZE);
    Matrix.multiplyMM(mMatrix, mTop, mTemp, MATRIX_SIZE, mTemp, 0);
}