android.opengl.Matrix.translateM()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(515)

本文整理了Java中android.opengl.Matrix.translateM()方法的一些代码示例,展示了Matrix.translateM()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Matrix.translateM()方法的具体详情如下:
包路径:android.opengl.Matrix
类名称:Matrix
方法名:translateM

Matrix.translateM介绍

暂无

代码示例

代码示例来源:origin: CarGuo/GSYVideoPlayer

@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);
    }
  }
}

代码示例来源:origin: robolectric/robolectric

@Test
public void testTranslateMInPlace() {
 float[] matrix = new float[]{
     1, 2, 3, 4,
     5, 6, 7, 8,
     9, 10, 11, 12,
     13, 14, 15, 16
 };
 float[] expected = new float[]{
     1, 2, 3, 4,
     5, 6, 7, 8,
     9, 10, 11, 12,
     89, 102, 115, 128
 };
 Matrix.translateM(matrix, 0, 2, 4, 6);
 assertThat(matrix).usingExactEquality().containsAllOf(expected);
}

代码示例来源:origin: CarGuo/GSYVideoPlayer

@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);
}

代码示例来源:origin: robolectric/robolectric

@Test
public void testTranslateM() {
 float[] matrix = new float[]{
     1, 2, 3, 4,
     5, 6, 7, 8,
     9, 10, 11, 12,
     13, 14, 15, 16
 };
 float[] expected = new float[]{
     1, 2, 3, 4,
     5, 6, 7, 8,
     9, 10, 11, 12,
     89, 102, 115, 128
 };
 float[] output = new float[16];
 Matrix.translateM(output, 0, matrix, 0, 2, 4, 6);
 assertThat(output).usingExactEquality().containsAllOf(expected);
}

代码示例来源:origin: doggycoder/AndroidOpenGLDemo

public void translate(float x,float y,float z){
  Matrix.translateM(mMatrixCurrent,0,x,y,z);
}

代码示例来源:origin: doggycoder/AndroidOpenGLDemo

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
  lx=0f;
  ly=0.8f;
  lz=-1f;
  matrix=MatrixUtils.getOriginalMatrix();
  Matrix.scaleM(matrix,0,0.5f,0.5f*width/(float)height,0.5f);
  lambMatrix=MatrixUtils.getOriginalMatrix();
  Matrix.translateM(lambMatrix,0,lx,ly,lz);
  Matrix.scaleM(lambMatrix,0,0.09f,0.09f*width/height,0.09f);
}

代码示例来源:origin: google/santa-tracker-android

private void drawQuad(float centerX, float centerY, float width, float height, float rotation) {
  // compute final matrix
  float[] modelViewM = mTmpMatA;
  float[] finalM = mTmpMatB;
  Matrix.setIdentityM(modelViewM, 0);
  Matrix.translateM(modelViewM, 0, centerX, centerY, 0.0f);
  Matrix.rotateM(modelViewM, 0, rotation, 0.0f, 0.0f, 1.0f);
  Matrix.scaleM(modelViewM, 0, width, height, 1.0f);
  Matrix.multiplyMM(finalM, 0, mProjMat, 0, modelViewM, 0);
  // push matrix
  GLES20.glUniformMatrix4fv(mLocMatrix, 1, false, finalM, 0);
  // push positions
  GLES20.glEnableVertexAttribArray(mLocPosition);
  mQuadGeomBuf.position(QUAD_GEOM_POS_OFFSET);
  GLES20.glVertexAttribPointer(
      mLocPosition, 3, GLES20.GL_FLOAT, false, QUAD_GEOM_STRIDE, mQuadGeomBuf);
  // push texture coordinates
  GLES20.glEnableVertexAttribArray(mLocTexCoord);
  mQuadGeomBuf.position(QUAD_GEOM_TEXCOORD_OFFSET);
  GLES20.glVertexAttribPointer(
      mLocTexCoord, 2, GLES20.GL_FLOAT, false, QUAD_GEOM_STRIDE, mQuadGeomBuf);
  // draw
  GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, QUAD_GEOM_VERTEX_COUNT);
}

