public void onSurfaceChanged(GL10 unused, int width, int height) { GLES20.glViewport(0, 0, width, height); ratio = (float) width / height; // this projection matrix is applied to object coodinates // in the onDrawFrame() method Matrix.orthoM(mProjMatrix, 0, -ratio, ratio, -1, 1, 3, 7); muMVPMatrixHandle = GLES20.glGetUniformLocation(mProgram, "uMVPMatrix"); Matrix.setLookAtM(mVMatrix, 0, 0, 0, 3, 0f, 0f, 0f, 0f, 1.0f, 0.0f); engine.initGL(); GLES20.glUseProgram(mProgram); GLES20.glActiveTexture(GLES20.GL_TEXTURE0); GLES20.glUniform1i(mSampleHandle, 0); GLES20.glUniform1f(mOpacityHandle, 1f); GLES20.glVertexAttribPointer(maPositionHandle, 3, GLES20.GL_FLOAT, false, 12, quadCoordsBuf); GLES20.glEnableVertexAttribArray(maPositionHandle); GLES20.glVertexAttribPointer(maTexCoordsHandle, 2, GLES20.GL_FLOAT, false, 8, quadTexCoordsBuf); GLES20.glEnableVertexAttribArray(maTexCoordsHandle); initTextures(); }
// 设置正交投影参数 public static void setProjectOrtho( float left, // near面的left float right, // near面的right float bottom, // near面的bottom float top, // near面的top float near, // near面距离 float far // far面距离 ) { Matrix.orthoM(mProjMatrix, 0, left, right, bottom, top, near, far); }
public void setZoomLevel(float zoomLevel) { Matrix.orthoM( mProjectionMatrix, 0, -1.0f / zoomLevel, 1.0f / zoomLevel, -1.0f / zoomLevel, 1.0f / zoomLevel, 1.0f, 10.0f); }
private void __setup_matrices() { // Set up our projection matrix to ortho, so that left top is 0,0 Matrix.orthoM( m_projection_matrix, 0, // Matrix and offset 0, // Left FULLSCREEN_VIRTUAL_RESOLUTION_WIDTH, // Right FULLSCREEN_VIRTUAL_RESOLUTION_HEIGHT, // Bottom 0, // Top -1, // Near 1 // Far ); // Set the rest up to be identity Matrix.setIdentityM(m_view_matrix, 0); m_default_shader.set_projection_matrix(m_projection_matrix); m_default_shader.set_view_matrix(m_view_matrix); }
/** * Fine settings used to set the light view and projection matrixes. This method is very important * as it allows to improve greatly quality without CPU additional charge. Try to set zFar and * zNear as best as you can. A good practice is to bind a camera instance to each node instance * used as root node for shadow map generation. * * @param cameraNodeInstance The node owning the camera * @param cameraIndex The indew of the camera in the node instance */ @SuppressLint("NewApi") public void setCamera(final Node cameraNodeInstance, final int cameraIndex) { // android.util.Log.d(TAG,"setCamera("+cameraNodeInstance.id+","+cameraIndex+")"); if (cameraNodeInstance.cameraInstances[cameraIndex].type == Camera.ORTHOGRAPHIC) { Matrix.orthoM( lightMvpCache, 16, -cameraNodeInstance.cameraInstances[cameraIndex].settings[Camera.XMAG], cameraNodeInstance.cameraInstances[cameraIndex].settings[Camera.XMAG], -cameraNodeInstance.cameraInstances[cameraIndex].settings[Camera.YMAG], cameraNodeInstance.cameraInstances[cameraIndex].settings[Camera.YMAG], cameraNodeInstance.cameraInstances[cameraIndex].settings[Camera.ZNEAR], cameraNodeInstance.cameraInstances[cameraIndex].settings[Camera.ZFAR]); } else { MatrixUtils.perspectiveM( this.lightMvpCache, 16, cameraNodeInstance.cameraInstances[cameraIndex].settings[Camera.YFOV], 1, cameraNodeInstance.cameraInstances[cameraIndex].settings[Camera.ZNEAR], cameraNodeInstance.cameraInstances[cameraIndex].settings[Camera.ZFAR]); } }
@Override public void onSurfaceCreated(GL10 unused, EGLConfig config) { ShaderManager.getSingletonObject().unloadAll(); ShaderManager.getSingletonObject().cleanUp(); TextureManager.getSingletonObject().unloadAll(); TextureManager.getSingletonObject().cleanUp(); loadResources(); if (phenixLineProgram != null) { phenixLineProgram.load(); } ShaderManager.getSingletonObject().unloadAllShaders(); renderTextures = new RenderTexture[2]; frameBuffers = new FrameBuffer[2]; setupFrameBuffer(unused); Matrix.setLookAtM(V_matrix, 0, 0, 0, 1.0f, 0f, 0f, 0f, 0f, -1.0f, 0.0f); Matrix.orthoM(Q_matrix, 0, 0, 1, 0, 1, -1, 1); }
public void updateRation(float ratio) { Matrix.orthoM(projectionMatrix, 0, -ratio, ratio, -1, 1, 1, 140); }
public CameraGL(float ratio) { super(); Matrix.orthoM(projectionMatrix, 0, -ratio, ratio, -1, 1, 1, 140); }
/* (non-Javadoc) * @see fr.kesk.gl.shader.GlShader#compile() */ @Override public void compile() { // android.util.Log.d(TAG,"initialize()"); // Build program if needed if (this.program == null) { InputStream vertIn = null; InputStream fragIn = null; try { vertIn = this.getVertexShaderInputStream(); fragIn = this.getFragmentShaderInputStream(); this.program = new GlProgram(vertIn, fragIn); this.program.start(); // Context this.u_lightMvpMatrixMat4Handle = this.program.getUniformHandle("u_mvpMatrixMat4"); // Attributes this.a_PositionVec4Handle = this.program.getAttributeHandle("a_PositionVec4"); } finally { if (vertIn != null) { try { vertIn.close(); } catch (IOException ioe) { } } if (fragIn != null) { try { fragIn.close(); } catch (IOException ioe) { } } } } if (this.shadowTextures == null) { this.shadowTextures = new GlTextureSet(); } if (this.currentShadowMap == null) { this.newShadowMap(); } // Create FBO or reinitialize if (this.fbo == null) { this.fbo = new GlFrameBufferObject(); // Build shadow map this.fbo.attach(this.currentShadowMap, Attachment.TYPE_COLOR); this.fbo.attach( new GlRenderBufferObject(GLES20.GL_DEPTH_COMPONENT16, this.quality, this.quality), Attachment.TYPE_DEPTH); if (this.fbo.getStatus() != GlFrameBufferObject.STATUS_COMPLETE) { throw new GLException(0, "Failed to initialize FBO (status " + this.fbo.getStatus() + ")"); } } // Setup a default camera Matrix.orthoM(lightMvpCache, 16, -10, 10, -10, 10, 0.1f, 100f); // Default Light this.lightType = Light.DIRECTIONAL; this.lightModel[0] = this.lightModel[1] = this.lightModel[2] = 10f; this.lightModel[3] = 1f; this.lightModel[4] = this.lightModel[5] = this.lightModel[7] = 0f; this.lightModel[6] = -1f; }
public void setProjectionMatrix(int width, int height) { float aspect = (float) width / (float) height; Matrix.orthoM(mProjMatrix, 0, -aspect, aspect, -1, 1, getNearPlane(), getFarPlane()); mProjMatrix[15] = mZoom; }
public void glOrthof(float left, float right, float bottom, float top, float near, float far) { Matrix.orthoM(mMatrix, mTop, left, right, bottom, top, near, far); }
private void recomputeTransformMatrices() { float screenToBitmapAspectRatio = mAspectRatio / mBitmapAspectRatio; // Ensure the bitmap is wider than the screen relatively by applying zoom // if necessary. Vary width but keep height the same. float zoom = Math.max(1f, 1.15f * screenToBitmapAspectRatio); // Total scale factors in both zoom and scale due to aspect ratio. float totalScale = zoom / screenToBitmapAspectRatio; mCurrentViewport.left = MathUtil.interpolate( -1f * Math.min( 1f, screenToBitmapAspectRatio), // remove screenToBitmapAspectRatio to unconstrain // panning amount 1f * Math.min(1f, screenToBitmapAspectRatio), mNormalOffsetX * (totalScale - 1) / totalScale); mCurrentViewport.right = mCurrentViewport.left + 2f / totalScale; mCurrentViewport.bottom = -1f / zoom; mCurrentViewport.top = 1f / zoom; float focusAmount = (mBlurKeyframes - mBlurAnimator.currentValue()) / mBlurKeyframes; if (mBlurRelatedToArtDetailMode && focusAmount > 0) { RectF artDetailViewport = ArtDetailViewport.getInstance().getViewport(mId); if (artDetailViewport.width() == 0 || artDetailViewport.height() == 0) { if (!mDemoMode && !mPreview) { // reset art detail viewport ArtDetailViewport.getInstance() .setViewport( mId, MathUtil.uninterpolate(-1, 1, mCurrentViewport.left), MathUtil.uninterpolate(1, -1, mCurrentViewport.top), MathUtil.uninterpolate(-1, 1, mCurrentViewport.right), MathUtil.uninterpolate(1, -1, mCurrentViewport.bottom), false); } } else { // interpolate mCurrentViewport.left = MathUtil.interpolate( mCurrentViewport.left, MathUtil.interpolate(-1, 1, artDetailViewport.left), focusAmount); mCurrentViewport.top = MathUtil.interpolate( mCurrentViewport.top, MathUtil.interpolate(1, -1, artDetailViewport.top), focusAmount); mCurrentViewport.right = MathUtil.interpolate( mCurrentViewport.right, MathUtil.interpolate(-1, 1, artDetailViewport.right), focusAmount); mCurrentViewport.bottom = MathUtil.interpolate( mCurrentViewport.bottom, MathUtil.interpolate(1, -1, artDetailViewport.bottom), focusAmount); } } Matrix.orthoM( mPMatrix, 0, mCurrentViewport.left, mCurrentViewport.right, mCurrentViewport.bottom, mCurrentViewport.top, 1, 10); }