Java Code Examples for android.opengl.Matrix#scaleM()
The following examples show how to use
android.opengl.Matrix#scaleM() .
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: Object3DImpl.java From react-native-3d-model-view with MIT License | 6 votes |
public float[] getMMatrix(Object3DData obj) { // calculate object transformation Matrix.setIdentityM(mMatrix, 0); if (obj.getRotation() != null) { Matrix.rotateM(mMatrix, 0, obj.getRotation()[0], 1f, 0f, 0f); Matrix.rotateM(mMatrix, 0, obj.getRotation()[1], 0, 1f, 0f); Matrix.rotateM(mMatrix, 0, obj.getRotationZ(), 0, 0, 1f); } if (obj.getScale() != null) { Matrix.scaleM(mMatrix, 0, obj.getScaleX(), obj.getScaleY(),obj.getScaleZ()); } if (obj.getPosition() != null) { Matrix.translateM(mMatrix, 0, obj.getPositionX(), obj.getPositionY(), obj.getPositionZ()); } return mMatrix; }
Example 2
Source File: RendererCommon.java From VideoCRE with MIT License | 6 votes |
/** * Returns layout transformation matrix that applies an optional mirror effect and compensates * for video vs display aspect ratio. */ public static void getLayoutMatrix( final float matrix[], boolean mirror, float videoAspectRatio, float displayAspectRatio) { float scaleX = 1; float scaleY = 1; // Scale X or Y dimension so that video and display size have same aspect ratio. if (displayAspectRatio > videoAspectRatio) { scaleY = videoAspectRatio / displayAspectRatio; } else { scaleX = displayAspectRatio / videoAspectRatio; } // Apply optional horizontal flip. if (mirror) { scaleX *= -1; } Matrix.setIdentityM(matrix, 0); Matrix.scaleM(matrix, 0, scaleX, scaleY, 1); adjustOrigin(matrix); }
Example 3
Source File: DetailFilterActivity.java From GSYVideoPlayer with Apache License 2.0 | 6 votes |
@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 4
Source File: Object3DData.java From react-native-3d-model-view with MIT License | 5 votes |
private void updateModelMatrix(){ Matrix.setIdentityM(modelMatrix,0); Matrix.setRotateM(modelMatrix,0,getRotationX(),1,0,0); Matrix.setRotateM(modelMatrix,0,getRotationY(),0,1,0); Matrix.setRotateM(modelMatrix,0,getRotationY(),0,0,1); Matrix.scaleM(modelMatrix,0,getScaleX(),getScaleY(),getScaleZ()); Matrix.translateM(modelMatrix,0,getPositionX(),getPositionY(),getPositionZ()); }
Example 5
Source File: UiLayer.java From myMediaCodecPlayer-for-FPV with MIT License | 5 votes |
@Override void updateViewport(final Viewport viewport) { Matrix.setIdentityM(this.mMvp, 0); final float xScale = this.mLineThicknessPx / viewport.width; final float yScale = 1.0f - 2.0f * this.mVerticalBorderPaddingPx / viewport.height; Matrix.scaleM(this.mMvp, 0, xScale, yScale, 1.0f); }
Example 6
Source File: GLES20Canvas.java From LB-Launcher with Apache License 2.0 | 5 votes |
@Override public void setSize(int width, int height) { mWidth = width; mHeight = height; GLES20.glViewport(0, 0, mWidth, mHeight); checkError(); Matrix.setIdentityM(mMatrices, mCurrentMatrixIndex); Matrix.orthoM(mProjectionMatrix, 0, 0, width, 0, height, -1, 1); if (getTargetTexture() == null) { mScreenWidth = width; mScreenHeight = height; Matrix.translateM(mMatrices, mCurrentMatrixIndex, 0, height, 0); Matrix.scaleM(mMatrices, mCurrentMatrixIndex, 1, -1, 1); } }
Example 7
Source File: Sprite2d.java From pause-resume-video-recording with Apache License 2.0 | 5 votes |
/** * Re-computes mModelViewMatrix, based on the current values for rotation, scale, and * translation. */ private void recomputeMatrix() { float[] modelView = mModelViewMatrix; Matrix.setIdentityM(modelView, 0); Matrix.translateM(modelView, 0, mPosX, mPosY, 0.0f); if (mAngle != 0.0f) { Matrix.rotateM(modelView, 0, mAngle, 0.0f, 0.0f, 1.0f); } Matrix.scaleM(modelView, 0, mScaleX, mScaleY, 1.0f); mMatrixReady = true; }
Example 8
Source File: Sprite2d.java From VideoRecorder with Apache License 2.0 | 5 votes |
/** * Re-computes mModelViewMatrix, based on the current values for rotation, scale, and * translation. */ private void recomputeMatrix() { float[] modelView = mModelViewMatrix; Matrix.setIdentityM(modelView, 0); Matrix.translateM(modelView, 0, mPosX, mPosY, 0.0f); if (mAngle != 0.0f) { Matrix.rotateM(modelView, 0, mAngle, 0.0f, 0.0f, 1.0f); } Matrix.scaleM(modelView, 0, mScaleX, mScaleY, 1.0f); mMatrixReady = true; }
Example 9
Source File: GlUtil.java From PLDroidShortVideo with Apache License 2.0 | 5 votes |
public static float[] changeMVPMatrixCrop(float viewWidth, float viewHeight, float textureWidth, float textureHeight) { float scale = viewWidth * textureHeight / viewHeight / textureWidth; float[] mvp = new float[16]; Matrix.setIdentityM(mvp, 0); Matrix.scaleM(mvp, 0, scale > 1 ? 1F : (1F / scale), scale > 1 ? scale : 1F, 1F); return mvp; }
Example 10
Source File: CoordinateTransform.java From VideoRecorder with Apache License 2.0 | 5 votes |
/** * @param m 矩阵 * @param x x 是否翻转 * @param y y 是否翻转 * @return 镜面翻转矩阵 */ public static float[] flip(float[] m, boolean x, boolean y) { if (x || y) { Matrix.scaleM(m, 0, x ? -1 : 1, y ? -1 : 1, 1); } return m; }
Example 11
Source File: GLES20Canvas.java From android-openGL-canvas with Apache License 2.0 | 5 votes |
private void setMatrix(ShaderParameter[] params, float x, float y, float width, float height, ICustomMVPMatrix customMVPMatrix) { if (customMVPMatrix != null) { GLES20.glUniformMatrix4fv(params[INDEX_MATRIX].handle, 1, false, customMVPMatrix.getMVPMatrix(mScreenWidth, mScreenHeight, x, y, width, height), 0); checkError(); return; } GLES20.glViewport(0, 0, mScreenWidth, mScreenHeight); 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); printMatrix("translate matrix:", mTempMatrix, MATRIX_SIZE); GLES20.glUniformMatrix4fv(params[INDEX_MATRIX].handle, 1, false, mTempMatrix, MATRIX_SIZE); checkError(); }
Example 12
Source File: FullFrameRect.java From kickflip-android-sdk with Apache License 2.0 | 5 votes |
/** * Draws a viewport-filling rect, texturing it with the specified texture object. */ public void drawFrame(int textureId, float[] texMatrix) { // Use the identity matrix for MVP so our 2x2 FULL_RECTANGLE covers the viewport. synchronized (mDrawLock) { if (mCorrectVerticalVideo && !mScaleToFit && (requestedOrientation == SCREEN_ROTATION.VERTICAL || requestedOrientation == SCREEN_ROTATION.UPSIDEDOWN_VERTICAL)) { Matrix.scaleM(texMatrix, 0, 0.316f, 1.0f, 1f); } mProgram.draw(IDENTITY_MATRIX, mRectDrawable.getVertexArray(), 0, mRectDrawable.getVertexCount(), mRectDrawable.getCoordsPerVertex(), mRectDrawable.getVertexStride(), texMatrix, TEX_COORDS_BUF, textureId, TEX_COORDS_STRIDE); } }
Example 13
Source File: Sprite2d.java From RtmpPublisher with Apache License 2.0 | 5 votes |
/** * Re-computes mModelViewMatrix, based on the current values for rotation, scale, and * translation. */ private void recomputeMatrix() { float[] modelView = mModelViewMatrix; Matrix.setIdentityM(modelView, 0); Matrix.translateM(modelView, 0, mPosX, mPosY, 0.0f); if (mAngle != 0.0f) { Matrix.rotateM(modelView, 0, mAngle, 0.0f, 0.0f, 1.0f); } Matrix.scaleM(modelView, 0, mScaleX, mScaleY, 1.0f); mMatrixReady = true; }
Example 14
Source File: MatrixStack.java From panoramagl with Apache License 2.0 | 4 votes |
public void glScalef(float x, float y, float z) { Matrix.scaleM(mMatrix, mTop, x, y, z); }
Example 15
Source File: GlPreviewRenderer.java From GPUVideo-android with MIT License | 4 votes |
@Override public void onDrawFrame(GlFramebufferObject fbo) { if (drawScale != gestureScale) { float tempScale = 1 / drawScale; Matrix.scaleM(MMatrix, 0, tempScale, tempScale, 1); drawScale = gestureScale; Matrix.scaleM(MMatrix, 0, drawScale, drawScale, 1); } synchronized (this) { if (updateTexImageCompare != updateTexImageCounter) { // loop and call updateTexImage() for each time the onFrameAvailable() method was called below. while (updateTexImageCompare != updateTexImageCounter) { previewTexture.updateTexImage(); previewTexture.getTransformMatrix(STMatrix); updateTexImageCompare++; // increment the compare value until it's the same as _updateTexImageCounter } } } if (isNewShader) { if (glFilter != null) { glFilter.setup(); glFilter.setFrameSize(fbo.getWidth(), fbo.getHeight()); } isNewShader = false; } if (glFilter != null) { filterFramebufferObject.enable(); } GLES20.glClear(GL_COLOR_BUFFER_BIT); Matrix.multiplyMM(MVPMatrix, 0, VMatrix, 0, MMatrix, 0); Matrix.multiplyMM(MVPMatrix, 0, ProjMatrix, 0, MVPMatrix, 0); previewShader.draw(texName, MVPMatrix, STMatrix, aspectRatio); if (glFilter != null) { fbo.enable(); GLES20.glClear(GL_COLOR_BUFFER_BIT); glFilter.draw(filterFramebufferObject.getTexName(), fbo); } synchronized (this) { if (videoEncoder != null) { // notify to capturing thread that the camera frame is available. videoEncoder.frameAvailableSoon(texName, STMatrix, MVPMatrix, aspectRatio); } } }
Example 16
Source File: DecoderSurface.java From Mp4Composer-android with MIT License | 4 votes |
/** * Draws the data from SurfaceTexture onto the current EGL surface. */ void drawImage() { framebufferObject.enable(); GLES20.glViewport(0, 0, framebufferObject.getWidth(), framebufferObject.getHeight()); if (filter != null) { filterFramebufferObject.enable(); GLES20.glViewport(0, 0, filterFramebufferObject.getWidth(), filterFramebufferObject.getHeight()); GLES20.glClearColor(filter.getClearColor()[0], filter.getClearColor()[1], filter.getClearColor()[2], filter.getClearColor()[3]); } GLES20.glClear(GL_COLOR_BUFFER_BIT); Matrix.multiplyMM(MVPMatrix, 0, VMatrix, 0, MMatrix, 0); Matrix.multiplyMM(MVPMatrix, 0, ProjMatrix, 0, MVPMatrix, 0); float scaleDirectionX = flipHorizontal ? -1 : 1; float scaleDirectionY = flipVertical ? -1 : 1; float scale[]; switch (fillMode) { case PRESERVE_ASPECT_FIT: scale = FillMode.getScaleAspectFit(rotation.getRotation(), inputResolution.getWidth(), inputResolution.getHeight(), outputResolution.getWidth(), outputResolution.getHeight()); // Log.d(TAG, "scale[0] = " + scale[0] + " scale[1] = " + scale[1]); Matrix.scaleM(MVPMatrix, 0, scale[0] * scaleDirectionX, scale[1] * scaleDirectionY, 1); if (rotation != Rotation.NORMAL) { Matrix.rotateM(MVPMatrix, 0, -rotation.getRotation(), 0.f, 0.f, 1.f); } break; case PRESERVE_ASPECT_CROP: scale = FillMode.getScaleAspectCrop(rotation.getRotation(), inputResolution.getWidth(), inputResolution.getHeight(), outputResolution.getWidth(), outputResolution.getHeight()); Matrix.scaleM(MVPMatrix, 0, scale[0] * scaleDirectionX, scale[1] * scaleDirectionY, 1); if (rotation != Rotation.NORMAL) { Matrix.rotateM(MVPMatrix, 0, -rotation.getRotation(), 0.f, 0.f, 1.f); } break; case CUSTOM: if (fillModeCustomItem != null) { Matrix.translateM(MVPMatrix, 0, fillModeCustomItem.getTranslateX(), -fillModeCustomItem.getTranslateY(), 0f); scale = FillMode.getScaleAspectCrop(rotation.getRotation(), inputResolution.getWidth(), inputResolution.getHeight(), outputResolution.getWidth(), outputResolution.getHeight()); if (fillModeCustomItem.getRotate() == 0 || fillModeCustomItem.getRotate() == 180) { Matrix.scaleM(MVPMatrix, 0, fillModeCustomItem.getScale() * scale[0] * scaleDirectionX, fillModeCustomItem.getScale() * scale[1] * scaleDirectionY, 1); } else { Matrix.scaleM(MVPMatrix, 0, fillModeCustomItem.getScale() * scale[0] * (1 / fillModeCustomItem.getVideoWidth() * fillModeCustomItem.getVideoHeight()) * scaleDirectionX, fillModeCustomItem.getScale() * scale[1] * (fillModeCustomItem.getVideoWidth() / fillModeCustomItem.getVideoHeight()) * scaleDirectionY, 1); } Matrix.rotateM(MVPMatrix, 0, -(rotation.getRotation() + fillModeCustomItem.getRotate()), 0.f, 0.f, 1.f); // Log.d(TAG, "inputResolution = " + inputResolution.getWidth() + " height = " + inputResolution.getHeight()); // Log.d(TAG, "out = " + outputResolution.getWidth() + " height = " + outputResolution.getHeight()); // Log.d(TAG, "rotation = " + rotation.getRotation()); // Log.d(TAG, "scale[0] = " + scale[0] + " scale[1] = " + scale[1]); } default: break; } previewShader.draw(texName, MVPMatrix, STMatrix, 1f); if (filter != null) { // 一度shaderに描画したものを、fboを利用して、drawする。drawには必要なさげだけど。 framebufferObject.enable(); GLES20.glClear(GL_COLOR_BUFFER_BIT); filter.draw(filterFramebufferObject.getTexName(), framebufferObject); } //////////////////////////////////////////////////////////////////////////////////// GLES20.glBindFramebuffer(GL_FRAMEBUFFER, 0); GLES20.glViewport(0, 0, framebufferObject.getWidth(), framebufferObject.getHeight()); GLES20.glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); normalShader.draw(framebufferObject.getTexName(), null); }
Example 17
Source File: AnchorRenderer.java From justaline-android with Apache License 2.0 | 4 votes |
/** * Encapsulates the OpenGL ES instructions for drawing this shape. */ public void draw(float[] cameraView, float[] cameraPerspective, boolean changeColor) { Matrix.multiplyMM(mModelViewMatrix, 0, cameraView, 0, mModelMatrix, 0); Matrix.multiplyMM(mModelViewProjectionMatrix, 0, cameraPerspective, 0, mModelViewMatrix, 0); Matrix.scaleM(mModelViewProjectionMatrix, 0, 0.005f, 0.005f, 0.005f); if (mProgram != 0) { // Add program to OpenGL environment GLES20.glUseProgram(mProgram); // Get handle to vertex shader's vPosition member int mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition"); // Enable a handle to the triangle vertices GLES20.glEnableVertexAttribArray(mPositionHandle); // Get handle to fragment shader's vColor member int mColor = GLES20.glGetAttribLocation(mProgram, "vColor"); // Enable a handle to the color vertices GLES20.glEnableVertexAttribArray(mColor); // Get handle to shape's transformation matrix int mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); checkGlError("glGetUniformLocation"); // Apply the projection and view transformation GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mModelViewProjectionMatrix, 0); checkGlError("glUniformMatrix4fv"); // Prepare the coordinate data GLES20.glVertexAttribPointer( mPositionHandle, COORDS_PER_VERTEX, GLES20.GL_FLOAT, false, VERTEX_STRIDE, mVertexBuffer); // Prepare the color data if (changeColor) { GLES20.glVertexAttribPointer( mColor, COORDS_PER_COLORS, GLES20.GL_FLOAT, false, COLORS_STRIDE, mColor2Buffer); } else { GLES20.glVertexAttribPointer( mColor, COORDS_PER_COLORS, GLES20.GL_FLOAT, false, COLORS_STRIDE, mColor1Buffer); } // Draw the shape GLES20.glDrawElements( GLES20.GL_TRIANGLES, INDICES.length, GLES20.GL_UNSIGNED_SHORT, mIndexBuffer); // Disable vertex array GLES20.glDisableVertexAttribArray(mPositionHandle); // Disable color array GLES20.glDisableVertexAttribArray(mColor); } else { Log.i(TAG, "Bummer"); } }
Example 18
Source File: GLES20Canvas.java From PhotoMovie with Apache License 2.0 | 4 votes |
@Override public void scale(float sx, float sy, float sz) { Matrix.scaleM(mMatrices, mCurrentMatrixIndex, sx, sy, sz); }
Example 19
Source File: CubeMapRender.java From TraceByAmap with MIT License | 4 votes |
@Override public void onDrawFrame(GL10 gl) { if(cube != null) { Matrix.setIdentityM(mvp, 0); //偏移 PointF pointF = aMap.getProjection().toOpenGLLocation(center); Matrix.multiplyMM(mvp,0, aMap.getProjectionMatrix(),0,aMap.getViewMatrix(),0); Matrix.translateM(mvp, 0 , pointF.x , pointF.y , 0); int scale = 1; Matrix.scaleM(mvp, 0 , scale, scale, scale); cube.drawES20(mvp); } }
Example 20
Source File: Right.java From IjkVRPlayer with Apache License 2.0 | 4 votes |
public Right(Texture2dProgram program) { super(program); Matrix.setIdentityM(mModelMatrix, 0); Matrix.scaleM(mModelMatrix, 0, 0.5f, 0.5f, 0.5f); Matrix.translateM(mModelMatrix, 0, 1f, 0, 0); // translation to the right }