android.opengl.Matrix类的使用及代码示例

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

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

Matrix介绍

暂无

代码示例

代码示例来源:origin: google/ExoPlayer

public Renderer(SceneRenderer scene) {
 this.scene = scene;
 Matrix.setIdentityM(deviceOrientationMatrix, 0);
 Matrix.setIdentityM(touchPitchMatrix, 0);
 Matrix.setIdentityM(touchYawMatrix, 0);
 deviceRoll = UPRIGHT_ROLL;
}

代码示例来源:origin: google/ExoPlayer

@Override
public void onDrawFrame(GL10 gl) {
 // Combine touch & sensor data.
 // Orientation = pitch * sensor * yaw since that is closest to what most users expect the
 // behavior to be.
 synchronized (this) {
  Matrix.multiplyMM(tempMatrix, 0, deviceOrientationMatrix, 0, touchYawMatrix, 0);
  Matrix.multiplyMM(viewMatrix, 0, touchPitchMatrix, 0, tempMatrix, 0);
 }
 Matrix.multiplyMM(viewProjectionMatrix, 0, projectionMatrix, 0, viewMatrix, 0);
 scene.drawFrame(viewProjectionMatrix, EyeType.MONOCULAR);
}

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

@Override
  public void onDrawFrame(GL10 glUnused) {
    super.onDrawFrame(glUnused);
    float[] transform = new float[16];
    Matrix.setIdentityM(transform, 0);
    Matrix.scaleM(transform, 0, 0.8f, 0.8f, 1);
    GLES20.glUniformMatrix4fv(getMuMVPMatrixHandle(), 1, false, transform, 0);
    GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, 4);
    GLES20.glFinish();
  }
}

代码示例来源:origin: cats-oss/android-gpuimage

public GPUImageTransformFilter() {
  super(TRANSFORM_VERTEX_SHADER, NO_FILTER_FRAGMENT_SHADER);
  orthographicMatrix = new float[16];
  Matrix.orthoM(orthographicMatrix, 0, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
  transform3D = new float[16];
  Matrix.setIdentityM(transform3D, 0);
}

代码示例来源:origin: google/ExoPlayer

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

代码示例来源: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: 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: doggycoder/AndroidOpenGLDemo

@Override
public void onSurfaceChanged(GL10 gl, int width, int height) {
  //计算宽高比
  float ratio=(float)width/height;
  //设置透视投影
  Matrix.frustumM(mProjectMatrix, 0, -ratio, ratio, -1, 1, 3, 20);
  //设置相机位置
  Matrix.setLookAtM(mViewMatrix, 0, 5.0f, 5.0f, 10.0f, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
  //计算变换矩阵
  Matrix.multiplyMM(mMVPMatrix,0,mProjectMatrix,0,mViewMatrix,0);
}

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

public static void getCenterInsideMatrix(float[] matrix,int imgWidth,int imgHeight,int viewWidth,int
    viewHeight){
  if(imgHeight>0&&imgWidth>0&&viewWidth>0&&viewHeight>0){
    float sWhView=(float)viewWidth/viewHeight;
    float sWhImg=(float)imgWidth/imgHeight;
    float[] projection=new float[16];
    float[] camera=new float[16];
    if(sWhImg>sWhView){
      Matrix.orthoM(projection,0,-1,1,-sWhImg/sWhView,sWhImg/sWhView,1,3);
    }else{
      Matrix.orthoM(projection,0,-sWhView/sWhImg,sWhView/sWhImg,-1,1,1,3);
    }
    Matrix.setLookAtM(camera,0,0,0,1,0,0,0,0,1,0);
    Matrix.multiplyMM(matrix,0,projection,0,camera,0);
  }
}

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

@Test
public void multiplyIdentity() throws Exception {
 final float[] res = new float[16];
 final float[] i = new float[16];
 Matrix.setIdentityM(i, 0);
 final float[] m1 = new float[]{
     1, 2, 3, 4,
     5, 6, 7, 8,
     9, 10, 11, 12,
     13, 14, 15, 16
 };
 Matrix.multiplyMM(res, 0, m1, 0, i, 0);
 assertThat(res).usingExactEquality().containsAllOf(m1);
 Matrix.multiplyMM(res, 0, i, 0, m1, 0);
 assertThat(res).usingExactEquality().containsAllOf(m1);
}

代码示例来源:origin: pedroSG94/rtmp-rtsp-stream-client-java

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

代码示例来源:origin: pedroSG94/rtmp-rtsp-stream-client-java

public void setRotation(int rotation) {
 Matrix.setIdentityM(rotationMatrix, 0);
 Matrix.rotateM(rotationMatrix, 0, rotation, 0f, 0f, -1f);
 update();
}

代码示例来源: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);
}

代码示例来源: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: 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: CarGuo/GSYVideoPlayer

@Override
  public void initRenderSize() {
    Matrix.scaleM(mMVPMatrix, 0, 1f, 1f, 1);
  }
}

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

@Test
public void multiplyMVIdentity() throws Exception {
 final float[] res = new float[4];
 final float[] i = new float[16];
 Matrix.setIdentityM(i, 0);
 float[] v1 = new float[]{1, 2, 3, 4};
 Matrix.multiplyMV(res, 0, i, 0, v1, 0);
 assertThat(res).usingExactEquality().containsAllOf(v1);
}

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

public void setSize(int width,int height){
  //计算宽高比
  float ratio=(float)width/height;
  //设置透视投影
  //Matrix.frustumM(mProjectMatrix, 0, -ratio*skyRate, ratio*skyRate, -1*skyRate, 1*skyRate, 1, 200);
  //透视投影矩阵/视锥
  MatrixHelper.perspectiveM(mProjectMatrix,0,45,ratio,1f,300);
  //设置相机位置
  Matrix.setLookAtM(mViewMatrix, 0, 0f, 0.0f,0.0f, 0.0f, 0.0f,-1.0f, 0f,1.0f, 0.0f);
  //模型矩阵
  Matrix.setIdentityM(mModelMatrix,0);
  //Matrix.scaleM(mModelMatrix,0,2,2,2);
}

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

@Test
public void testRotateMInPlace() {
 float[] matrix = new float[]{
     1, 2, 3, 4,
     5, 6, 7, 8,
     9, 10, 11, 12,
     13, 14, 15, 16
 };
 float[] expected = new float[]{
     0.95625275f, 1.9625025f, 2.968752f, 3.9750016f,
     5.0910234f, 6.07802f, 7.0650167f, 8.052013f,
     8.953606f, 9.960234f, 10.966862f, 11.973489f,
     13, 14, 15, 16
 };
 Matrix.rotateM(matrix, 0, 2, 4, 6, 8);
 assertThat(matrix).usingExactEquality().containsAllOf(expected);
}

相关文章