2d array with Kinect

edited April 2014 in Kinect

Never programmed a line of code in my life. I'm using Processing 2.0 on Mac OS X. Yes I have gotten my kinect to work.

I'm trying to use the third example here: http://www.processing.org/tutorials/2darray/ coupled with some of the code found in Daniel Borenstein's "making things see".

However, instead of using sine to calculate the color of the array, I would like to use the Kinect Depth Data to do it. Don't know how to continue. The code below is what I have so far. I know that I have to do something in the "void draw" to make it work. I just don't know exactly how to proceed. Can someone check my code and help me finish my code, or point me in the right direction? I don't know if I need the oscillate part of code or the interpolated X. My code so far is:

import SimpleOpenNI.*; SimpleOpenNI kinect;

int cols = 48; int rows = 20;

void setup(){ size (900, 400); kinect = new SimpleOpenNI(this);

kinect.enableDepth();

grid = new Cell [cols][rows]; for (int j = 0; j < cols; j++) { for (int k = 0; k < rows; k++){

   //Initialize each object
   grid [j][k] = new Cell(j*20,k*20,20,20,j+k);
 }

} }

void draw (){ background (0);

int[] depthValues = kinect.depthMap(); for (int y = 0; y < 400; y++) { for(int x = 0; x < 900; x++) {

int reversedX = 900-x-1;

int i = reversedX + y * 900;
int currentDepthValue = depthValues [i];

if(currentDepthValue > 610 && currentDepthValue < 1525 && currentDepthValue < closestValue) { closestValue = currentDepthValue; closestX = x; closestY = y;

} } }

float interpolatedX = lerp(lastX, closestX, 0.3f); float interpolatedY = lerp (lastY, closestY, 0.3f); for (int j = 0; j < cols; j++){ for (int k = 0; k < rows; k++){

//Oscillate and displat each, later might want to change 
//the interaction of each object.
grid [j][k].oscillate();
grid [j][k].display();

} } }

Sign In or Register to comment.