无法在屏幕上使用Z轴绘制顶点

时间:2017-02-06 06:12:22

标签: android opengl-es-2.0

我需要在屏幕上绘制几个坐标,不显示Z轴的坐标,但不显示Z轴值的坐标。我尝试在绘制坐标之前对坐标进行标准化。归一化时,绘制所有坐标。但是在非标准化坐标的情况下,Z轴的顶点是隐藏的。

OpenGL版本:ES 2.0

坐标:

float squareCoords[] = {
            202.00002f, 244.00002f, 0.0f,
            440.00003f, 625.00006f, 0.0f,
            440.00003f, 625.00006f, 0.0f,
            690.00006f, 186.0f,0.0f,

            202.00002f, 244.00002f, 50.0f,
            440.00003f, 625.00006f, 50.0f,
            440.00003f, 625.00006f, 50.0f,
            690.00006f, 186.0f, 50.0f
    };

指数:

short[] drawOrder = {
            0,1,2,3,
            0,4,
            1,5,
            2,6,
            4,5,6,7
    };

绘制代码:

 GLES20.glDrawElements(
                GLES20.GL_LINES, drawOrder.length,
                GLES20.GL_UNSIGNED_SHORT, drawListBuffer);

On Surface Changed code:

public void onSurfaceChanged(GL10 unused, int width, int height) {
        mWidth = width;
        mHeight = height;

        GLES20.glViewport(0, 0, mWidth, mHeight);

        float ratio = (float) mWidth / mHeight;

        // this projection matrix is applied to object coordinates
        // in the onDrawFrame() method
        Matrix.orthoM(mProjMatrix, 0, 0f, width, 0.0f, height, 0, 50);

    }

的OnDraw:

public void onDrawFrame(GL10 unused) {
        Square square = new Square();
        GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT|GLES20.GL_DEPTH_BUFFER_BIT);

        if (mFirstDraw)
            mFirstDraw = false;

        long time = SystemClock.uptimeMillis() % 4000L;
      float angle = 0.090f * ((int) time);
       // float angle = 90;
       // Matrix.setRotateM(mRotationMatrix, 0, angle, 0, 0, -1.0f);
       // angle += 0.7f;
        if (angle > 360f)
            angle = 0f;
        Matrix.setLookAtM(mVMatrix, 0, 0f, 0f, 4f, 0f, 0f, 0f, 0f, 1f, 0f);
        // projection x view = modelView
        Matrix.multiplyMM(mMVPMatrix, 0, mProjMatrix, 0, mVMatrix, 0);
        // Creating rotation matrix
        Matrix.setRotateM(rotationMatrix, 0, angle, -1f, 0f, 0f);

        // rotation x camera = modelView
        float[] duplicateMatrix = Arrays.copyOf(mMVPMatrix, 16);

        Matrix.multiplyMM(mMVPMatrix, 0, duplicateMatrix, 0, rotationMatrix, 0);

        square.draw(mMVPMatrix);
    }

我旋转图表以确定是否绘制了Z轴上的顶点。

我个人认为这条线是罪魁祸首,在这里我给出了远值50和接近值0.我想知道这些值应该是什么

Matrix.orthoM(mProjMatrix, 0, 0f, width, 0.0f, height, 0, 50);

1 个答案:

答案 0 :(得分:2)

这里的问题是远远不够高的价值。我把它放得远远超过500

Matrix.orthoM(mProjectionMatrix, 0, 0f, width, 0.0f, height,0, 500);

并将坐标更改为:

float squareCoords[] = {
            202.00002f, 244.00002f, 0.0f,
            440.00003f, 625.00006f, 0.0f,
            440.00003f, 625.00006f, 0.0f,
            690.00006f, 186.0f,0.0f,

            202.00002f, 244.00002f, 200.0f,
            440.00003f, 625.00006f, 200.0f,
            440.00003f, 625.00006f, 200.0f,
            690.00006f, 186.0f, 200.0f
    };

现在正在工作。