Java Code Examples for android.opengl.Matrix#orthoM()

The following examples show how to use android.opengl.Matrix#orthoM() . 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: MakeupProgramLandmarks.java    From sealrtc-android with MIT License 6 votes vote down vote up
public void refresh(float[] landmarksData, int width, int height) {
    if (mWidth != width || mHeight != height) {
        float[] orthoMtx = new float[16];
        float[] rotateMtx = new float[16];
        Matrix.orthoM(orthoMtx, 0, 0, width, 0, height, -1, 1);
        Matrix.setRotateM(rotateMtx, 0, 180, 1.0f, 0.0f, 0.0f);
        Matrix.multiplyMM(mvpMtx, 0, rotateMtx, 0, orthoMtx, 0);

        mWidth = width;
        mHeight = height;
    }
    if (mLandmarks == null || mLandmarks.length != landmarksData.length) {
        mLandmarks = new float[landmarksData.length];
    }
    System.arraycopy(landmarksData, 0, mLandmarks, 0, landmarksData.length);
    updateVertexArray(mLandmarks);
}
 
Example 2
Source File: GLRenderer.java    From bombsquad-remote-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onSurfaceChanged(GL10 unused, int width, int height) {
  // Adjust the viewport based on geometry changes,
  // such as screen rotation
  GLES20.glViewport(0, 0, width, height);

  _ratio = (float) width / height;
  //Log.v(TAG,"SETTING RATIO "+_ratio);
  // this projection matrix is applied to object coordinates
  // in the onDrawFrame() method
  //Matrix.frustumM(mProjMatrix, 0, -ratio, ratio, -1, 1, 3, 7);
  Matrix.orthoM(mProjMatrix, 0, -1, 1, -1 / _ratio, 1 / _ratio, -1, 1);
  //printMat(mProjMatrix,"ORTHO");
}
 
Example 3
Source File: GLES20DrawContext.java    From settlers-remake with MIT License 5 votes vote down vote up
@Override
public void reinit(int width, int height) {
	GLES20.glViewport(0, 0, width, height);

	Matrix.setIdentityM(mat, 0);
	Matrix.orthoM(mat, 0, 0, width, 0, height, -1, 1);

	for(ShaderProgram shader : shaders) {
		useProgram(shader);
		GLES20.glUniformMatrix4fv(shader.ufs[PROJ], 1, false, mat, 0);
	}
}
 
Example 4
Source File: GLES20Canvas.java    From PhotoMovie with Apache License 2.0 5 votes vote down vote up
@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 5
Source File: RendererContext.java    From Tanks with MIT License 5 votes vote down vote up
public RendererContext()
{
  viewMatrix = new float[16];
  projectionMatrix = new float[16];
  projectionViewMatrix = new float[16];

  orthoMatrix = new float[16];
  Matrix.setIdentityM(orthoMatrix, 0);
  Matrix.orthoM(orthoMatrix, 0, Renderer.Left, Renderer.Right, Renderer.Bottom, Renderer.Top, -1, 1);

  lightData = new Light.Data();
}
 
Example 6
Source File: PlaneProjection.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void updateProjection(){
    planeScaleCalculator.setViewportRatio(getRatio());
    planeScaleCalculator.calculate();
    float scale = sNearBase / getNear();
    final float left = - planeScaleCalculator.getViewportWidth() / 2 * scale;
    final float right = planeScaleCalculator.getViewportWidth() / 2 * scale;
    final float bottom = - planeScaleCalculator.getViewportHeight() / 2 * scale;
    final float top = planeScaleCalculator.getViewportHeight() / 2 * scale;
    final float far = 500;
    Matrix.orthoM(getProjectionMatrix(), 0, left, right, bottom, top, 1, far);
}
 
Example 7
Source File: GLES20Canvas.java    From android-openGL-canvas with Apache License 2.0 5 votes vote down vote up
@Override
public void setSize(int width, int height) {
    mWidth = width;
    mHeight = height;
    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 8
Source File: MatrixUtils.java    From In77Camera with MIT License 5 votes vote down vote up
public static void updateProjectionFit(int imageWidth, int imageHeight, int surfaceWidth, int surfaceHeight, float[] projectionMatrix) {
    float screenRatio=(float)surfaceWidth/surfaceHeight;
    float videoRatio=(float) imageWidth / imageHeight;
    if (videoRatio>screenRatio){
        Matrix.orthoM(projectionMatrix,0,-1f,1f,-videoRatio/screenRatio,videoRatio/screenRatio,-1f,1f);
    }else Matrix.orthoM(projectionMatrix,0,-screenRatio/videoRatio,screenRatio/videoRatio,-1f,1f,-1f,1f);
}
 
Example 9
Source File: MakeupProgramLandmarks.java    From PLDroidShortVideo with Apache License 2.0 5 votes vote down vote up
public void refresh(float[] landmarksData, int width, int height) {
    if (mWidth != width || mHeight != height) {
        float[] orthoMtx = new float[16];
        float[] rotateMtx = new float[16];
        Matrix.orthoM(orthoMtx, 0, 0, width, 0, height, -1, 1);
        Matrix.setRotateM(rotateMtx, 0, 180, 1.0f, 0.0f, 0.0f);
        Matrix.multiplyMM(mvpMtx, 0, rotateMtx, 0, orthoMtx, 0);

        mWidth = width;
        mHeight = height;
    }
    updateVertexArray(Arrays.copyOf(landmarksData, landmarksData.length));
}
 
Example 10
Source File: GPUImageTransformFilter.java    From SimpleVideoEditor with Apache License 2.0 5 votes vote down vote up
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);
}
 
