void drawKinectMesh() {
kinect.update();
PVector[] depthPoints = kinect.depthMapRealWorld();
TriangleMesh kinectMesh = new TriangleMesh();
int skip = 20;
int width = 640;// number of columns the kinect returns
// dont do last row
for (int i = 0; i < depthPoints.length - width; i += skip) {
PVector veca1;
PVector veca2;
PVector veca3;
PVector veca4;
int col = i % width;
int row = floor(i / width);
int counter = 0;
if (col < (width - 1)) {
veca1 = depthPoints[i];
veca2 = depthPoints[i + 1];
veca3 = depthPoints[col + (width * (row + 1))];
veca4 = depthPoints[(col + (width * (row + 1))) + 1];
PVector[] vecsArr = { veca1, veca2, veca3, veca4 };
TriangleMesh tri1 = new TriangleMesh();
TriangleMesh tri2 = new TriangleMesh();
Vertex v1 = new Vertex(
new Vec3D(veca1.x, veca1.y, veca1.z), counter);
counter++;
Vertex v2 = new Vertex(
new Vec3D(veca2.x, veca2.y, veca2.z), counter);
counter++;
Vertex v3 = new Vertex(
new Vec3D(veca3.x, veca3.y, veca3.z), counter);
counter++;
Vertex v4 = new Vertex(
new Vec3D(veca4.x, veca4.y, veca4.z), counter);
counter++;
tri1.addFace(v1, v2, v3);
tri2.addFace(v2, v4, v3);
kinectMesh.addMesh(tri1);
kinectMesh.addMesh(tri2);
}
}
stroke(255);
fill(255,0,0);
gfx.mesh(kinectMesh);
}
public void setup() {
size(40, 25);
frameRate(12);
}
public void draw() {
loadPixels();
println(pixels.length); //prints 3200
}