import processing.video.*;
import processing.opengl.*;
Capture cam;
heightMesh rutt;
PFont font = createFont("",12);
void setup(){
// rotten apple
try { quicktime.QTSession.open(); }
catch (quicktime.QTException qte) { qte.printStackTrace(); }
size(1200,720,OPENGL);
frameRate(60);
cam = new Capture(this,128,64,30);
rutt = new heightMesh(cam);
textFont(font);
}
void draw(){
if(cam.available()){
cam.read();
rutt.updateMesh(cam);
}
background(0);
camera(0,0,750,0,0,0,0,1,0);
stroke(255,100);
rotateX(radians(mouseY));
rotateY(radians(mouseX));
rutt.draw(cam);
}
class heightMesh{
PVector verts[][];
PVector dim;
heightMesh(PImage vid) {
dim = new PVector(800, 500, 600);
verts = new PVector[vid.width][vid.height];
for(int j=0;j<vid.height;j++){
for(int i=0;i<vid.width;i++){
verts[i][j] = new PVector();
}
}
}
void updateMesh(PImage vid){
for(int j=0;j<vid.height;j++){
for(int i=0;i<vid.width;i++){
int pixelloc = j*vid.width+i;
verts[i][j].set(
map(i,0,vid.width, -dim.x/2, dim.x/2),
map( ( vid.pixels[pixelloc] >> 8 & 0xff) ,0,255, 0, -dim.y),
map(j,0,vid.height, -dim.z/2, dim.z/2)
);
}
}
}
void draw(PImage vid){
for(int j=0;j<vid.height;j++){
for(int i=0;i<vid.width-1;i++){
line( verts[i][j].x, verts[i][j].y, verts[i][j].z,
verts[i+1][j].x, verts[i+1][j].y, verts[i+1][j].z );
}
}
}
}