Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 84b398c3 authored by jinwu's avatar jinwu Committed by Gerrit - the friendly Code Review server
Browse files

Fix the rorating issue of 3D activity

Change the ratio of viewport after rotating and also reset the
viewport area according to the width and heigh.

Change-Id: Ia21fd043a69f18c7cc55bd9ae9bd78c0e4d234a8
CRs-Fixed: 2074163
parent 20108bbe
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -91,13 +91,25 @@ public class Renderer implements GLSurfaceView.Renderer {

    @Override
    public void onSurfaceChanged(GL10 gl, int width, int height) {
        Log.d(TAG, "w=" + width + "x" + height);
        Log.d("TAG", "onSurfaceChanged:" + width + "x" + height);
        float ratio = (float) width / height;
        if (width > height) {
            ratio = (float) height / width;
        }

        float sinY = (float) Math.sin(Math.toRadians(Settings.FIELD_OF_VIEW / 2)) / ratio;
        float cosY = (float) Math.cos(Math.toRadians(Settings.FIELD_OF_VIEW / 2));
        float fovY = (float) Math.toDegrees(Math.atan2(sinY, cosY) * 2.f);
        Matrix.perspectiveM(mProjectionMatrix, 0, fovY, ratio, 0.1f, 500.f);
        if (width > height) {
            // Caculate the width after rotating 90 or 270.
            int scaledWidth = height * height / width;
            // Caculate the offset in X level
            int offsetX = width/2 - scaledWidth/2;
            GLES20.glViewport(offsetX, 0, scaledWidth, height);
        } else {
            GLES20.glViewport(0, 0, width, height);
        }
        mSurfaceRect = new RectF(0, 0, width, height);
        setImageInvertMatrix();
    }