Example 11
Source File: GPUImageTransformFilter.java    From SimpleVideoEditor with Apache License 2.0 5 votes vote down vote up
@Override
public void onOutputSizeChanged(final int width, final int height) {
    super.onOutputSizeChanged(width, height);

    if (!ignoreAspectRatio) {
        Matrix.orthoM(orthographicMatrix, 0, -1.0f, 1.0f, -1.0f * (float) height / (float) width, 1.0f * (float) height / (float) width, -1.0f, 1.0f);
        setUniformMatrix4f(orthographicMatrixUniform, orthographicMatrix);
    }
}
 
Example 12
Source File: GPUImageTransformFilter.java    From SimpleVideoEditor with Apache License 2.0 5 votes vote down vote up
public void setIgnoreAspectRatio(boolean ignoreAspectRatio) {
    this.ignoreAspectRatio = ignoreAspectRatio;

    if (ignoreAspectRatio) {
        Matrix.orthoM(orthographicMatrix, 0, -1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
        setUniformMatrix4f(orthographicMatrixUniform, orthographicMatrix);
    } else {
        onOutputSizeChanged(getOutputWidth(), getOutputHeight());
    }
}
 
Example 13
Source File: GLMatrixStack.java    From tilt-game-android with MIT License 4 votes vote down vote up
public void glOrthof(final float pLeft, final float pRight, final float pBottom, final float pTop, final float pZNear, final float pZFar) {
	Matrix.orthoM(this.mMatrixStack, this.mMatrixStackOffset, pLeft, pRight, pBottom, pTop, pZNear, pZFar);
}
 
Example 14
Source File: OpenGLRenderer.java    From smartGL with Apache License 2.0 4 votes vote down vote up
private void computeProjMatrix2D(float[] matrix2D) {
    Matrix.orthoM(matrix2D, 0, 0f, mWidth, mHeight, 0, -1f, 1f);
}
 
Example 15
Source File: MatrixStack.java    From PanoramaGL with Apache License 2.0 4 votes vote down vote up
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);
}
 
Example 16
Source File: GlVideoRenderer.java    From LiTr with BSD 2-Clause "Simplified" License 4 votes vote down vote up
private void initMvpMatrix(int rotation, float videoAspectRatio) {
    float[] projectionMatrix = new float[16];
    Matrix.setIdentityM(projectionMatrix, 0);
    Matrix.orthoM(projectionMatrix, 0, -videoAspectRatio, videoAspectRatio, -1, 1, -1, 1);

    // rotate the camera to match video frame rotation
    float[] viewMatrix = new float[16];
    Matrix.setIdentityM(viewMatrix, 0);
    float upX;
    float upY;
    switch (rotation) {
        case 0:
            upX = 0;
            upY = 1;
            break;
        case 90:
            upX = 1;
            upY = 0;
            break;
        case 180:
            upX = 0;
            upY = -1;
            break;
        case 270:
            upX = -1;
            upY = 0;
            break;
        default:
            // this should never happen, but if it does, use trig as a last resort
            upX = (float) Math.sin(rotation / Math.PI);
            upY = (float) Math.cos(rotation / Math.PI);
            break;
    }
    Matrix.setLookAtM(viewMatrix, 0,
                      0, 0, 1,
                      0, 0, 0,
                      upX, upY, 0);

    Matrix.setIdentityM(mvpMatrix, 0);
    Matrix.multiplyMM(mvpMatrix, 0, projectionMatrix, 0, viewMatrix, 0);
}
 
Example 17
Source File: HardwareScalerActivity.java    From grafika with Apache License 2.0 4 votes vote down vote up
/**
 * Handles changes to the size of the underlying surface.  Adjusts viewport as needed.
 * Must be called before we start drawing.
 * (Called from RenderHandler.)
 */
