Time the duration of an event
in
Programming Questions
•
5 months ago
Hello there,
Like many, I have trouble with making a timer using Processing. I have searched the forum, but could not find an answer that suited my question. (I am quite new to Processing)
I am making a kinect application, and I want to create a button that you can trigger by holding one of your hands over it for two seconds. I have made the following function that checks wether your hand overlaps a specified target area (this is not really important, but good for knowing the context):
- boolean handOverlapCheck(float targetX, float targetY, float targetWidth, float targetHeight)
- {
- // Check the position of the left hand
- PVector leftHandPos = new PVector();
- kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_LEFT_HAND, leftHandPos);
- PVector convertedLeftHandPos = new PVector();
- kinect.convertRealWorldToProjective(leftHandPos, convertedLeftHandPos);
- // Check the position of the right hand
- PVector rightHandPos = new PVector();
- kinect.getJointPositionSkeleton(userId, SimpleOpenNI.SKEL_RIGHT_HAND, rightHandPos);
- PVector convertedRightHandPos = new PVector();
- kinect.convertRealWorldToProjective(rightHandPos, convertedRightHandPos);
- if (targetX < convertedLeftHandPos.x && convertedLeftHandPos.x < (targetX + targetWidth) && targetY < convertedLeftHandPos.y && convertedLeftHandPos.y < (targetY + targetWidth))
- {
- return true;
- } else if (targetX < convertedRightHandPos.x && convertedRightHandPos.x < (targetX + targetWidth) && targetY < convertedRightHandPos.y && convertedRightHandPos.y < (targetY + targetWidth))
- {
- return true;
- } else
- {
- return false;
- }
- }
Now I want to make a check wether the above function is triggered for two seconds without interruption. (Later, I want to accompany that with some visual feedback of this timer-event):
- if (handOverlapCheck(menuButtonX, menuButtonY, menuButtonWidth, menuButtonHeight) == true)
- {
- // magic check wether this event happens for 2 seconds
- backgroundLevel = 3;
- }
- if (handOverlapCheck(menuButtonX, menuButtonY, menuButtonWidth, menuButtonHeight) == true)
- {
- int newTimer = millis();
- if (mills() - newTimer = 2000)
- {
- backgroundLevel = 3;
- }
- }
But, obviously this won't work, since this keeps updating the newTimer value to the current time. All the variations that I can think of do this.
And now I find myself thinking in circles... Could someone please help me in a forward direction?
Kind regards,
hajraa
1