Java Code Examples for android.opengl.Matrix#perspectiveM()
The following examples show how to use
android.opengl.Matrix#perspectiveM() .
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: SphereReflector.java From In77Camera with MIT License | 6 votes |
@Override public void onDrawFrame(int textureId) { super.onDrawFrame(textureId); glSphereProgram.use(); sphere.uploadTexCoordinateBuffer(glSphereProgram.getTextureCoordinateHandle()); sphere.uploadVerticesBuffer(glSphereProgram.getPositionHandle()); Matrix.perspectiveM(projectionMatrix, 0, 90, ratio, 1f, 500f); Matrix.multiplyMM(modelViewMatrix, 0, viewMatrix, 0, modelMatrix, 0); Matrix.multiplyMM(mMVPMatrix, 0, projectionMatrix, 0, modelViewMatrix, 0); GLES20.glUniformMatrix4fv(glSphereProgram.getMVPMatrixHandle(), 1, false, mMVPMatrix, 0); TextureUtils.bindTexture2D(textureId, GLES20.GL_TEXTURE0,glSphereProgram.getTextureSamplerHandle(),0); sphere.draw(); }
Example 2
Source File: SphereReflector.java From Fatigue-Detection with MIT License | 6 votes |
@Override public void onDrawFrame(int textureId) { super.onDrawFrame(textureId); glSphereProgram.use(); sphere.uploadTexCoordinateBuffer(glSphereProgram.getTextureCoordinateHandle()); sphere.uploadVerticesBuffer(glSphereProgram.getPositionHandle()); Matrix.perspectiveM(projectionMatrix, 0, 90, ratio, 1f, 500f); Matrix.multiplyMM(modelViewMatrix, 0, viewMatrix, 0, modelMatrix, 0); Matrix.multiplyMM(mMVPMatrix, 0, projectionMatrix, 0, modelViewMatrix, 0); GLES20.glUniformMatrix4fv(glSphereProgram.getMVPMatrixHandle(), 1, false, mMVPMatrix, 0); TextureUtils.bindTexture2D(textureId, GLES20.GL_TEXTURE0,glSphereProgram.getTextureSamplerHandle(),0); sphere.draw(); }
Example 3
Source File: myRenderer.java From opengl with Apache License 2.0 | 5 votes |
@Override public void onSurfaceChanged(GL10 glUnused, int width, int height) { mWidth = width; mHeight = height; // Set the viewport GLES30.glViewport(0, 0, mWidth, mHeight); float aspect = (float) width / height; // this projection matrix is applied to object coordinates //no idea why 53.13f, it was used in another example and it worked. Matrix.perspectiveM(mProjectionMatrix, 0, 53.13f, aspect, Z_NEAR, Z_FAR); }
Example 4
Source File: RendererContext.java From Tanks with MIT License | 5 votes |
public void setCamera(Camera.Data value) { float eyeX = value.eye.getX(); float eyeY = value.eye.getY(); float eyeZ = value.eye.getZ(); float targetX = value.target.getX(); float targetY = value.target.getY(); float targetZ = value.target.getZ(); Matrix.setLookAtM(viewMatrix, 0, eyeX, eyeY, eyeZ, targetX, targetY, targetZ, 0.0f, 0.0f, 1.0f); Matrix.perspectiveM(projectionMatrix, 0, 60.0f, Renderer.getAspect(), 0.1f, 200.0f); Matrix.multiplyMM(projectionViewMatrix, 0, projectionMatrix, 0, viewMatrix, 0); }
Example 5
Source File: PCRenderer.java From tango with MIT License | 5 votes |
@Override public void onSurfaceChanged(GL10 gl, int width, int height) { GLES20.glViewport(0, 0, width, height); mCameraAspect = (float) width / height; Matrix.perspectiveM(mProjectionMatrix, 0, CAMERA_FOV, mCameraAspect, CAMERA_NEAR, CAMERA_FAR); }
Example 6
Source File: CN1Matrix4f.java From CodenameOne with GNU General Public License v2.0 | 5 votes |
public CN1Matrix4f makePerspective(float fovy, float aspect, float zNear, float zFar) { float[] m = new float[16]; Matrix.perspectiveM(m, 0, (float) (fovy * 180f / Math.PI), aspect, zNear, zFar); CN1Matrix4f out = new CN1Matrix4f(m); out.factory = this; return out; }
Example 7
Source File: PCRenderer.java From ParaViewTangoRecorder with Apache License 2.0 | 5 votes |
@Override public void onSurfaceChanged(GL10 gl, int width, int height) { GLES20.glViewport(0, 0, width, height); mCameraAspect = (float) width / height; Matrix.perspectiveM(mProjectionMatrix, 0, CAMERA_FOV, mCameraAspect, CAMERA_NEAR, CAMERA_FAR); }
Example 8
Source File: Renderer.java From ParaViewTangoRecorder with Apache License 2.0 | 5 votes |
public void setTopDownView() { viewId = TOP_DOWN; mCameraPosition[0] = 0; mCameraPosition[1] = 5; mCameraPosition[2] = 0; Matrix.perspectiveM(mProjectionMatrix, 0, TOPDOWN_FOV, mCameraAspect, CAMERA_NEAR, CAMERA_FAR); }
Example 9
Source File: Renderer.java From ParaViewTangoRecorder with Apache License 2.0 | 5 votes |
public void setThirdPersonView() { viewId = THIRD_PERSON; mCameraPosition[0] = 5; mCameraPosition[1] = 5; mCameraPosition[2] = 5; mRotationX = mRotationY = (float) (Math.PI / 4); mCameraOrbitRadius = 5.0f; Matrix.perspectiveM(mProjectionMatrix, 0, THIRD_PERSON_FOV, mCameraAspect, CAMERA_NEAR, CAMERA_FAR); }
Example 10
Source File: OpenGLRenderer.java From smartGL with Apache License 2.0 | 5 votes |
private void computeProjMatrix3D(float[] matrix3D) { // float ratio = (float) mWidth / (float) mHeight; // float near = 0.1f; // Matrix.frustumM(matrix3D, 0, -near, near, -near / ratio, near / ratio, near, 100); if (mCamera == null) { return; } float FOV = mCamera.getFOV(); final float near = mCamera.getNear(); final float far = mCamera.getFar(); float ratio = (float) getWidth() / (float) getHeight(); Matrix.perspectiveM(matrix3D, 0, FOV, ratio, near, far); // Rotation float ox = -mCamera.getRotX(); float oy = -mCamera.getRotY(); float oz = -mCamera.getRotZ(); if (ox != 0) Matrix.rotateM(matrix3D, 0, ox, 1, 0, 0); if (oy != 0) Matrix.rotateM(matrix3D, 0, oy, 0, 1, 0); if (oz != 0) Matrix.rotateM(matrix3D, 0, oz, 0, 0, 1); // Translation float x = -mCamera.getPosX(); float y = -mCamera.getPosY(); float z = -mCamera.getPosZ(); Matrix.translateM(matrix3D, 0, x, y, z); mCamera.setDirty(false); }
Example 11
Source File: myRenderer.java From opengl with Apache License 2.0 | 5 votes |
public void onSurfaceChanged(GL10 glUnused, int width, int height) { mWidth = width; mHeight = height; // Set the viewport GLES30.glViewport(0, 0, mWidth, mHeight); float aspect = (float) width / height; // this projection matrix is applied to object coordinates //no idea why 53.13f, it was used in another example and it worked. Matrix.perspectiveM(mProjectionMatrix, 0, 53.13f, aspect, Z_NEAR, Z_FAR); }
Example 12
Source File: ShapeView.java From OpenGLESRecorder with Apache License 2.0 | 5 votes |
@Override public void onSurfaceChanged(GL10 gl, int width, int height) { GLRecoder.init(width, height,mEglConfig); try { GLRecoder.startEncoder(new File("/sdcard/zzzzzzz.mp4")); } catch (IOException e1) { e1.printStackTrace(); } sScreenWidth = width; sScreenHeight = height; GLES20.glViewport(0, 0, width, height); Matrix.perspectiveM(mProjectionMatrix, 0, 45, (float)width/height, 2, 5); Matrix.setLookAtM(mViewMatrix, 0, 0, 0, 3, 0, 0, 0, 0, 1, 0); }
Example 13
Source File: DemoRenderer.java From LearnOpenGL with MIT License | 5 votes |
@Override public void onSurfaceChanged(GL10 unused, int width, int height) { GLES20.glViewport(0, 0, width, height); Matrix.perspectiveM(mProjectionMatrix, 0, 45, (float) width / height, 1f, 10f); Matrix.setIdentityM(mModelMatrix, 0); Matrix.translateM(mModelMatrix, 0, 0f, 0f, -2.5f); Matrix.rotateM(mModelMatrix, 0, -60f, 1f, 0f, 0f); Matrix.multiplyMM(mTmpMatrix, 0, mProjectionMatrix, 0, mModelMatrix, 0); System.arraycopy(mTmpMatrix, 0, mProjectionMatrix, 0, mTmpMatrix.length); }
Example 14
Source File: GLDrawer.java From Building-Android-UIs-with-Custom-Views with MIT License | 5 votes |
@Override public void onSurfaceChanged(GL10 unused, int width, int height) { GLES20.glViewport(0, 0, width, height); float ratio = (float) width / height; Matrix.perspectiveM(mProjectionMatrix, 0, 90, ratio, 0.1f, 7.f); }
Example 15
Source File: GLDrawer.java From Building-Android-UIs-with-Custom-Views with MIT License | 5 votes |
@Override public void onSurfaceChanged(GL10 unused, int width, int height) { GLES20.glViewport(0, 0, width, height); float ratio = (float) width / height; Matrix.perspectiveM(mProjectionMatrix, 0, 90, ratio, 0.1f, 7.f); }
Example 16
Source File: myRenderer.java From opengl with Apache License 2.0 | 5 votes |
public void onSurfaceChanged(GL10 glUnused, int width, int height) { mWidth = width; mHeight = height; // Set the viewport GLES30.glViewport(0, 0, mWidth, mHeight); float aspect = (float) width / height; // this projection matrix is applied to object coordinates //no idea why 53.13f, it was used in another example and it worked. Matrix.perspectiveM(mProjectionMatrix, 0, 53.13f, aspect, Z_NEAR, Z_FAR); }
Example 17
Source File: Sphere2DPlugin.java From Pano360 with MIT License | 4 votes |
@Override public void onDrawFrame(int textureId) { GLES20.glEnable(GLES20.GL_DEPTH_TEST); glSphereProgram.use(); sphere.uploadTexCoordinateBuffer(glSphereProgram.getTextureCoordinateHandle()); sphere.uploadVerticesBuffer(glSphereProgram.getPositionHandle()); float currentDegree= (float) (Math.toDegrees(Math.atan(mScale))*2); if(statusHelper.getPanoDisPlayMode()== PanoMode.DUAL_SCREEN) Matrix.perspectiveM(projectionMatrix, 0, currentDegree, ratio/2, 1f, 500f); else Matrix.perspectiveM(projectionMatrix, 0, currentDegree, ratio, 1f, 500f); Matrix.setIdentityM(modelMatrix, 0); if (statusHelper.getPanoInteractiveMode()==PanoMode.MOTION){ orientationHelper.recordRotation(rotationMatrix); System.arraycopy(rotationMatrix, 0, modelMatrix, 0, 16); orientationHelper.revertRotation(modelMatrix); } else{ Matrix.rotateM(modelMatrix, 0, mDeltaY, 1.0f, 0.0f, 0.0f); Matrix.rotateM(modelMatrix, 0, mDeltaX, 0.0f, 1.0f, 0.0f); } Matrix.multiplyMM(modelViewMatrix, 0, viewMatrix, 0, modelMatrix, 0); Matrix.multiplyMM(mMVPMatrix, 0, projectionMatrix, 0, modelViewMatrix, 0); GLES20.glUniformMatrix4fv(glSphereProgram.getMVPMatrixHandle(), 1, false, mMVPMatrix, 0); TextureUtils.bindTexture2D(textureId,GLES20.GL_TEXTURE0,glSphereProgram.getTextureSamplerHandle(),0); onPreDrawElements(); if (statusHelper.getPanoDisPlayMode()== PanoMode.DUAL_SCREEN){ GLES20.glViewport(0,0,surfaceWidth/2,surfaceHeight); sphere.draw(); GLES20.glViewport(surfaceWidth/2,0,surfaceWidth-surfaceWidth/2,surfaceHeight); sphere.draw(); drawHotSpot(); GLES20.glViewport(0,0,surfaceWidth/2,surfaceHeight); drawHotSpot(); }else{ GLES20.glViewport(0,0,surfaceWidth,surfaceHeight); sphere.draw(); drawHotSpot(); } GLES20.glDisable(GLES20.GL_DEPTH_TEST); }
Example 18
Source File: SphericalViewRenderer.java From DeviceConnect-Android with MIT License | 4 votes |
private synchronized void draw(final Camera camera) { Matrix.setIdentityM(mModelMatrix, 0); Matrix.setIdentityM(mViewMatrix, 0); Matrix.setIdentityM(mProjectionMatrix, 0); if (mTextureUpdate && null != mTexture && !mTexture.isRecycled()) { if (mTextures[0] != 0) { GLES20.glDeleteTextures(1, mTextures, 0); } loadTexture(mTexture); mTextureUpdate = false; } float x = camera.getPosition().x(); float y = camera.getPosition().y(); float z = camera.getPosition().z(); float frontX = camera.getFrontDirection().x(); float frontY = camera.getFrontDirection().y(); float frontZ = camera.getFrontDirection().z(); float upX = camera.getUpperDirection().x(); float upY = camera.getUpperDirection().y(); float upZ = camera.getUpperDirection().z(); float fov = camera.mFovDegree; if (mFlipVertical) { frontY *= -1; } Matrix.setLookAtM(mViewMatrix, 0, x, y, z, frontX, frontY, frontZ, upX, upY, upZ); Matrix.perspectiveM(mProjectionMatrix, 0, fov, getScreenAspect(), Z_NEAR, Z_FAR); GLES20.glUniformMatrix4fv(mModelMatrixHandle, 1, false, mModelMatrix, 0); GLES20.glUniformMatrix4fv(mProjectionMatrixHandle, 1, false, mProjectionMatrix, 0); GLES20.glUniformMatrix4fv(mViewMatrixHandle, 1, false, mViewMatrix, 0); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, mTextures[0]); GLES20.glUniform1i(mTexHandle, 0); mShell.draw(mPositionHandle, mUVHandle); }
Example 19
Source File: Renderer.java From ParaViewTangoRecorder with Apache License 2.0 | 4 votes |
public void setFirstPersonView() { viewId = FIRST_PERSON; Matrix.perspectiveM(mProjectionMatrix, 0, CAMERA_FOV, mCameraAspect, CAMERA_NEAR, CAMERA_FAR); }
Example 20
Source File: CN1Matrix4f.java From CodenameOne with GNU General Public License v2.0 | 4 votes |
public void setPerspective(float fovy, float aspect, float zNear, float zFar) { Matrix.perspectiveM(data, 0, (float) (fovy * 180f / Math.PI), aspect, zNear, zFar); type = TYPE_UNKNOWN; }