Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/340.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java OpenGL ES 2.0:从正交到透视(卡片翻转效果)_Java_Android_Opengl Es_Opengl Es 2.0_Coordinate Transformation - Fatal编程技术网

Java OpenGL ES 2.0:从正交到透视(卡片翻转效果)

Java OpenGL ES 2.0:从正交到透视(卡片翻转效果),java,android,opengl-es,opengl-es-2.0,coordinate-transformation,Java,Android,Opengl Es,Opengl Es 2.0,Coordinate Transformation,我这样设置正交矩阵: ratio = (float) width / height; left = -ratio; right = ratio; bottom = -1f; top = 1f; Matrix.orthoM(projectionMatrix, 0, left, right, bottom, top, -1f, 1f); viewProjMatrix = projectionMatrix; float widthF = (right - left) / numColumns; //

我这样设置正交矩阵:

ratio = (float) width / height;
left = -ratio;
right = ratio;
bottom = -1f;
top = 1f;
Matrix.orthoM(projectionMatrix, 0, left, right, bottom, top, -1f, 1f);
viewProjMatrix = projectionMatrix;
float widthF = (right - left) / numColumns; // left to right
float heightF = (bottom - top) / numRows; // top to bottom
for (int row = 0; row < numRows; ++row) {
    for (int col = 0; col < numColumns; ++col) {
        float x1 = left + col * widthF;
        float y1 = top + row * heightF;
        float x2 = left + (col + 1) * widthF;
        float y2 = top + (row + 1) * heightF;
        float z = 0f;
        // and so on, add to vertex buffer
    }
}
通过以下方式创建一些平铺:

ratio = (float) width / height;
left = -ratio;
right = ratio;
bottom = -1f;
top = 1f;
Matrix.orthoM(projectionMatrix, 0, left, right, bottom, top, -1f, 1f);
viewProjMatrix = projectionMatrix;
float widthF = (right - left) / numColumns; // left to right
float heightF = (bottom - top) / numRows; // top to bottom
for (int row = 0; row < numRows; ++row) {
    for (int col = 0; col < numColumns; ++col) {
        float x1 = left + col * widthF;
        float y1 = top + row * heightF;
        float x2 = left + (col + 1) * widthF;
        float y2 = top + (row + 1) * heightF;
        float z = 0f;
        // and so on, add to vertex buffer
    }
}
结果是:

但是,如何使图像以“全屏”显示,即填充视口?正交矩阵填充视口的方式,但这次是透视图


(此卡片翻转效果由的Tiles3D过渡输入)

投影矩阵描述从场景的3D点到视口的2D点的映射。投影矩阵从视图空间转换到剪辑空间,剪辑空间中的坐标通过除以剪辑坐标的
w
分量转换为(-1,-1,-1)到(1,1,1)范围内的归一化设备坐标(NDC)

在透视投影中,投影矩阵描述了从针孔相机中看到的世界上的三维点到视口中的二维点的映射
摄影机平截头体(截断棱锥体)中的眼空间坐标映射到立方体(规范化设备坐标)

视图空间中的投影面积与视图空间的Z坐标之间是线性关系。它取决于视场角度和纵横比

你必须根据图像调整视野。为此,您必须知道图像到相机位置的距离

float distZ = ....; // distance of the camera to the image
float sizeX = ....; // width of the rectangle where the image is placed in
float sizeY = ....; // height of the rectangle where the image is placed in

float near = 1f;
float far  = 10f;

float left   = -0.5 * sizeX * near / distZ;
float right  =  0.5 * sizeX * near / distZ;
float bottom = -0.5 * sizeY * near / distZ;
float top    =  0.5 * sizeY * near / distZ;

Matrix.frustumM(projectionMatrix, 0, left, right, bottom, top, near, far);
注意,当然图像必须与视图“居中”