Mesh, vertices and wireframe

Hi! I’m have some troubles with a code. I’m making 3d mesh with kinect ofxKinect library.
(…part of the code) ->

void testApp::drawPointCloud() {  
    	int w = 640;  
	int h = 480;  
    int t = 0;  
	   ofMesh mesh;  
    int step = 20;  
	for(int y = 0; y < h; y += step) {  
		for(int x = 0; x < w; x += step) {  
			if(kinect.getDistanceAt(x, y) > 0) {  
                if(kinect.getDistanceAt(x,y) <1500 ) {  
                    int n = mesh.getNumVertices();  
	// the projected points are 'upside down' and 'backwards'   
	ofScale(1, -1, -1);  
	ofTranslate(0, 0, -1000); // center the points a bit  

How can u see, i’m drawing Vertices and then Wireframe.
I need that wireframe bild only whith nearest vertices.
example in foto

(what i have)->>>

(what i need)->>>

can some one help?
how i understand, i need some fun… like “near”.

i think that only pushing some vertices in a ofMesh ,it’s not sufficient to obtain a mesh (in general you need also the indices). Probably you have to use some delaunay triangulation to specify the order in which the indices of the triangles give coherence at the whole. Otherwise you get that weird look.

you can have it setup auto indices by doing.
mesh.setupAutoIndices(); after adding all your vertexes.

I agree though - it will be way easier if you triangulate the points in the range your interested in and then just use OF_PRIMITIVE_TRIANGLES

I think zach has some good triangle addons here: