OpenGL ES 2.0 drawing line based on motion, Line always starts in origin

末鹿安然 提交于 2019-12-05 14:38:22
for (int i = counter/2; i < points2.size(); i++) {

        vector = convertCoordinates(points2.get(i));
        Coords[counter] = vector[0] / vector[3];
        Coords[counter+1] = -1 * (vector[1] / vector[3]);

        counter= counter+2;
    }

You have intialized Coords to hold 100000 floats and it initializes them to 0. In this loop the last iteration has 'counter' with the number of floats you have set in your array.

What you pass to glDrawArrays should be the number of VERTICES to draw. so in this case half of 'counter'.

GLES20.glDrawArrays(GLES20.GL_LINE_STRIP, 0, counter);

Your for-loop is adding 'counter'/2 extra amount of (0,0) vertices at the end of your array. the quickest fix would be to pass 'counter'/ 2 to glDrawArrays but I'd suggest a clearer approach.

numOfVertices = points2.size(); //make field 
int counter = 0; //make local
for (int i = 0; i < numOfVertices; i++) {
        vector = convertCoordinates(points2.get(i));
        Coords[counter] = vector[0] / vector[3];
        Coords[counter+1] = -1 * (vector[1] / vector[3]);
        counter= counter+2;
    }

and then

GLES20.glDrawArrays(GLES20.GL_LINE_STRIP, 0, numOfVertices);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!