Java Code Examples for android.opengl.Matrix#setIdentityM()
The following examples show how to use
android.opengl.Matrix#setIdentityM() .
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: RenderHandler.java From Tok-Android with GNU General Public License v3.0 | 6 votes |
public final void setEglContext(final EGLContext shared_context, final int tex_id, final Object surface, final boolean isRecordable) { if (DEBUG) Log.i(TAG, "setEglContext:"); if (!(surface instanceof Surface) && !(surface instanceof SurfaceTexture) && !(surface instanceof SurfaceHolder)) throw new RuntimeException("unsupported window type:" + surface); synchronized (mSync) { if (mRequestRelease) return; mShard_context = shared_context; mTexId = tex_id; mSurface = surface; mIsRecordable = isRecordable; mRequestSetEglContext = true; Matrix.setIdentityM(mMatrix, 0); Matrix.setIdentityM(mMatrix, 16); mSync.notifyAll(); try { mSync.wait(); } catch (final InterruptedException e) { } } }
Example 2
Source File: GLDrawer2D.java From libcommon with Apache License 2.0 | 6 votes |
/** * コンストラクタ * GLコンテキスト/EGLレンダリングコンテキストが有効な状態で呼ばないとダメ * @param vertices 頂点座標, floatを8個 = (x,y) x 4ペア * @param texcoord テクスチャ座標, floatを8個 = (s,t) x 4ペア * @param isOES 外部テクスチャ(GL_TEXTURE_EXTERNAL_OES)を描画に使う場合はtrue。 * 通常の2Dテキスチャを描画に使うならfalse */ protected GLDrawer2D(final boolean isGLES3, final float[] vertices, final float[] texcoord, final boolean isOES) { if (DEBUG) Log.v(TAG, "コンストラクタ:isGLES3=" + isGLES3 + ",isOES=" + isOES); this.isGLES3 = isGLES3; VERTEX_NUM = Math.min( vertices != null ? vertices.length : 0, texcoord != null ? texcoord.length : 0) / 2; VERTEX_SZ = VERTEX_NUM * 2; mTexTarget = isOES ? GL_TEXTURE_EXTERNAL_OES : GL_TEXTURE_2D; pVertex = BufferHelper.createFloatBuffer(vertices); pTexCoord = BufferHelper.createFloatBuffer(texcoord); // モデルビュー変換行列を初期化 Matrix.setIdentityM(mMvpMatrix, 0); resetShader(); }
Example 3
Source File: FrameRotationQueue.java From Telegram-FOSS with GNU General Public License v2.0 | 6 votes |
/** * Computes a recentering matrix from the given angle-axis rotation only accounting for yaw. Roll * and tilt will not be compensated. * * @param recenterMatrix The recenter matrix. * @param rotationMatrix The rotation matrix. */ public static void computeRecenterMatrix(float[] recenterMatrix, float[] rotationMatrix) { // The re-centering matrix is computed as follows: // recenter.row(2) = temp.col(2).transpose(); // recenter.row(0) = recenter.row(1).cross(recenter.row(2)).normalized(); // recenter.row(2) = recenter.row(0).cross(recenter.row(1)).normalized(); // | temp[10] 0 -temp[8] 0| // | 0 1 0 0| // recenter = | temp[8] 0 temp[10] 0| // | 0 0 0 1| Matrix.setIdentityM(recenterMatrix, 0); float normRowSqr = rotationMatrix[10] * rotationMatrix[10] + rotationMatrix[8] * rotationMatrix[8]; float normRow = (float) Math.sqrt(normRowSqr); recenterMatrix[0] = rotationMatrix[10] / normRow; recenterMatrix[2] = rotationMatrix[8] / normRow; recenterMatrix[8] = -rotationMatrix[8] / normRow; recenterMatrix[10] = rotationMatrix[10] / normRow; }
Example 4
Source File: FrameBufferObjectRenderer.java From SimpleVideoEdit with Apache License 2.0 | 6 votes |
public void onSurfaceChanged(int width, int height){ Log.d(TAG, "onSurfaceChanged width = " + width + " height = " + height); filterFramebufferObject.setup(width, height); previewFilter.setFrameSize(width, height); if (glFilter != null) { glFilter.setFrameSize(width, height); } /* * Projection and camera view in OpenGL ES 2.0: Second Step: * First Step is in GlPreviewFilter.java where we declare the vertex shader with uMVPMatrix * create a projection matrix from device screen geometry * */ aspectRatio = (float) width / height; Matrix.frustumM(ProjMatrix, 0, -aspectRatio, aspectRatio, -1, 1, 5, 7); Matrix.setIdentityM(MMatrix, 0); }
Example 5
Source File: Animator.java From react-native-3d-model-view with MIT License | 6 votes |
/** * This method should be called each frame to update the animation currently * being played. This increases the animation time (and loops it back to * zero if necessary), finds the pose that the entity should be in at that * time of the animation, and then applies that pose to all the model's * joints by setting the joint transforms. */ public void update(Object3DData obj) { if (!this.play) { return; } if (!(obj instanceof AnimatedModel)) { return; } AnimatedModel animatedModel = (AnimatedModel)obj; if (animatedModel.getAnimation() == null) return; initAnimation(animatedModel); increaseAnimationTime((AnimatedModel)obj); Map<String, float[]> currentPose = calculateCurrentAnimationPose(animatedModel); float parentTransform[] = new float[16]; Matrix.setIdentityM(parentTransform,0); applyPoseToJoints(currentPose, (animatedModel).getRootJoint(), parentTransform); }
Example 6
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 7
Source File: ObjectRenderer.java From react-native-arcore with MIT License | 5 votes |
/** * Updates the object model matrix and applies scaling. * * @param modelMatrix A 4x4 model-to-world transformation matrix, stored in column-major order. * @param scaleFactor A separate scaling factor to apply before the {@code modelMatrix}. * @see Matrix */ public void updateModelMatrix(float[] modelMatrix, float scaleFactor) { float[] scaleMatrix = new float[16]; Matrix.setIdentityM(scaleMatrix, 0); scaleMatrix[0] = scaleFactor; scaleMatrix[5] = scaleFactor; scaleMatrix[10] = scaleFactor; Matrix.multiplyMM(mModelMatrix, 0, modelMatrix, 0, scaleMatrix, 0); }
Example 8
Source File: ContrastFilterRender.java From rtmp-rtsp-stream-client-java with Apache License 2.0 | 5 votes |
public ContrastFilterRender() { squareVertex = ByteBuffer.allocateDirect(squareVertexDataFilter.length * FLOAT_SIZE_BYTES) .order(ByteOrder.nativeOrder()) .asFloatBuffer(); squareVertex.put(squareVertexDataFilter).position(0); Matrix.setIdentityM(MVPMatrix, 0); Matrix.setIdentityM(STMatrix, 0); }
Example 9
Source File: LessonOneRenderer.java From opengl with Apache License 2.0 | 5 votes |
@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); // 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); }
Example 10
Source File: TextureRender.java From phoenix with Apache License 2.0 | 5 votes |
public TextureRender() { mTriangleVertices = ByteBuffer.allocateDirect( mTriangleVerticesData.length * FLOAT_SIZE_BYTES) .order(ByteOrder.nativeOrder()).asFloatBuffer(); mTriangleVertices.put(mTriangleVerticesData).position(0); Matrix.setIdentityM(mSTMatrix, 0); }
Example 11
Source File: BlackFilterRender.java From rtmp-rtsp-stream-client-java with Apache License 2.0 | 5 votes |
public BlackFilterRender() { squareVertex = ByteBuffer.allocateDirect(squareVertexDataFilter.length * FLOAT_SIZE_BYTES) .order(ByteOrder.nativeOrder()) .asFloatBuffer(); squareVertex.put(squareVertexDataFilter).position(0); Matrix.setIdentityM(MVPMatrix, 0); Matrix.setIdentityM(STMatrix, 0); }
Example 12
Source File: GLDrawer2D.java From Tok-Android with GNU General Public License v3.0 | 5 votes |
/** * Constructor * this should be called in GL context */ public GLDrawer2D() { pVertex = ByteBuffer.allocateDirect(VERTEX_SZ * FLOAT_SZ) .order(ByteOrder.nativeOrder()) .asFloatBuffer(); pVertex.put(VERTICES); pVertex.flip(); pTexCoord = ByteBuffer.allocateDirect(VERTEX_SZ * FLOAT_SZ) .order(ByteOrder.nativeOrder()) .asFloatBuffer(); pTexCoord.put(TEXCOORD); pTexCoord.flip(); hProgram = loadShader(vss, fss); GLES20.glUseProgram(hProgram); maPositionLoc = GLES20.glGetAttribLocation(hProgram, "aPosition"); maTextureCoordLoc = GLES20.glGetAttribLocation(hProgram, "aTextureCoord"); muMVPMatrixLoc = GLES20.glGetUniformLocation(hProgram, "uMVPMatrix"); muTexMatrixLoc = GLES20.glGetUniformLocation(hProgram, "uTexMatrix"); Matrix.setIdentityM(mMvpMatrix, 0); GLES20.glUniformMatrix4fv(muMVPMatrixLoc, 1, false, mMvpMatrix, 0); GLES20.glUniformMatrix4fv(muTexMatrixLoc, 1, false, mMvpMatrix, 0); GLES20.glVertexAttribPointer(maPositionLoc, 2, GLES20.GL_FLOAT, false, VERTEX_SZ, pVertex); GLES20.glVertexAttribPointer(maTextureCoordLoc, 2, GLES20.GL_FLOAT, false, VERTEX_SZ, pTexCoord); GLES20.glEnableVertexAttribArray(maPositionLoc); GLES20.glEnableVertexAttribArray(maTextureCoordLoc); }
Example 13
Source File: GLLabelProvider.java From Tanks with MIT License | 5 votes |
private void tryRebuildMatrix() { if (!needRebuildMatrix) return; Matrix.setIdentityM(modelMatrix, 0); Matrix.translateM(modelMatrix, 0, position.getX(), position.getY(), position.getZ()); Matrix.rotateM(modelMatrix, 0, angle, 0, 0, 1); needRebuildMatrix = false; }
Example 14
Source File: PixelatedFilterRender.java From rtmp-rtsp-stream-client-java with Apache License 2.0 | 5 votes |
public PixelatedFilterRender() { squareVertex = ByteBuffer.allocateDirect(squareVertexDataFilter.length * FLOAT_SIZE_BYTES) .order(ByteOrder.nativeOrder()) .asFloatBuffer(); squareVertex.put(squareVertexDataFilter).position(0); Matrix.setIdentityM(MVPMatrix, 0); Matrix.setIdentityM(STMatrix, 0); }
Example 15
Source File: GlUtil.java From PLDroidShortVideo with Apache License 2.0 | 5 votes |
public static float[] changeMVPMatrixInside(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 / scale) : 1F, scale > 1 ? 1F : scale, 1F); return mvp; }
Example 16
Source File: MD360Director.java From MD360Player4Android with Apache License 2.0 | 5 votes |
private void updateCameraMatrix() { final float eyeX = mCamera.getEyeX() + mCameraUpdate.getEyeX(); final float eyeY = mCamera.getEyeY() + mCameraUpdate.getEyeY(); final float eyeZ = mCamera.getEyeZ() + mCameraUpdate.getEyeZ(); final float lookX = mCamera.getLookX() + mCameraUpdate.getLookX(); final float lookY = mCamera.getLookY() + mCameraUpdate.getLookY(); final float lookZ = -1.0f; final float upX = 0.0f; final float upY = 1.0f; final float upZ = 0.0f; Matrix.setIdentityM(mCameraMatrix, 0); Matrix.setLookAtM(mCameraMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ); }
Example 17
Source File: Sprite2d.java From FuAgoraDemoDroid with MIT License | 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 18
Source File: TextureRenderer.java From Telegram with GNU General Public License v2.0 | 4 votes |
public TextureRenderer(int rotation, MediaController.SavedFilterState savedFilterState, String image, String paint, ArrayList<VideoEditedInfo.MediaEntity> entities, int w, int h, float fps, boolean photo) { rotationAngle = rotation; isPhoto = photo; float[] verticesData = { -1.0f, -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, 1.0f, 1.0f, }; float[] texData = { 0.f, 0.f, 1.f, 0.f, 0.f, 1.f, 1.f, 1.f, }; verticesBuffer = ByteBuffer.allocateDirect(verticesData.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer(); verticesBuffer.put(verticesData).position(0); textureBuffer = ByteBuffer.allocateDirect(texData.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer(); textureBuffer.put(texData).position(0); verticesBuffer = ByteBuffer.allocateDirect(verticesData.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer(); verticesBuffer.put(verticesData).position(0); bitmapVerticesBuffer = ByteBuffer.allocateDirect(bitmapData.length * 4).order(ByteOrder.nativeOrder()).asFloatBuffer(); bitmapVerticesBuffer.put(bitmapData).position(0); Matrix.setIdentityM(mSTMatrix, 0); if (savedFilterState != null) { filterShaders = new FilterShaders(true); filterShaders.setDelegate(FilterShaders.getFilterShadersDelegate(savedFilterState)); } videoWidth = w; videoHeight = h; imagePath = image; paintPath = paint; mediaEntities = entities; videoFps = fps == 0 ? 30 : fps; }
Example 19
Source File: OrthoFilter.java From In77Camera with MIT License | 4 votes |
public OrthoFilter(Context context) { super(); glPassThroughProgram=new GLPassThroughProgram(context); Matrix.setIdentityM(projectionMatrix,0); }
Example 20
Source File: SingleEGLImageModel.java From VIA-AI with MIT License | 4 votes |
public void draw(int index, boolean fourInOne, boolean b1x4,boolean luminance) { Matrix.orthoM(projectMatrix, 0, -1, 1, -1, 1, -1, 1); Matrix.setIdentityM(viewMatrix, 0); Matrix.multiplyMM(mvpMatrix, 0, projectMatrix, 0, viewMatrix, 0); if (luminance == true) { GLES20.glUseProgram(this.mProgram_Luminance); GLUtility.checkGlError("glUseProgram"); } else { GLES20.glUseProgram(this.mProgram); GLUtility.checkGlError("glUseProgram"); } // Set the face rotation GLES20.glFrontFace(GLES20.GL_CW); GLUtility.checkGlError("glFrontFace"); // get handle to vertex shader's vPosition member int mPositionHandle = GLES20.glGetAttribLocation(mProgram, "vPosition"); GLUtility.checkGlError("glGetAttribLocation"); // Enable a handle to the triangle vertices GLES20.glEnableVertexAttribArray(mPositionHandle); GLUtility.checkGlError("glEnableVertexAttribArray"); // Bind VBO Position GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mPositionVBO[0]); GLUtility.checkGlError("glBindBuffer"); GLES20.glVertexAttribPointer( mPositionHandle, 3, GLES20.GL_FLOAT, false, 0, 0); GLUtility.checkGlError("glVertexAttribPointer"); // Get handle to mTextureCoordinate coordinates location int mTexCoordHandle = GLES20.glGetAttribLocation(mProgram, "aTexCoord"); GLUtility.checkGlError("glGetAttribLocation"); // Enable generic vertex attribute array GLES20.glEnableVertexAttribArray(mTexCoordHandle); GLUtility.checkGlError("glEnableVertexAttribArray"); // Bind VBO Texture Coordinate if (fourInOne == false) { GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mTextureCoordinateVBO[0]); GLUtility.checkGlError("glBindBuffer"); } else { if(b1x4) { GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mTextureCoordinateMergeVBO1x4[index]); } else { GLES20.glBindBuffer(GLES20.GL_ARRAY_BUFFER, mTextureCoordinateMergeVBO2x2[index]); } GLUtility.checkGlError("glBindBuffer"); } GLES20.glVertexAttribPointer( mTexCoordHandle, 2, GLES20.GL_FLOAT, false, 0, 0); GLUtility.checkGlError("glVertexAttribPointer"); // get handle to shape's transformation matrix int mMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); GLUtility.checkGlError("glGetUniformLocation"); // Apply the projection and view transformation GLES20.glUniformMatrix4fv(mMVPMatrixHandle, 1, false, mvpMatrix, 0); GLUtility.checkGlError("glUniformMatrix4fv"); // Get handle to mTextureObject locations int mTexSamplerHandle = GLES20.glGetUniformLocation(mProgram, "sTexture"); GLUtility.checkGlError("glGetUniformLocation"); // Set the sampler mTextureCoordinate unit to 0, where we have saved the mTextureCoordinate. GLES20.glUniform1i(mTexSamplerHandle, 0); GLUtility.checkGlError("glUniform1i"); GLES20.glDrawArrays(GLES20.GL_TRIANGLE_STRIP, 0, mPosition.length / 3); GLUtility.checkGlError("glDrawArrays"); // Disable vertex array GLES20.glDisableVertexAttribArray(mPositionHandle); GLUtility.checkGlError("glDisableVertexAttribArray"); GLES20.glDisableVertexAttribArray(mTexCoordHandle); GLUtility.checkGlError("glDisableVertexAttribArray"); }