private void newVertexBufferToDraw() { // (number of points) * (number of coordinate values) * 4 bytes per float) ByteBuffer bb = ByteBuffer.allocateDirect(verticesCoords.size() * COORDS_PER_VERTEX * 4); // use the device hardware's native byte order bb.order(ByteOrder.nativeOrder()); // create a floating point buffer from the ByteBuffer vertexBuffer = bb.asFloatBuffer(); // add the coordinates to the FloatBuffer vertexBuffer.put(Utils.pointVectorToArray(verticesCoords)); // set the buffer to read the first coordinate vertexBuffer.position(0); vertexCount = verticesCoords.size(); // Log.d(GAlg.DEBUG_TAG, "Scene coords to draw: " + verticesCoords.toString()); GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, 0, vertexCount, vertexBuffer); if (drawLines) { bb = ByteBuffer.allocateDirect(linesCoords.size() * COORDS_PER_VERTEX * 4); bb.order(ByteOrder.nativeOrder()); linesVertexBuffer = bb.asFloatBuffer(); linesVertexBuffer.put(Utils.pointVectorToArray(linesCoords)); linesVertexBuffer.position(0); linesVertexCount = linesCoords.size(); Log.d(GAlg.DEBUG_TAG, "Drawing lines between: " + linesCoords.toString()); GLES20.glBufferSubData(GLES20.GL_ARRAY_BUFFER, 0, linesVertexCount, linesVertexBuffer); } }
public void addRandomPoints() { verticesCoords.addAll( Utils.generateSomeVertices( GAlg.HOW_MANY_POINTS_GENERATE, GAlg.BORDER_POINT_POSITION, GAlg.BORDER_POINT_POSITION, pointsRenderer.getSurfaceWidth() - GAlg.BORDER_POINT_POSITION, pointsRenderer.getSurfaceHeight() - GAlg.BORDER_POINT_POSITION)); newVertexBufferToDraw(); }
public void selectVertex(Point2D point2d) { if (!vertexSelected) { // Brutal force :-) for (int i = 0; i < verticesCoords.size(); i++) { if (Utils.isInRectangle(point2d, GAlg.FINGER_ACCURACY, verticesCoords.get(i))) { selectedVertexIndex = i; vertexSelected = true; break; } } } }
public void removeVertex(Point2D point2d) { List<Point2D> newSceneCoords = verticesCoords; // Brutal force... // TODO: Divide search space for (int i = 0; i < verticesCoords.size(); i++) { if (Utils.isInRectangle(point2d, GAlg.FINGER_ACCURACY, verticesCoords.get(i))) { newSceneCoords.remove(i); break; } } verticesCoords = newSceneCoords; newVertexBufferToDraw(); }