Loading...
Logo
Processing Forum
Hey people,

I have the follow script that creates a 'pond effect'. The background is a live capture aimed at the users head to simulate a reflection. Where I am stuck is that I need dual cameras working to also use a home made multitouch display.


Script:


Capture img;


Ripple ripple;
 
void setup() {
  img = new Capture(this, 680, 420);
  size(680, 420);
  ripple = new Ripple();
  frameRate(60);
}
 
void draw() {
 
  if (img.available() == true) {
    img.read();
    image(img, 160, 100);
    // The following does the same, and is faster when just drawing the image
    // without any additional resizing, transformations, or tint.
    //set(160, 100, cam);
  loadPixels();
  img.loadPixels();
  for (int loc = 0; loc < width * height; loc++) {
    pixels[loc] = ripple.col[loc];
  }
  updatePixels();
  ripple.newframe();
  }
}
 
class Ripple {
  int i, a, b;
  int oldind, newind, mapind;
  short ripplemap[]; // the height map
  int col[]; // the actual pixels
  int riprad;
  int rwidth, rheight;
  int ttexture[];
  int ssize;
 
  Ripple() {
    // constructor
    riprad = 3;
    rwidth = width >> 1;
    rheight = height >> 1;
    ssize = width * (height + 2) * 2;
    ripplemap = new short[ssize];
    col = new int[width * height];
    ttexture = new int[width * height];
    oldind = width;
    newind = width * (height + 3);
  }
 
 
 
  void newframe() {
    // update the height map and the image
    i = oldind;
    oldind = newind;
    newind = i;
 
    i = 0;
    mapind = oldind;
    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
        short data = (short)((ripplemap[mapind - width] + ripplemap[mapind + width] +
          ripplemap[mapind - 1] + ripplemap[mapind + 1]) >> 1);
        data -= ripplemap[newind + i];
        data -= data >> 5;
        if (x == 0 || y == 0) // avoid the wraparound effect
          ripplemap[newind + i] = 0;
        else
          ripplemap[newind + i] = data;
 
        // where data = 0 then still, where data > 0 then wave
        data = (short)(1024 - data);
 
        // offsets
        a = ((x - rwidth) * data / 1024) + rwidth;
        b = ((y - rheight) * data / 1024) + rheight;
 
        //bounds check
        if (a >= width)
          a = width - 1;
        if (a < 0)
          a = 0;
        if (b >= height)
          b = height-1;
        if (b < 0)
          b=0;
 
        col[i] = img.pixels[a + (b * width)];
        mapind++;
        i++;
      }
    }
  }
}
 
 
void mouseMoved() {
  for (int j = mouseY - ripple.riprad; j < mouseY + ripple.riprad; j++) {
    for (int k = mouseX - ripple.riprad; k < mouseX + ripple.riprad; k++) {
      if (j >= 0 && j < height && k>= 0 && k < width) {
        ripple.ripplemap[ripple.oldind + (j * width) + k] += 512;
      }
    }
  }
}



What do I do to allow this secondary camera to act as a touch pad?


Thanks in advance.