翻转OpenGL ES 2.0 X-Axis?

时间:2012-08-05 18:27:50

标签: java opengl-es opengl-es-2.0

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

enter image description here

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

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 };

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

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);
}

为什么会被'向后'画出来。我还认为我的相机可能在物体后面,这样如果我在物体后面,那么在三维空间中就会是正面的。

1 个答案:

答案 0 :(得分:6)

你确实是从背面看物体。

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

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

您可能会发现红皮书的this chapter信息丰富。