翻转OpenGL ES 2.0 X-Axis?

Nat*_*ins 4 java opengl-es opengl-es-2.0

我开始绘制Quad,但是当我开始使用Vertices时,我发现X坐标被翻转了.下面是一张图片来说明我的意思:

在此输入图像描述

这是我的顶点 - 指数和纹理坐标,我没有必要显示.

static final int COORDS_PER_VERTEX = 3;
static float positionCoords[] = { 
    -0.5f,  0.5f, 0.0f,   // top left
    -0.5f, -0.5f, 0.0f,   // bottom left
     0.5f, -0.5f, 0.0f,   // bottom right
     0.5f,  0.5f, 0.0f }; // top right

static final int COORDS_PER_TEXTURE = 2;
static float textureCoords[] = { 
    0.0f, 0.0f, 
    0.0f, 1.0f,
    1.0f, 1.0f,
    1.0f, 0.0f, };

private final short indices[] = { 0, 1, 2 };
Run Code Online (Sandbox Code Playgroud)

这是我更改投影和查看矩阵的地方.

public void onSurfaceChanged(GL10 naGl, int width, int height)
{
        Log.d(TAG, "GL Surface Changed - Setting Up View");

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

    float ratio = (float) width / height;

    Matrix.frustumM(ProjectionMatrix, 0, -ratio, ratio, -1, 1, 3, 7);

    Matrix.setLookAtM(ViewMatrix, 0, 0, 0, -3, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
}
Run Code Online (Sandbox Code Playgroud)

为什么会被"倒退".我还认为我的相机可能在物体后面,因此如果我在物体后面,那么在三维空间中将是正面的.

Tim*_*Tim 6

你确实是从背面看物体.

你的lookAt函数将目光放在(0,0,-3),lookAt指向(0,0,0).默认情况下,负z轴指向屏幕,但您从反方向(朝向正z轴)查看它.

您应该注意(0,0,3)朝向(0,0,0)以获得您期望的视图.

您可能会发现红皮书的这一章内容丰富.