代码示例来源:origin: fookwood/Launcher3

@Override
public void translate(float x, float y, float z) {
  Matrix.translateM(mMatrices, mCurrentMatrixIndex, x, y, z);
}

代码示例来源:origin: ChillingVan/android-openGL-canvas

@Override
public void translate(float x, float y, float z) {
  Matrix.translateM(mMatrices, mCurrentMatrixIndex, x, y, z);
}

代码示例来源:origin: fookwood/Launcher3

@Override
public void getBounds(Rect bounds, int x, int y, int width, int height) {
  Matrix.translateM(mTempMatrix, 0, mMatrices, mCurrentMatrixIndex, x, y, 0f);
  Matrix.scaleM(mTempMatrix, 0, width, height, 1f);
  Matrix.multiplyMV(mTempMatrix, MATRIX_SIZE, mTempMatrix, 0, BOUNDS_COORDINATES, 0);
  Matrix.multiplyMV(mTempMatrix, MATRIX_SIZE + 4, mTempMatrix, 0, BOUNDS_COORDINATES, 4);
  bounds.left = Math.round(mTempMatrix[MATRIX_SIZE]);
  bounds.right = Math.round(mTempMatrix[MATRIX_SIZE + 4]);
  bounds.top = Math.round(mTempMatrix[MATRIX_SIZE + 1]);
  bounds.bottom = Math.round(mTempMatrix[MATRIX_SIZE + 5]);
  bounds.sort();
}

代码示例来源:origin: codeka/wwmmo

public void setTranslation(float xDp, float yDp) {
 float xPx = dimensionResolver.dp2px(xDp);
 float yPx = dimensionResolver.dp2px(yDp);
 matrix[12] = 0; matrix[13] = 0; matrix[14] = 0; matrix[15] = 1.0f;
 Matrix.translateM(matrix, 0, xPx / widthPx, yPx / heightPx, 0.0f);
}

代码示例来源:origin: WeAreFairphone/FP2-Launcher

@Override
public void getBounds(Rect bounds, int x, int y, int width, int height) {
  Matrix.translateM(mTempMatrix, 0, mMatrices, mCurrentMatrixIndex, x, y, 0f);
  Matrix.scaleM(mTempMatrix, 0, width, height, 1f);
  Matrix.multiplyMV(mTempMatrix, MATRIX_SIZE, mTempMatrix, 0, BOUNDS_COORDINATES, 0);
  Matrix.multiplyMV(mTempMatrix, MATRIX_SIZE + 4, mTempMatrix, 0, BOUNDS_COORDINATES, 4);
  bounds.left = Math.round(mTempMatrix[MATRIX_SIZE]);
  bounds.right = Math.round(mTempMatrix[MATRIX_SIZE + 4]);
  bounds.top = Math.round(mTempMatrix[MATRIX_SIZE + 1]);
  bounds.bottom = Math.round(mTempMatrix[MATRIX_SIZE + 5]);
  bounds.sort();
}

代码示例来源:origin: ChillingVan/android-openGL-canvas

@Override
public void getBounds(Rect bounds, int x, int y, int width, int height) {
  Matrix.translateM(mTempMatrix, 0, mMatrices, mCurrentMatrixIndex, x, y, 0f);
  Matrix.scaleM(mTempMatrix, 0, width, height, 1f);
  Matrix.multiplyMV(mTempMatrix, MATRIX_SIZE, mTempMatrix, 0, BOUNDS_COORDINATES, 0);
  Matrix.multiplyMV(mTempMatrix, MATRIX_SIZE + 4, mTempMatrix, 0, BOUNDS_COORDINATES, 4);
  bounds.left = Math.round(mTempMatrix[MATRIX_SIZE]);
  bounds.right = Math.round(mTempMatrix[MATRIX_SIZE + 4]);
  bounds.top = Math.round(mTempMatrix[MATRIX_SIZE + 1]);
  bounds.bottom = Math.round(mTempMatrix[MATRIX_SIZE + 5]);
  bounds.sort();
}

