Conditional problem in draw(), condition is false, but keep executing
in
Contributed Library Questions
•
1 year ago
Hi,
I just started using Kinect with Processing. I am trying to do a simple hand tracking.
But there is strange thing happened, this is the code:
- int prevPos = 1;
- int count = 0;
- void draw() {
- kinect.update();
- image(kinect.depthImage(), 0, 0);
- for (int i = 1; i < handPositions.size(); i++) {
- currentHand = handPositions.get(i);
- previousHand = handPositions.get(i-1);
- if (currentHand.x <= 290) { //left area
- if (prevPos != 1) {
- prevPos = 1;
- text(count++, 10, 50);
- }
- }
- else if (currentHand.x > 290 && currentHand.x <= 390) {//middle area
- if (prevPos != 2) {
- prevPos = 2;
- }
- }
- else {
- if (prevPos != 3) {//right area
- prevPos = 3;
- }
- }
- line(previousHand.x, previousHand.y, currentHand.x, currentHand.y);
- }
- }
Basically I divide the area into 3 parts, according to the hand x-coordinate.
Then, if the hand are still in the same area, I don't want to repeatedly execute the same instruction, in this case is the count++.
But once it executed, it keep increasing, no matter where the hand is. It seems like even though the prevPos is equal to 1 it still execute the count++.
I would really appreciate if anyone can help me. I am sorry if it turns out a simple mistake, I am not an expert in Processing or programming in general.
1