2017-02-06 37 views
4

我需要绘制在屏幕上几个坐标,坐标,不得到显示Z轴,但也未显示与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); 

在表面改变的代码:

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); 
+0

你试过-50? OpenGL通常假设-z是深度。 – BDL

回答

2

这里的问题是远远WASN的价值”不够高。我把远在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 
    }; 

它现在的工作。