代码示例来源:origin: codeka/wwmmo

public void translate(float xDp, float yDp) {
 float xPx = dimensionResolver.dp2px(xDp);
 float yPx = dimensionResolver.dp2px(yDp);
 Matrix.translateM(matrix, 0, xPx, yPx, 0.0f);
}

代码示例来源:origin: dbrant/ModelViewer3D

private void updateViewMatrix() {
  Matrix.setLookAtM(viewMatrix, 0, 0, 0, translateZ, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
  Matrix.translateM(viewMatrix, 0, -translateX, -translateY, 0f);
  Matrix.rotateM(viewMatrix, 0, rotateAngleX, 1f, 0f, 0f);
  Matrix.rotateM(viewMatrix, 0, rotateAngleY, 0f, 1f, 0f);
}

代码示例来源:origin: codeka/wwmmo

public float[] getViewProjMatrix() {
 Matrix.setIdentityM(viewMatrix, 0);
 Matrix.scaleM(viewMatrix, 0, zoomAmount, zoomAmount, 1.0f);
 Matrix.translateM(viewMatrix, 0, translateX, translateY, 0.0f);
 Matrix.multiplyMM(viewProjMatrix, 0, projMatrix, 0, viewMatrix, 0);
 return viewProjMatrix;
}

代码示例来源:origin: dbrant/ModelViewer3D

private void updateViewMatrix() {
  Matrix.setLookAtM(viewMatrix, 0, 0, 0, translateZ, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
  Matrix.translateM(viewMatrix, 0, -translateX, -translateY, 0f);
  Matrix.rotateM(viewMatrix, 0, rotateAngleX, 1f, 0f, 0f);
  Matrix.rotateM(viewMatrix, 0, rotateAngleY, 0f, 1f, 0f);
}

代码示例来源:origin: fookwood/Launcher3

private void setMatrix(ShaderParameter[] params, float x, float y, float width, float height) {
  Matrix.translateM(mTempMatrix, 0, mMatrices, mCurrentMatrixIndex, x, y, 0f);
  Matrix.scaleM(mTempMatrix, 0, width, height, 1f);
  Matrix.multiplyMM(mTempMatrix, MATRIX_SIZE, mProjectionMatrix, 0, mTempMatrix, 0);
  GLES20.glUniformMatrix4fv(params[INDEX_MATRIX].handle, 1, false, mTempMatrix, MATRIX_SIZE);
  checkError();
}

代码示例来源:origin: WeAreFairphone/FP2-Launcher

private void setMatrix(ShaderParameter[] params, float x, float y, float width, float height) {
  Matrix.translateM(mTempMatrix, 0, mMatrices, mCurrentMatrixIndex, x, y, 0f);
  Matrix.scaleM(mTempMatrix, 0, width, height, 1f);
  Matrix.multiplyMM(mTempMatrix, MATRIX_SIZE, mProjectionMatrix, 0, mTempMatrix, 0);
  GLES20.glUniformMatrix4fv(params[INDEX_MATRIX].handle, 1, false, mTempMatrix, MATRIX_SIZE);
  checkError();
}

代码示例来源:origin: dbrant/ModelViewer3D

protected void initModelMatrix(float boundSize, float rotateX, float rotateY, float rotateZ) {
  Matrix.setIdentityM(modelMatrix, 0);
  Matrix.rotateM(modelMatrix, 0, rotateX, 1.0f, 0.0f, 0.0f);
  Matrix.rotateM(modelMatrix, 0, rotateY, 0.0f, 1.0f, 0.0f);
  Matrix.rotateM(modelMatrix, 0, rotateZ, 0.0f, 0.0f, 1.0f);
  scaleModelMatrixToBounds(boundSize);
  Matrix.translateM(modelMatrix, 0, -centerMassX, -centerMassY, -centerMassZ);
}

相关文章