private void surfaceChanged(int width, int height) {
    // This method is called when the surface is first created, and shortly after the
    // call to setFixedSize().  The tricky part is that this is called when the
    // drawing surface is *about* to change size, not when it has *already* changed
    // size.  A query on the EGL surface will confirm that the surface dimensions
    // haven't yet changed.  If you re-query after the next swapBuffers() call,
    // you will see the new dimensions.
    //
    // To have a smooth transition, we should continue to draw at the old size until the
    // surface query tells us that the size of the underlying buffers has actually
    // changed.  I don't really expect a "normal" app will want to call setFixedSize()
    // dynamically though, so in practice this situation shouldn't arise, and it's
    // just not worth the hassle of doing it right.

    Log.d(TAG, "surfaceChanged " + width + "x" + height);

    // Use full window.
    GLES20.glViewport(0, 0, width, height);

    // Simple orthographic projection, with (0,0) in lower-left corner.
    Matrix.orthoM(mDisplayProjectionMatrix, 0, 0, width, 0, height, -1, 1);

    int smallDim = Math.min(width, height);

    // Set initial shape size / position / velocity based on window size.  Movement
    // has the same "feel" on all devices, but the actual path will vary depending
    // on the screen proportions.  We do it here, rather than defining fixed values
    // and tweaking the projection matrix, so that our squares are square.
    mTri.setColor(0.1f, 0.9f, 0.1f);
    mTri.setTexture(mFineTexture);
    mTri.setScale(smallDim / 3.0f, smallDim / 3.0f);
    mTri.setPosition(width / 2.0f, height / 2.0f);
    mRect.setColor(0.9f, 0.1f, 0.1f);
    mRect.setTexture(mCoarseTexture);
    mRect.setScale(smallDim / 5.0f, smallDim / 5.0f);
    mRect.setPosition(width / 2.0f, height / 2.0f);
    mRectVelX = 1 + smallDim / 4.0f;
    mRectVelY = 1 + smallDim / 5.0f;

    // left edge
    float edgeWidth = 1 + width / 64.0f;
    mEdges[0].setColor(0.5f, 0.5f, 0.5f);
    mEdges[0].setScale(edgeWidth, height);
    mEdges[0].setPosition(edgeWidth / 2.0f, height / 2.0f);
    // right edge
    mEdges[1].setColor(0.5f, 0.5f, 0.5f);
    mEdges[1].setScale(edgeWidth, height);
    mEdges[1].setPosition(width - edgeWidth / 2.0f, height / 2.0f);
    // top edge
    mEdges[2].setColor(0.5f, 0.5f, 0.5f);
    mEdges[2].setScale(width, edgeWidth);
    mEdges[2].setPosition(width / 2.0f, height - edgeWidth / 2.0f);
    // bottom edge
    mEdges[3].setColor(0.5f, 0.5f, 0.5f);
    mEdges[3].setScale(width, edgeWidth);
    mEdges[3].setPosition(width / 2.0f, edgeWidth / 2.0f);

    // Inner bounding rect, used to bounce objects off the walls.
    mInnerLeft = mInnerBottom = edgeWidth;
    mInnerRight = width - 1 - edgeWidth;
    mInnerTop = height - 1 - edgeWidth;

    Log.d(TAG, "mTri: " + mTri);
    Log.d(TAG, "mRect: " + mRect);
}
 
Example 18
Source File: MatrixStack.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
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);
}
 
Example 19
Source File: ICanvasGL.java    From android-openGL-canvas with Apache License 2.0 3 votes vote down vote up
@Override
public float[] obtainResultMatrix(int viewportW, int viewportH, float x, float y, float drawW, float drawH) {
    float ratio = (float) viewportW / viewportH;

    transform[TRANSLATE_X] += x;
    transform[TRANSLATE_Y] += y;

    GLES20.glViewport(0, 0, viewportW, viewportH);

    Matrix.orthoM(mProjectionMatrix, 0, 0, ratio, 0, 1, -1, 1);
    Matrix.multiplyMM(viewProjectionMatrix, 0, mProjectionMatrix, 0, mViewMatrix, 0);

    Matrix.scaleM(mModelMatrix, 0, 1, -1, 1);
    GLES20Canvas.printMatrix("model init:", mModelMatrix, 0);

    Matrix.rotateM(mModelMatrix, 0, transform[ROTATE_Z], 0, 0, 1f);
    GLES20Canvas.printMatrix("model rotated:", mModelMatrix, 0);


    final float transX = transform[TRANSLATE_X] / viewportW;
    final float transY = transform[TRANSLATE_Y] / viewportH -1;
    Matrix.translateM(tempMultiplyMatrix4, 0, mModelMatrix, 0, transX, transY, 0);
    GLES20Canvas.printMatrix("model translated:", tempMultiplyMatrix4, 0);

    Matrix.scaleM(tempMultiplyMatrix4, 0, transform[SCALE_X] * drawW/viewportW * ratio, transform[SCALE_Y] * drawH/viewportH, 1);
    GLES20Canvas.printMatrix("model scaled:", tempMultiplyMatrix4, 0);


    Matrix.multiplyMM(mvp, 0, viewProjectionMatrix, 0, tempMultiplyMatrix4, 0);
    GLES20Canvas.printMatrix("ultra matrix:", mvp, 0);

    return mvp;
}
 
Example 20
Source File: MatrixUtils.java    From ZGDanmaku with Apache License 2.0 2 votes vote down vote up
/**
 * 设置正交投影参数
 *
 * @param left   left面的x坐标
 * @param right  right面的x坐标
 * @param bottom bottom的y坐标
 * @param top    top面的y坐标
 * @param near   near面距离
 * @param far    far面距离
 */
public static void setProjectOrtho(float left, float right, float bottom, float top, float near, float far) {
    Matrix.orthoM(mProjectMatrix, 0, left, right, bottom, top, near, far);
}