so, you certainly could add those vertices using a for loop.
When you disable polyM2.setMode(OF_PRIMITIVE_LINES);
you simply use the default mesh mode which I think is OF_PRIMITIVE_TRIANGLES.
When set to OF_PRIMITIVE_LINES
you should still be able to see something.
It certainly is a problem with indexing.
check the following chapters of ofBook.
http://openframeworks.cc/ofBook/chapters/openGL.html
http://openframeworks.cc/ofBook/chapters/lines.html
http://openframeworks.cc/ofBook/chapters/generativemesh.html
I understand what you want to achieve, but all the code before the following is a bit sense less, I mean its not gonna work how you want it to.
//This is the kinect code
for (int y = 0; y < kinect.getHeight(); y += 1) {
for (int x = 0; x < kinect.getWidth(); x += 1) {
if (kinect.getDistanceAt(x, y) > 0) {
polyM2.addColor(kinect.getColorAt(x, y));
polyM2.addVertex(kinect.getWorldCoordinateAt(x, y));
}
}
}
The fix is a bit easier than what you might think.
In the above code, in
for (int y = 0; y < kinect.getHeight(); y += 1) {
instead of increasing y by 1 on each loop increase it by a larger number so you can get spaced lines.
you can even set it to update to a random value within a certain range in each loop.
Then, I think that it is a better idea to use OF_PRIMITIVE_TRIANGLE_STRIP as the mesh mode and several meshes to avoid the indexing issue. It is less optimal than doing it with a single mesh and manually doing the indexing but it should work anyways.
do the following
int spacing = 5;
vector<ofMesh> meshes;
float lineWidth = 3;// play with these two values
for (int y = 0; y < kinect.getHeight(); y += spacing ) {
meshes.push_back(ofMesh());
ofMesh & m = meshes.back();// this is just a reference, to avoid writing more
m.setMode(OF_PRIMITIVE_TRIANGLE_STRIP);
for (int x = 0; x < kinect.getWidth(); x += 1) {
if (kinect.getDistanceAt(x, y) > 0) {
auto c = kinect.getColorAt(x, y);
auto v = kinect.getWorldCoordinateAt(x, y);
m.addColor(c);
m.addVertex(v.x, v.y - lineWidth/2, v.z);
m.addColor(c);
m.addVertex(v.x, v.y + lineWidth/2, v.z);
}
}
}
for(int i = 0; i < meshes.size(); i++){
meshes[i].draw();
}
This should work although I havent tested it as I just coded here in the forum text editor.
cheers