Android openGL ES 2.0 scene scrolling

对着背影说爱祢 提交于 2019-12-02 11:44:15

I've solved this by modifying parameters for Matrix.frustumM so they represent FOV. Than when you know angle from middle to side, you can calculate offset with tangens function.

 GLES20.glViewport(0, 0, width, height);

    float ratio = (float) width/height;
    float near = 1.0f;
    float far = 150.0f;
    float fov = 80;
    float top = (float) (Math.tan(fov * Math.PI / 360.0f) * near);
    float bottom = -top;
    float left = ratio * bottom;
    float right = ratio * top;

    offsetY = (float) (Math.tan(Math.PI/180*fov/2) * Math.abs(cameraAway));
    offsetX = offsetY * ratio; //because we know ratio between x and y

    Matrix.frustumM(mProjectionMatrix, 0, left, right, bottom, top, near, far);

You can also use Matrix.perspectivM(), but it is only avaliable for api 14+.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!