Created
November 25, 2012 21:06
-
-
Save hilukasz/4145333 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import processing.opengl.*; | |
import SimpleOpenNI.*; | |
SimpleOpenNI kinect; | |
/* | |
import controlP5.*; | |
ControlP5 cp5; | |
int sliderValue = 180; | |
*/ | |
int rotation = 0; | |
int boxSize = 150; | |
PVector boxCenter = new PVector(0,0,600); | |
float s = 1; | |
void setup(){ | |
size(1024, 768, OPENGL); | |
kinect = new SimpleOpenNI(this); | |
kinect.enableDepth(); | |
//kinect.enableRGB(); | |
//kinect.alternativeViewPointDepthToImage(); | |
/* | |
cp5 = new ControlP5(this); | |
cp5.addSlider("sliderValue") | |
.setPosition(10,10) | |
.setRange(0,360) | |
; | |
*/ | |
} | |
void draw(){ | |
strokeWeight(4); | |
//println(frameRate); | |
background(0); | |
kinect.update(); | |
//PImage rgbImage = kinect.rgbImage(); | |
//pushMatrix(); | |
translate(width/2, height/2, -1000); | |
rotateX(radians(180)); | |
translate(0, 0, 1400); | |
rotateY(radians(map(mouseX, 0, width, -180, 180))); | |
translate(0, 0, s*-1000); | |
scale(s); | |
stroke(255); | |
PVector[] depthPoints = kinect.depthMapRealWorld(); | |
int depthPointsInBox = 0; | |
for (int i = 0; i<depthPoints.length; i+=10){ | |
PVector currentPoint = depthPoints[i]; | |
if ( currentPoint.x > boxCenter.x - boxSize/2 && currentPoint.x < boxCenter.x + boxSize/2){ | |
if ( currentPoint.y > boxCenter.y - boxSize/2 && currentPoint.y < boxCenter.y + boxSize/2){ | |
if ( currentPoint.z > boxCenter.z - boxSize/2 && currentPoint.z < boxCenter.z + boxSize/2){ | |
depthPointsInBox++; | |
} | |
} | |
} | |
point(currentPoint.x, currentPoint.y, currentPoint.z); | |
} | |
println(depthPointsInBox); | |
float boxAlpha = map(depthPointsInBox, 0, 100, 0, 255); | |
translate(boxCenter.x, boxCenter.y, boxCenter.z); | |
fill(255, 0, 0, boxAlpha); | |
stroke(255, 0, 0); | |
box(boxSize); | |
//popMatrix(); | |
} | |
void keyPressed(){ | |
if(keyCode == 38){ | |
s += 0.01; | |
} | |
if (keyCode == 40){ | |
s -= 0.01; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment