Draw doesn't work proper (+kinect)
in
Contributed Library Questions
•
1 year ago
I can't see the stuff that i draw with this:
hint(DISABLE_DEPTH_TEST);
fill(255, 0, 0);
rect(0, 0, 100, 100);
fill(255);
text(frameRate, 20, 20);
Does someone have a clue why?
- import SimpleOpenNI.*;
- SimpleOpenNI context;
- float zoomF = 0.3;
- float rotX = radians(180);
- float rotY = radians(0);
- void setup() {
- size(1024, 768, P3D);
- context = new SimpleOpenNI(this);
- context.enableDepth();
- context.enableRGB();
- context.alternativeViewPointDepthToImage();
- stroke(255, 255, 255);
- smooth();
- perspective(radians(45),
- float(width)/float(height),
- 10, 150000);
- }
- void draw() {
- context.update();
- background(0);
- pushMatrix();
- translate(width/2, height/2, 0);
- rotateX(rotX);
- rotateY(rotY);
- scale(zoomF);
- PImage rgbImage = context.rgbImage();
- int[] depthMap = context.depthMap();
- int steps = 3; // to speed up the drawing, draw every third point
- int index;
- PVector realWorldPoint;
- color pixelColor;
- strokeWeight(steps);
- translate(0, 0, -1000); // set the rotation center of the scene 1000 infront of the camera
- PVector[] realWorldMap = context.depthMapRealWorld();
- for (int y=0;y < context.depthHeight();y+=steps)
- {
- for (int x=0;x < context.depthWidth();x+=steps)
- {
- index = x + y * context.depthWidth();
- if (depthMap[index] > 0)
- {
- // get the color of the point
- pixelColor = rgbImage.pixels[index];
- stroke(pixelColor);
- // draw the projected point
- realWorldPoint = realWorldMap[index];
- point(realWorldPoint.x, realWorldPoint.y, realWorldPoint.z); // make realworld z negative, in the 3d drawing coordsystem +z points in the direction of the eye
- }
- }
- }
- // draw the kinect cam
- //context.drawCamFrustum();
- popMatrix();
- hint(DISABLE_DEPTH_TEST);
- fill(255, 0, 0);
- rect(0, 0, 100, 100);
- fill(255);
- text(frameRate, 20, 20);
- }
- void keyPressed()
- {
- switch(key)
- {
- case ' ':
- context.setMirror(!context.mirror());
- break;
- }
- switch(keyCode)
- {
- case LEFT:
- rotY += 0.1f;
- break;
- case RIGHT:
- // zoom out
- rotY -= 0.1f;
- break;
- case UP:
- if (keyEvent.isShiftDown())
- zoomF += 0.02f;
- else
- rotX += 0.1f;
- break;
- case DOWN:
- if (keyEvent.isShiftDown())
- {
- zoomF -= 0.02f;
- if (zoomF < 0.01)
- zoomF = 0.01;
- }
- else
- rotX -= 0.1f;
- break;
- }
- }
1