SimpleopenNI and PGraphics
in
Contributed Library Questions
•
3 months ago
Hi Everyone help me with this.
It should splash color on the PGraphics but it not happening. It is continuously throwing Null point exception error... it uses NITE click gesture to throw color ...please help
-
import SimpleOpenNI.*;SimpleOpenNI context;
PGraphics topLayer;boolean handsTrackFlag = false;PVector handVec = new PVector();PVector handVec2D = new PVector();//just for drawingString lastGesture = "";float lastZ = 0;boolean isPushing,wasPushing;float yourClickThreshold = 20;//set this up as you see fit for your interaction
void setup(){size(640,480);context = new SimpleOpenNI(this);context.enableDepth();// enable hands + gesture generationcontext.enableGesture();context.enableHands();// add focus gestures / here i do have some problems on the mac, i only recognize raiseHand ? Maybe cpu performance ?context.addGesture("Wave");context.addGesture("Click");context.addGesture("RaiseHand");topLayer = createGraphics(640, 480, g.getClass().getName());}
void draw(){context.update();image(context.depthImage(),0,0);// draw the tracked handif(handsTrackFlag){context.convertRealWorldToProjective(handVec,handVec2D);float diff = (handVec.z-lastZ);isPushing = diff < 0;if(diff > yourClickThreshold){if(!wasPushing && isPushing) fill(255,0,0);if(wasPushing && !isPushing) fill(0,255,0);splash();
}else fill(255);lastZ = handVec.z;wasPushing = isPushing;ellipse(handVec2D.x,handVec2D.y,10,10);}image(topLayer,0,0);}
// -----------------------------------------------------------------// hand events
void onCreateHands(int handId,PVector pos,float time){println("onCreateHands - handId: " + handId + ", pos: " + pos + ", time:" + time);
handsTrackFlag = true;handVec = pos;}
void onUpdateHands(int handId,PVector pos,float time){//println("onUpdateHandsCb - handId: " + handId + ", pos: " + pos + ", time:" + time);handVec = pos;}
void onDestroyHands(int handId,float time){println("onDestroyHandsCb - handId: " + handId + ", time:" + time);handsTrackFlag = false;context.addGesture(lastGesture);}
// -----------------------------------------------------------------// gesture events
void onRecognizeGesture(String strGesture, PVector idPosition, PVector endPosition){if(strGesture == "Click") println("onRecognizeGesture - strGesture: " + strGesture + ", idPosition: " + idPosition + ", endPosition:" + endPosition);
lastGesture = strGesture;context.removeGesture(strGesture);context.startTrackingHands(endPosition);}
void onProgressGesture(String strGesture, PVector position,float progress){//println("onProgressGesture - strGesture: " + strGesture + ", position: " + position + ", progress:" + progress);}
//---------------------------------------------------------------------------void splash(){stroke(255, 0, 0);fill(random(0,255),random(0,255),random(0,255));star((int)random(2, 8), mouseX-random(100), mouseY-random(100), random(100), random(100), -PI / 2.0, random(0, 1.5));star((int)random(2, 8), mouseX+random(200), mouseY+random(140), random(100), random(100), -PI / 2.0, random(0, 3.0));star((int)random(2, 8), mouseX+random(50), mouseY-random(78), random(100), random(100), -PI / 2.0, random(0, 2));star((int)random(2, 8), mouseX-random(120), mouseY+random(100), random(100), random(100), -PI / 2.0, random(0, 0.50));// ellipse(mouseX + 50, mouseY + 50,random(40),random(40));
}void star(int n, float cx, float cy, float r, float proportion){star(n, cx, cy, 2.0 * r, 2.0 * r, 0.0, proportion);}void star(int n, float cx, float cy, float w, float h, float startAngle, float proportion){if (n > 2){float angle = TWO_PI/ (random(2,6) *n);float dw; // draw widthfloat dh; // draw heightw = w / 2.0;h = h / 2.0;topLayer.beginShape();for (int i = 0; i < random(4, 12) * n; i++){dw = w;dh = h;if (i % 2 == 1) // for odd vertices, use short radius{dw = w * proportion;dh = h * proportion;}topLayer.curveVertex(cx + dw * cos(startAngle + angle * i) + random(10),cy + dh * sin(startAngle + angle * i) + random(10));}topLayer.endShape(CLOSE);}
}void deleteDrawing(){if(keyPressed && key == 'd'){setup();}}
1