double TimeCounter::getElapsedTime() const { if(isTimeRunning()) { timeval now; gettimeofday(&now, NULL); return getDifference(start_time_, now); } return getDifference(start_time_, end_time_); }
unsigned char LEDStrip::getMaximumDifference(Color color1, Color color2) { unsigned char redDifference = getDifference(color1.r, color2.r); unsigned char greenDifference = getDifference(color1.g, color2.g); unsigned char blueDifference = getDifference(color1.b, color2.b); unsigned char alphaDifference = getDifference(color1.a, color2.a); unsigned char maximumDifference = max(redDifference, greenDifference); maximumDifference = max(maximumDifference, blueDifference); maximumDifference = max(maximumDifference, alphaDifference); return maximumDifference; }
byte LEDStrip::getStepSize(unsigned char colorValue1, unsigned char colorValue2, byte fadeSpeed, unsigned char maximumDifference) { unsigned char currentDifference = getDifference(colorValue1, colorValue2); byte stepSize = round((int)(fadeSpeed * currentDifference) / maximumDifference); stepSize = min(fadeSpeed, stepSize); stepSize = max(1, stepSize); return stepSize; }
bool WallFollowingStrategy::lineCondition(std::pair<cv::Vec4i, float> line, cv::Vec4i initialLineSegment) { float slope = calcSlope(initialLineSegment); return fabs(line.second - slope) < 0.3 && abs(line.first[0] - initialLineSegment[0]) < getDifference(line.first[0], line.first[2]) && compareY(line.first[1], initialLineSegment[1]) < compareY(line.first[1], line.first[3]); }
std::vector<std::shared_ptr<TestCaseError>> PositionVerificationTest::verify(TestCaseResult &result) { //todo find reference to closest plane for error report bool correct = true; std::vector<std::shared_ptr<TestCaseError>> errors; for(int planeIndex = 0; planeIndex < tc->getPlanes().size() && correct; planeIndex++) { TestServerPlane testServerPlane = tc->getPlanes()[planeIndex]; Vector3d* closestPosition = nullptr; bool match = false; //if there are planes to compare, set closest plane to first one for testing if(result.getPlanes().size() > 0) { closestPosition = new Vector3d(result.getPlanes()[0].getPosition()); } for (int resultPlaneIndex = 0; resultPlaneIndex < result.getPlanes().size(); resultPlaneIndex++) { Vector3d resultPlanePos = result.getPlanes()[resultPlaneIndex].getPosition(); Vector3d distance = getDifference(testServerPlane.getLatLongAlt(), tc->getOwnship().getLatLongAlt()) - resultPlanePos; bool correctLat = fabs(distance.x) < THRESHOLD; bool correctLong = fabs(distance.y) < THRESHOLD; bool correctAlt = fabs(distance.z) < THRESHOLD; bool localMatch = correctLat && correctLong && correctAlt; match |= localMatch; //if plane is too far away to be a match, but is closest of the 'wrong' planes, report this as an error if(!localMatch && distance.getMagnitude() < closestPosition->getMagnitude()) { closestPosition = new Vector3d(distance); } } PositionTestCaseError error = PositionTestCaseError(result.getTime(),testServerPlane.getLatLongAlt(),*closestPosition); error.setError(!match && closestPosition); errors.push_back(std::make_shared<PositionTestCaseError>(error)); /* * if(!match && closestPosition) { errors.push_back(std::make_shared<PositionTestCaseError>(PositionTestCaseError(result.getTime(),testServerPlane.getLatLongAlt(),*closestPosition))); } */ } return errors; }
//-------------------------------------------------------------- void ofApp::update(){ // Grab the camera feed // and check for new frames grabber.update(); if(grabber.isFrameNew()){ getRGBPixels(); convertToGrayscale(); getDifference(); backgroundLearning(); } }
bool AnimationSaver::saveAnimation(std::string path, std::weak_ptr<IFrameController> container) { if (!path.length() != 0) { return false; } FileManager writer; if (!writer.openFileForWriting(path)) { return false; } std::shared_ptr<IFrameController> currentContainer; if(container.expired()) { return false; } currentContainer = container.lock(); int total = currentContainer->totalNumberOfFrames(); if (!writer.writeToFile<int>(total)) { return false; } //Fake-zero frame for algorithnm to be more consistent std::shared_ptr<Frame> fakeZeroShared = std::make_shared<Frame>(total); std::weak_ptr<Frame>fakezero = std::weak_ptr<Frame>(fakeZeroShared); std::weak_ptr<Frame> currentFrame = currentContainer->getFirstFrame(); //save difference between first and empty frame if(!saveDifference(currentFrame.lock()->getDifference(fakezero), writer)) { return false; } fakeZeroShared.reset(); for (int i = 1; i < total; ++i) { auto tmpFrame = currentContainer->getNextFrame().lock(); std::unique_ptr<Frame::Diff> diff = tmpFrame->getDifference(currentFrame); if (!saveDifference(diff, writer)) { return false; } currentFrame = currentContainer->getCurrentFrame(); } writer.closeOutputFile(); return true; }
//-------------------------------------------------------------- void ofApp::update(){ // Grab the camera feed // and check for new frames grabber.update(); if(grabber.isFrameNew()){ getRGBPixels(); convertToGrayscale(); getDifference(); backgroundLearning(); // Update vertex position and colors // being used to make the drawing int index = 0; for(int y=0; y<height; y++){ for(int x=0; x<width; x++){ ofVec3f vertex = mesh.getVertex(index); ofColor color = difference.getColor(x, y); // Make transparent where // the image is black (= no movement) if(color == 0) color.a = 0; // Get average color values and extrude along the z-axis // Mix this with previous z-positions to get an easing effect float z = (color.r + color.g + color.b) * 0.5; vertex.z = (vertex.z * 0.6) + (z * 0.4); // Update mesh.setVertex(index, vertex); mesh.setColor(index, color); index++; } } } }
/* * Inserisce nell'array dei Sample, N° misurazioni con differenza di tempo pari a quella specificata * nel file di configurazione. */ void addSample() { if (count <= Config::NUMBER_OF_SAMPLES) { if (count > 1) { if (getDifference(tmp[count - 1].timeOfCapture, millis()) >= Config::TIME_OF_CAPTURE) { tmp[count] = getRaw(); count++; } } else { tmp[count] = getRaw(); count++; } } else { count = 0; tmp[count] = getRaw(); } }
void performLoop() { FILE *callResults = fopen("fcall_results.txt", "w"); char buffer[30]; struct timeval start, end; int i = 0; double difference = 0.0; double total = 0; double average = 0; int the_number_of_arguments =0; /* This Segment calls and records the average time taken by function00(). function00 has no arguments */ total=0;average=0; gettimeofday(&start, NULL); for(i=0; i<NUMBER_OF_CALLS ; i++) { function00(); } gettimeofday(&end, NULL); difference = getDifference(&start, &end); printf("Calling function00() "); average = difference / (double)NUMBER_OF_CALLS; printf("Average: %f \n", average); the_number_of_arguments = 0; fprintf(callResults, "%d %f\n", the_number_of_arguments , average); /* This Segment calls and records the average time taken by function01(). function01 has 1 argument. */ total=0;average=0; gettimeofday(&start, NULL); for(i=0; i<NUMBER_OF_CALLS ; i++) { function01(3.2); } gettimeofday(&end, NULL); difference = getDifference(&start, &end); printf("Calling function01() "); average = difference / (double)NUMBER_OF_CALLS; printf("Average: %f \n", average); the_number_of_arguments = 1; fprintf(callResults, "%d %f\n", the_number_of_arguments , average); /* This Segment calls and records the average time taken by function02(). function02 has 2 arguments */ total=0;average=0; gettimeofday(&start, NULL); for(i=0; i<NUMBER_OF_CALLS ; i++) { function02(3.2, 3.2); } gettimeofday(&end, NULL); difference = getDifference(&start, &end); printf("Calling function02() "); average = difference / (double)NUMBER_OF_CALLS; printf("Average: %f \n", average); the_number_of_arguments = 2; fprintf(callResults, "%d %f\n", the_number_of_arguments , average); /* This Segment calls and records the average time taken by function03(). function03 has 3 arguments. */ total=0;average=0; gettimeofday(&start, NULL); for(i=0; i<NUMBER_OF_CALLS ; i++) { function03(3.2, 3.2, 3.2); } gettimeofday(&end, NULL); difference = getDifference(&start, &end); printf("Calling function03() "); average = difference / (double)NUMBER_OF_CALLS; printf("Average: %f \n", average); the_number_of_arguments = 3; fprintf(callResults, "%d %f\n", the_number_of_arguments , average); /* This Segment calls and records the average time taken by function04(). function04 has 4 arguments */ total=0;average=0;difference=0.0; gettimeofday(&start, NULL); for(i=0; i<NUMBER_OF_CALLS ; i++) { function04(3.2, 3.2, 3.2, 3.2); } gettimeofday(&end, NULL); difference = getDifference(&start, &end); printf("Calling function04() "); average = difference / (double)NUMBER_OF_CALLS; printf("Average: %f \n", average); the_number_of_arguments = 4; fprintf(callResults, "%d %f\n", the_number_of_arguments , average); /* This Segment calls and records the average time taken by function05(). function05 has 5 arguments */ total=0;average=0; gettimeofday(&start, NULL); for(i=0; i<NUMBER_OF_CALLS ; i++) { function05(3.2, 3.2, 3.2, 3.2, 3.2); } gettimeofday(&end, NULL); difference = getDifference(&start, &end); printf("Calling function05() "); average = difference / (double)NUMBER_OF_CALLS; printf("Average: %f \n", average); the_number_of_arguments = 5; fprintf(callResults, "%d %f\n", the_number_of_arguments , average); /* This Segment calls and records the average time taken by function06(). function06 has 6 arguments */ total=0;average=0; gettimeofday(&start, NULL); for(i=0; i<NUMBER_OF_CALLS ; i++) { function06(3.2, 3.2, 3.2, 3.2, 3.2, 3.2); } gettimeofday(&end, NULL); difference = getDifference(&start, &end); printf("Calling function06() "); average = difference / (double)NUMBER_OF_CALLS; printf("Average: %f \n", average); the_number_of_arguments = 6; fprintf(callResults, "%d %f\n", the_number_of_arguments , average); /* This Segment calls and records the average time taken by function07(). function07 has 7 arguments */ total=0;average=0; gettimeofday(&start, NULL); for(i=0; i<NUMBER_OF_CALLS ; i++) { function07(3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2); } gettimeofday(&end, NULL); difference = getDifference(&start, &end); printf("Calling function07() "); average = difference / (double)NUMBER_OF_CALLS; printf("Average: %f \n", average); the_number_of_arguments = 7; fprintf(callResults, "%d %f\n", the_number_of_arguments , average); /* This Segment calls and records the average time taken by function08(). function08 has 8 arguments */ total=0;average=0; gettimeofday(&start, NULL); for(i=0; i<NUMBER_OF_CALLS ; i++) { function08(3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2); } gettimeofday(&end, NULL); difference = getDifference(&start, &end); printf("Calling function08() "); average = difference / (double)NUMBER_OF_CALLS; printf("Average: %f \n", average); the_number_of_arguments = 8; fprintf(callResults, "%d %f\n", the_number_of_arguments , average); /* This Segment calls and records the average time taken by function09(). function09 has 9 arguments */ total=0;average=0; gettimeofday(&start, NULL); for(i=0; i<NUMBER_OF_CALLS ; i++) { function09(3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2); } gettimeofday(&end, NULL); difference = getDifference(&start, &end); printf("Calling function09() "); average = difference / (double)NUMBER_OF_CALLS; printf("Average: %f \n", average); the_number_of_arguments = 9; fprintf(callResults, "%d %f\n", the_number_of_arguments , average); /* This Segment calls and records the average time taken by function10(). function10 has 10 arguments */ total=0;average=0; gettimeofday(&start, NULL); for(i=0; i<NUMBER_OF_CALLS ; i++) { function10(3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2); } gettimeofday(&end, NULL); difference = getDifference(&start, &end); printf("Calling function10() "); average = difference / (double)NUMBER_OF_CALLS; printf("Average: %f \n", average); the_number_of_arguments = 10; fprintf(callResults, "%d %f\n", the_number_of_arguments , average); /* This Segment calls and records the average time taken by function11(). function11 has 11 arguments */ total=0;average=0; gettimeofday(&start, NULL); for(i=0; i<NUMBER_OF_CALLS ; i++) { function11(3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2); } gettimeofday(&end, NULL); difference = getDifference(&start, &end); printf("Calling function11() "); average = difference / (double)NUMBER_OF_CALLS; printf("Average: %f \n", average); the_number_of_arguments = 11; fprintf(callResults, "%d %f\n", the_number_of_arguments , average); /* This Segment calls and records the average time taken by function12(). function12 has 12 arguments */ total=0;average=0; gettimeofday(&start, NULL); for(i=0; i<NUMBER_OF_CALLS ; i++) { function12(3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2); } gettimeofday(&end, NULL); difference = getDifference(&start, &end); printf("Calling function12() "); average = difference / (double)NUMBER_OF_CALLS; printf("Average: %f \n", average); the_number_of_arguments = 12; fprintf(callResults, "%d %f\n", the_number_of_arguments , average); /* This Segment calls and records the average time taken by function15(). function15 has 15 arguments */ total=0;average=0; gettimeofday(&start, NULL); for(i=0; i<NUMBER_OF_CALLS ; i++) { function15(3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2); } gettimeofday(&end, NULL); difference = getDifference(&start, &end); printf("Calling function15() "); average = difference / (double)NUMBER_OF_CALLS; printf("Average: %f \n", average); the_number_of_arguments = 15; fprintf(callResults, "%d %f\n", the_number_of_arguments , average); /* This Segment calls and records the average time taken by function25(). function25 has 25 arguments */ total=0;average=0; gettimeofday(&start, NULL); for(i=0; i<NUMBER_OF_CALLS ; i++) { function25(3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2, 3.2); } gettimeofday(&end, NULL); difference = getDifference(&start, &end); printf("Calling function25() "); average = difference / (double)NUMBER_OF_CALLS; printf("Average: %f \n", average); the_number_of_arguments = 25; fprintf(callResults, "%d %f\n", the_number_of_arguments , average); fclose(fp); }
void GestureDetector::detect(NUI_SKELETON_FRAME &SkeletonFrame, NUI_SKELETON_FRAME &prevFrame) { NUI_SKELETON_DATA SkeletonData = SkeletonFrame.SkeletonData[id]; NUI_SKELETON_DATA prevSkeletonData = prevFrame.SkeletonData[id]; /*** The compiler does not like initializing variables within case statements ***/ // Temporary variables for actual body part points Vector4 headPoint; Vector4 rightHandPoint; Vector4 leftHandPoint; Vector4 handPoint; Vector4 spinePoint; // Vector4 rightShoulderPoint; // Vector4 leftShoulderPoint; // These are derived points used for magnification and movement Vector4 upPoint; Vector4 downPoint; Vector4 leftPoint; Vector4 rightPoint; Vector4 centerPoint; FLOAT displacement_x = 0; FLOAT displacement_y = 0; long long curTime = 0; Quadrant curQuadrant; // Do as much as we can before entering the state machine, because long states are confusing // If they make the "stop" gesture, turn off gesture recognition and magnification period // // In this case the "stop" gesture is hands _crossed_ and touching the shoulders // rightHandPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT]; // leftHandPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_LEFT]; // rightShoulderPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_SHOULDER_RIGHT]; // leftShoulderPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_SHOULDER_LEFT]; // if (areClose(leftShoulderPoint, rightHandPoint, detectRange) && areClose(rightShoulderPoint, leftHandPoint, detectRange)) // Stop gesture is hands on head rightHandPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT]; leftHandPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_LEFT]; headPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HEAD]; if (id == activeSkeleton) // Only if we're the active skeleton - nobody else should be able to kill it { if ( areClose3D(headPoint, rightHandPoint, detectRange) && areClose3D(headPoint, leftHandPoint, detectRange) ) { moveAmount_y = 0; moveAmount_x = 0; // Stop us from immediately re-enabling after disabling (cycling) if (! hideWindowOn) { hideWindowOn = TRUE; // Reset magnification value magnificationFloor = 0; HideMagnifier(); clearAndHideOverlay(); state->set(OFF); } } else { hideWindowOn = FALSE; } } // If the magnifier is off now, don't bother detecting gestures, just stop. if (id == activeSkeleton && (! IsWindowVisible(hwndMag))) { return; } // Most states are only applicable if we're the active skeleton if (id != activeSkeleton) { // Setting an already OFF state to OFF won't cause issues. if (state->state != SALUTE1) { // Adding a 'return' here will prevent anyone from stealing focus while a gesture is happening state->set(OFF); } } // Timeout any state other than OFF curTime = getTimeIn100NSIntervals(); if ( (curTime - startTime) > timeout ) { if (id == activeSkeleton) { moveAmount_y = 0; moveAmount_x = 0; clearAndHideOverlay(); state->set(OFF); } state->set(OFF); } // Same thing if they make the "cancel" gesture // The cancel gesture is to start the salute again static BOOL cancelling = FALSE; if (cancelling || (id == activeSkeleton && state->state != SALUTE1 && state->state != OFF && state->state != SALUTE2)) { // Headpoint already initialized above for the stop gesture // headPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HEAD]; if (hand == RIGHT) { handPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT]; } else { handPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_LEFT]; } if (areClose3D(headPoint, handPoint, detectRange)) { if (! cancelling) { cancelling = TRUE; moveAmount_y = 0; moveAmount_x = 0; clearAndHideOverlay(); state->set(OFF); } return; } else { cancelling = FALSE; } } // If they make the "cancel" gesture, stop recognizing gestures // Cancel gesture here is both hands touching. // static BOOL cancelling = FALSE; // if (id == activeSkeleton // && areClose3D(leftHandPoint, rightHandPoint, handsTogether)) // { // if ( ! cancelling) // { // cancelling = TRUE; // killGesturesStartTime = getTimeIn100NSIntervals(); // } // else // { // if ( (curTime - killGesturesStartTime) > killGesturesTime) // { // moveAmount_y = 0; // moveAmount_x = 0; // clearAndHideOverlay(); // state->set(OFF); // } // } // } // else // { // cancelling = FALSE; // } // Click gesture spinePoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_SPINE]; static BOOL amClicking = FALSE; if (id == activeSkeleton && state->state == MOVECENTER && ( ((spinePoint.z - rightHandPoint.z) > clickDistance) || ((spinePoint.z - leftHandPoint.z) > clickDistance) ) ) { if (showOverlays) { int ulx_small; int ulx_ss; int uly_small = (yRes/2) - (boxSmall/2); int uly_ss = (yRes/2) - (boxSuperSmall/2); if (hand == RIGHT) { ulx_small = (xRes*3/4) - (boxSmall/2); ulx_ss = (xRes*3/4) - (boxSuperSmall/2); } else { ulx_small = (xRes/4) - (boxSmall/2); ulx_ss = (xRes/4) - (boxSuperSmall/2); } // Make the center swirls go red drawRectangle(ulx_small, uly_small, boxSmall, boxSmall, 0); drawRectangle(ulx_ss, uly_ss, boxSuperSmall, boxSuperSmall, 0); } if (! amClicking) { // It'd be nice if the screen could flash at this // point or something, but that doesn't seem entirely // trivial with our current concept of overlays mouse_event(MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); amClicking = TRUE; } } else { amClicking = FALSE; } switch (state->state) { case OFF: if (id == activeSkeleton) { moveAmount_y = 0; moveAmount_x = 0; } // Check if a hand is close to the head headPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HEAD]; rightHandPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT]; leftHandPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_LEFT]; if (areClose(headPoint, rightHandPoint, detectRange)) { state->set(SALUTE1); startTime = getTimeIn100NSIntervals(); hand = RIGHT; return; } if (areClose(headPoint, leftHandPoint, detectRange)) { state->set(SALUTE1); startTime = getTimeIn100NSIntervals(); hand = LEFT; return; } break; case SALUTE1: // Check for saluting action (box up and away) headPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HEAD]; headPoint.y += saluteUp; if (hand == RIGHT) { handPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT]; headPoint.x += saluteOver; } else { handPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_LEFT]; headPoint.x -= saluteOver; } if (areClose(headPoint, handPoint, detectRange)) { if (showOverlays) { if (allowMagnifyGestures) { if (hand == RIGHT) { drawRectangle ((xRes*3/4) - (boxLarge/2), (yRes/2) - (boxLarge/2), boxLarge, boxLarge, 0); } else { drawRectangle ((xRes/4) - (boxLarge/2), (yRes/2) - (boxLarge/2), boxLarge, boxLarge, 0); } drawRectangle ((xRes/2) - (boxLarge/2), (yRes/2) - (boxLarge/2), boxLarge, boxLarge, 0); } else { if (hand == RIGHT) { drawRectangle ((xRes*3/4) - (boxLarge/2), (yRes/2) - (boxLarge/2), boxLarge, boxLarge, 0); } else { drawRectangle ((xRes/4) - (boxLarge/2), (yRes/2) - (boxLarge/2), boxLarge, boxLarge, 0); } } } state->set(SALUTE2); // Right now, an alert to let me know gesture tracking is working //MessageBox(NULL, "Salute detected", "Gesture Detection", NULL); // Change the active user // This is a race condition, but what it's doing is also inherently one if (activeSkeleton != id) { activeSkeleton = id; clearOverlay(); moveAmount_x = 0; moveAmount_y = 0; } startTime = getTimeIn100NSIntervals(); return; } // Otherwise, keep looking (until the timeout) break; case SALUTE2: spinePoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_SPINE]; centerPoint = spinePoint; if (hand == RIGHT) { handPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT]; centerPoint.x += centerRightOver; } else { handPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_LEFT]; centerPoint.x -= centerLeftOver; } // Only allow user magnification if it's turned on if (allowMagnifyGestures) { if (areClose(spinePoint, handPoint, detectRange)) { // Lock-on if (! lockingOn_magnify) { lockingOn_magnify = TRUE; lockonStartTime = getTimeIn100NSIntervals(); if (showOverlays) { clearOverlay(); drawLockOn(xRes/2, yRes/2); drawText ((xRes/3), (yRes/10), L"Locking on to Magnification Mode", 56); } } else // We're locking on already { curTime = getTimeIn100NSIntervals(); if ((curTime - lockonStartTime) > lockonTime) { state->set(MAGNIFYLEFT); startTime = getTimeIn100NSIntervals(); if (showOverlays) { clearOverlay(); drawRectangle ((xRes/2) - (boxLarge/2), (yRes/2) - (boxLarge/2), boxLarge, boxLarge, 1); drawText ((xRes/3), (yRes/10), L"Magnification Gesture Mode", 56); } } } return; } else if (areClose(centerPoint, handPoint, detectRange)) { // Don't do anything during the dead time if (! lockingOn_move) { lockingOn_move = TRUE; lockonStartTime = getTimeIn100NSIntervals(); if (showOverlays) { clearOverlay(); if (hand == RIGHT) { drawLockOn(xRes*3/4, yRes/2); } else { drawLockOn(xRes/4, yRes/2); } drawText ((xRes/3), (yRes/10), L"Locking on to Movement Mode", 56); } } else { curTime = getTimeIn100NSIntervals(); if ((curTime - lockonStartTime) > lockonTime) { state->set(MOVECENTER); startTime = getTimeIn100NSIntervals(); if (showOverlays) { clearOverlay(); int ulx; int ulx_small; int ulx_ss; int uly = (yRes/2) - (boxLarge/2); int uly_small = (yRes/2) - (boxSmall/2); int uly_ss = (yRes/2) - (boxSuperSmall/2); if (hand == RIGHT) { ulx = (xRes*3/4) - (boxLarge/2); ulx_small = (xRes*3/4) - (boxSmall/2); ulx_ss = (xRes*3/4) - (boxSuperSmall/2); } else { ulx = (xRes/4) - (boxLarge/2); ulx_small = (xRes/4) - (boxSmall/2); ulx_ss = (xRes/4) - (boxSuperSmall/2); } drawTrapezoid(ulx, uly, Q_TOP, 0); drawTrapezoid(ulx, uly, Q_BOTTOM, 0); // drawTrapezoid(ulx, uly, Q_RIGHT, 0); // drawTrapezoid(ulx, uly, Q_LEFT, 0); drawRectangle(ulx, uly, boxLarge, boxLarge, 1); drawRectangle(ulx_small, uly_small, boxSmall, boxSmall, 1); drawRectangle(ulx_ss, uly_ss, boxSuperSmall, boxSuperSmall, 1); drawText ((xRes/3), (yRes/10), L"Movement Gesture Mode", 56); } } } return; } // Nothing hit, so we're not locking on lockingOn_move = FALSE; lockingOn_magnify = FALSE; if (showOverlays) { clearOverlay(); if (hand == RIGHT) { drawRectangle ((xRes*3/4) - (boxLarge/2), (yRes/2) - (boxLarge/2), boxLarge, boxLarge, 0); } else { drawRectangle ((xRes/4) - (boxLarge/2), (yRes/2) - (boxLarge/2), boxLarge, boxLarge, 0); } drawRectangle ((xRes/2) - (boxLarge/2), (yRes/2) - (boxLarge/2), boxLarge, boxLarge, 0); } } else // Only movement gestures { if (areClose(centerPoint, handPoint, detectRange)) { if (! lockingOn_move) { lockingOn_move = TRUE; lockonStartTime = getTimeIn100NSIntervals(); if (showOverlays) { clearOverlay(); if (hand == RIGHT) { drawLockOn(xRes*3/4, yRes/2); } else { drawLockOn(xRes/4, yRes/2); } drawText ((xRes/3), (yRes/10), L"Locking on to Movement Mode", 56); } } else { // We're locking on curTime = getTimeIn100NSIntervals(); if ((curTime - lockonStartTime) > lockonTime) { state->set(MOVECENTER); startTime = getTimeIn100NSIntervals(); if (showOverlays) { clearOverlay(); int ulx; int ulx_small; int ulx_ss; int uly = (yRes/2) - (boxLarge/2); int uly_small = (yRes/2) - (boxSmall/2); int uly_ss = (yRes/2) - (boxSuperSmall/2); if (hand == RIGHT) { ulx = (xRes*3/4) - (boxLarge/2); ulx_small = (xRes*3/4) - (boxSmall/2); ulx_ss = (xRes*3/4) - (boxSuperSmall/2); } else { ulx = (xRes/4) - (boxLarge/2); ulx_small = (xRes/4) - (boxSmall/2); ulx_ss = (xRes/4) - (boxSuperSmall/2); } drawTrapezoid(ulx, uly, Q_TOP, 0); drawTrapezoid(ulx, uly, Q_BOTTOM, 0); // drawTrapezoid(ulx, uly, Q_RIGHT, 0); // drawTrapezoid(ulx, uly, Q_LEFT, 0); drawRectangle(ulx, uly, boxLarge, boxLarge, 1); drawRectangle(ulx_small, uly_small, boxSmall, boxSmall, 1); drawRectangle(ulx_ss, uly_ss, boxSuperSmall, boxSuperSmall, 1); drawText ((xRes/3), (yRes/10), L"Movement Gesture Mode", 56); } } } return; } // We're not close to anything, so turn off the lockon lockingOn_move = FALSE; if (showOverlays) { clearOverlay(); if (hand == RIGHT) { drawRectangle ((xRes*3/4) - (boxLarge/2), (yRes/2) - (boxLarge/2), boxLarge, boxLarge, 0); } else { drawRectangle ((xRes/4) - (boxLarge/2), (yRes/2) - (boxLarge/2), boxLarge, boxLarge, 0); } } } break; // case BODYCENTER: // spinePoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_SPINE]; // centerPoint = spinePoint; // if (hand == RIGHT) // { // handPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT]; // centerPoint.x += centerRightOver; // } // else // { // handPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_LEFT]; // centerPoint.x -= centerLeftOver; // } // if (areClose(centerPoint, handPoint, detectRange)) // { // if (hand == RIGHT) // { // // Center // drawRectangle ((xRes*3/4) - (boxSmall/2), (yRes/2) - (boxSmall/2), boxSmall, boxSmall, 1); // // Vert // drawRectangle ((xRes*3/4) - (boxSmall/2), (yRes/2) - (boxSmall/2) - overlayCircleRadius, boxSmall, boxSmall, 0); // drawRectangle ((xRes*3/4) - (boxSmall/2), (yRes/2) - (boxSmall/2) + overlayCircleRadius, boxSmall, boxSmall, 0); // // Horiz // drawRectangle ((xRes*3/4) - (boxSmall/2) - overlayCircleRadius, (yRes/2) - (boxSmall/2), boxSmall, boxSmall, 0); // drawRectangle ((xRes*3/4) - (boxSmall/2) + overlayCircleRadius, (yRes/2) - (boxSmall/2), boxSmall, boxSmall, 0); // } // else // { // // Center // drawRectangle ((xRes/4) - (boxSmall/2), (yRes/2) - (boxSmall/2), boxSmall, boxSmall, 1); // // Vert // drawRectangle ((xRes/4) - (boxSmall/2), (yRes/2) - (boxSmall/2) - overlayCircleRadius, boxSmall, boxSmall, 0); // drawRectangle ((xRes/4) - (boxSmall/2), (yRes/2) - (boxSmall/2) + overlayCircleRadius, boxSmall, boxSmall, 0); // // Horiz // drawRectangle ((xRes/4) - (boxSmall/2) - overlayCircleRadius, (yRes/2) - (boxSmall/2), boxSmall, boxSmall, 0); // drawRectangle ((xRes/4) - (boxSmall/2) + overlayCircleRadius, (yRes/2) - (boxSmall/2), boxSmall, boxSmall, 0); // } // state->set(MOVECENTER); // startTime = getTimeIn100NSIntervals(); // return; // } // // Otherwise, keep looking (until the timeout) // break; case MOVECENTER: case MOVEUP: case MOVEDOWN: case MOVERIGHT: case MOVELEFT: spinePoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_SPINE]; centerPoint = spinePoint; if (hand == RIGHT) { handPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT]; centerPoint.x += centerRightOver; // Add velocity getDifference(handPoint, prevSkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT], displacement_x, displacement_y); } else { handPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_LEFT]; centerPoint.x -= centerLeftOver; // Add velocity getDifference(handPoint, prevSkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_LEFT], displacement_x, displacement_y); } // Specific direction curQuadrant = findQuadrant(centerPoint, handPoint); // Place the direction arrows if (curQuadrant == Q_TOP) { if (showOverlays) { int ulx; int ulx_small; int ulx_ss; int uly = (yRes/2) - (boxLarge/2); int uly_small = (yRes/2) - (boxSmall/2); int uly_ss = (yRes/2) - (boxSuperSmall/2); if (hand == RIGHT) { ulx = (xRes*3/4) - (boxLarge/2); ulx_small = (xRes*3/4) - (boxSmall/2); ulx_ss = (xRes*3/4) - (boxSuperSmall/2); } else { ulx = (xRes/4) - (boxLarge/2); ulx_small = (xRes/4) - (boxSmall/2); ulx_ss = (xRes/4) - (boxSuperSmall/2); } // Overwrite old center stuff drawRectangle(ulx_small, uly_small, boxSmall, boxSmall, 2); drawRectangle(ulx_ss, uly_ss, boxSuperSmall, boxSuperSmall, 2); drawRectangle(ulx, uly, boxLarge, boxLarge, 0); drawTrapezoid(ulx, uly, Q_BOTTOM, 0); /*drawTrapezoid(ulx, uly, Q_RIGHT, 0); drawTrapezoid(ulx, uly, Q_LEFT, 0);*/ drawTrapezoid(ulx, uly, Q_TOP, 1); drawText ((xRes/3), (yRes/10), L"Movement Gesture Mode", 56); } state->set(MOVEUP); if (MOVEMENT_STYLE == Velocity_Style) { if (displacement_y < 0) { moveAmount_y += 500*displacement_y; } } else if (MOVEMENT_STYLE == Constant_Style) { moveAmount_x = 0; moveAmount_y = -constantMovement; } startTime = getTimeIn100NSIntervals(); return; } else if (curQuadrant == Q_BOTTOM) { if (showOverlays) { int ulx; int ulx_small; int ulx_ss; int uly = (yRes/2) - (boxLarge/2); int uly_small = (yRes/2) - (boxSmall/2); int uly_ss = (yRes/2) - (boxSuperSmall/2); if (hand == RIGHT) { ulx = (xRes*3/4) - (boxLarge/2); ulx_small = (xRes*3/4) - (boxSmall/2); ulx_ss = (xRes*3/4) - (boxSuperSmall/2); } else { ulx = (xRes/4) - (boxLarge/2); ulx_small = (xRes/4) - (boxSmall/2); ulx_ss = (xRes/4) - (boxSuperSmall/2); } // Overwrite old center stuff drawRectangle(ulx_small, uly_small, boxSmall, boxSmall, 2); drawRectangle(ulx_ss, uly_ss, boxSuperSmall, boxSuperSmall, 2); drawRectangle(ulx, uly, boxLarge, boxLarge, 0); drawTrapezoid(ulx, uly, Q_TOP, 0); /*drawTrapezoid(ulx, uly, Q_RIGHT, 0); drawTrapezoid(ulx, uly, Q_LEFT, 0);*/ drawTrapezoid(ulx, uly, Q_BOTTOM, 1); drawText ((xRes/3), (yRes/10), L"Movement Gesture Mode", 56); } state->set(MOVEDOWN); if (MOVEMENT_STYLE == Velocity_Style) { if (displacement_y > 0) { moveAmount_y += 500*displacement_y; } } else if (MOVEMENT_STYLE == Constant_Style) { moveAmount_x = 0; moveAmount_y = constantMovement; } startTime = getTimeIn100NSIntervals(); return; } else if (curQuadrant == Q_RIGHT) { if (showOverlays) { int ulx; int ulx_small; int ulx_ss; int uly = (yRes/2) - (boxLarge/2); int uly_small = (yRes/2) - (boxSmall/2); int uly_ss = (yRes/2) - (boxSuperSmall/2); if (hand == RIGHT) { ulx = (xRes*3/4) - (boxLarge/2); ulx_small = (xRes*3/4) - (boxSmall/2); ulx_ss = (xRes*3/4) - (boxSuperSmall/2); } else { ulx = (xRes/4) - (boxLarge/2); ulx_small = (xRes/4) - (boxSmall/2); ulx_ss = (xRes/4) - (boxSuperSmall/2); } // Overwrite old center stuff drawRectangle(ulx_small, uly_small, boxSmall, boxSmall, 2); drawRectangle(ulx_ss, uly_ss, boxSuperSmall, boxSuperSmall, 2); drawRectangle(ulx, uly, boxLarge, boxLarge, 0); /*drawTrapezoid(ulx, uly, Q_TOP, 0); drawTrapezoid(ulx, uly, Q_BOTTOM, 0);*/ drawTrapezoid(ulx, uly, Q_LEFT, 0); drawTrapezoid(ulx, uly, Q_RIGHT, 1); drawText ((xRes/3), (yRes/10), L"Movement Gesture Mode", 56); } state->set(MOVERIGHT); if (MOVEMENT_STYLE == Velocity_Style) { if (displacement_x > 0) { moveAmount_x += 500*displacement_x; } } else if (MOVEMENT_STYLE == Constant_Style) { moveAmount_y = 0; moveAmount_x = constantMovement; } startTime = getTimeIn100NSIntervals(); return; } else if (curQuadrant == Q_LEFT) { if (showOverlays) { int ulx; int ulx_small; int ulx_ss; int uly = (yRes/2) - (boxLarge/2); int uly_small = (yRes/2) - (boxSmall/2); int uly_ss = (yRes/2) - (boxSuperSmall/2); if (hand == RIGHT) { ulx = (xRes*3/4) - (boxLarge/2); ulx_small = (xRes*3/4) - (boxSmall/2); ulx_ss = (xRes*3/4) - (boxSuperSmall/2); } else { ulx = (xRes/4) - (boxLarge/2); ulx_small = (xRes/4) - (boxSmall/2); ulx_ss = (xRes/4) - (boxSuperSmall/2); } // Overwrite old center stuff drawRectangle(ulx_small, uly_small, boxSmall, boxSmall, 2); drawRectangle(ulx_ss, uly_ss, boxSuperSmall, boxSuperSmall, 2); drawRectangle(ulx, uly, boxLarge, boxLarge, 0); /*drawTrapezoid(ulx, uly, Q_TOP, 0); drawTrapezoid(ulx, uly, Q_BOTTOM, 0);*/ drawTrapezoid(ulx, uly, Q_RIGHT, 0); drawTrapezoid(ulx, uly, Q_LEFT, 1); drawText ((xRes/3), (yRes/10), L"Movement Gesture Mode", 56); } state->set(MOVELEFT); if (MOVEMENT_STYLE == Velocity_Style) { if (displacement_x < 0) { moveAmount_x += 500*displacement_x; } } else if (MOVEMENT_STYLE == Constant_Style) { moveAmount_y = 0; moveAmount_x = -constantMovement; } startTime = getTimeIn100NSIntervals(); return; } // Back to MOVECENTER else if (curQuadrant == Q_CENTER) { if (MOVEMENT_STYLE == Constant_Style) { moveAmount_y = 0; moveAmount_x = 0; } if (showOverlays) { int ulx; int ulx_small; int ulx_ss; int uly = (yRes/2) - (boxLarge/2); int uly_small = (yRes/2) - (boxSmall/2); int uly_ss = (yRes/2) - (boxSuperSmall/2); if (hand == RIGHT) { ulx = (xRes*3/4) - (boxLarge/2); ulx_small = (xRes*3/4) - (boxSmall/2); ulx_ss = (xRes*3/4) - (boxSuperSmall/2); } else { ulx = (xRes/4) - (boxLarge/2); ulx_small = (xRes/4) - (boxSmall/2); ulx_ss = (xRes/4) - (boxSuperSmall/2); } if (! amClicking) { drawRectangle(ulx_small, uly_small, boxSmall, boxSmall, 1); drawRectangle(ulx_ss, uly_ss, boxSuperSmall, boxSuperSmall, 1); } drawTrapezoid(ulx, uly, Q_TOP, 0); drawTrapezoid(ulx, uly, Q_BOTTOM, 0); /*drawTrapezoid(ulx, uly, Q_RIGHT, 0); drawTrapezoid(ulx, uly, Q_LEFT, 0);*/ drawRectangle(ulx, uly, boxLarge, boxLarge, 1); drawText ((xRes/3), (yRes/10), L"Movement Gesture Mode", 56); } state->set(MOVECENTER); startTime = getTimeIn100NSIntervals(); return; } // Otherwise, keep looking (until the timeout) break; // case MOVE: // spinePoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_SPINE]; // centerPoint = spinePoint; // if (hand == RIGHT) // { // handPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT]; // centerPoint.x += centerRightOver; // } // else // { // handPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_LEFT]; // centerPoint.x -= centerLeftOver; // } // // Back to MOVECENTER // if (areClose(centerPoint, handPoint, detectRange)) // { // state->set(MOVECENTER); // startTime = getTimeIn100NSIntervals(); // return; // } // // Otherwise, keep looking (until the timeout) // break; // case MAGNIFYCENTER: // spinePoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_SPINE]; // centerPoint = spinePoint; // if (hand == RIGHT) // { // handPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT]; // centerPoint.x += centerRightOver; // } // else // { // handPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_LEFT]; // centerPoint.x -= centerLeftOver; // } // // Place the direction arrows // upPoint = centerPoint; // upPoint.y += directionRadius; // if (areClose(upPoint, handPoint, detectRange)) // { // state->set(MAGNIFYUP); // return; // } // downPoint = centerPoint; // downPoint.y -= directionRadius; // if (areClose(downPoint, handPoint, detectRange)) // { // state->set(MAGNIFYDOWN); // startTime = getTimeIn100NSIntervals(); // return; // } // rightPoint = centerPoint; // rightPoint.x += directionRadius; // if (areClose(rightPoint, handPoint, detectRange)) // { // state->set(MAGNIFYRIGHT); // startTime = getTimeIn100NSIntervals(); // return; // } // leftPoint = centerPoint; // leftPoint.x -= directionRadius; // if (areClose(leftPoint, handPoint, detectRange)) // { // state->set(MAGNIFYLEFT); // startTime = getTimeIn100NSIntervals(); // return; // } // if (showOverlays) // { // clearOverlay(); // drawText ((xRes/3), (yRes/10), L"Rotate clockwise to decrease magnification and vice-versa to increase", 56); // // Center // drawRectangle ((xRes*3/4) - (boxSmall/2), (yRes/2) - (boxSmall/2), boxSmall, boxSmall, 0); // // Vert // drawRectangle ((xRes*3/4) - (boxSmall/2), (yRes/2) - (boxSmall/2) - overlayCircleRadius, boxSmall, boxSmall, 0); // drawRectangle ((xRes*3/4) - (boxSmall/2), (yRes/2) - (boxSmall/2) + overlayCircleRadius, boxSmall, boxSmall, 0); // // Horiz // drawRectangle ((xRes*3/4) - (boxSmall/2) - overlayCircleRadius, (yRes/2) - (boxSmall/2), boxSmall, boxSmall, 0); // drawRectangle ((xRes*3/4) - (boxSmall/2) + overlayCircleRadius, (yRes/2) - (boxSmall/2), boxSmall, boxSmall, 0); // } // // Otherwise, keep looking (until the timeout) // break; case MAGNIFYUP: spinePoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_SPINE]; centerPoint = spinePoint; if (hand == RIGHT) { handPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT]; centerPoint.x += centerRightOver; // Add velocity getDifference(handPoint, prevSkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT], displacement_x, displacement_y); } else { handPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_LEFT]; centerPoint.x -= centerLeftOver; // Add velocity getDifference(handPoint, prevSkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_LEFT], displacement_x, displacement_y); } // Place the direction arrows // upPoint = centerPoint; // upPoint.y += directionRadius; // if (areClose(upPoint, handPoint, detectRange)) // { // state->set(MAGNIFYUP); // return; // } // downPoint = centerPoint; // downPoint.y -= directionRadius; // if (areClose(downPoint, handPoint, detectRange)) // { // state->set(MAGNIFYDOWN); // startTime = getTimeIn100NSIntervals(); // return; // } rightPoint = centerPoint; rightPoint.x += directionRadius; if (areClose(rightPoint, handPoint, detectRange)) { state->set(MAGNIFYRIGHT); // Clockwise is increase magnification magnifyAmount += abs(displacement_x + displacement_y); startTime = getTimeIn100NSIntervals(); return; } leftPoint = centerPoint; leftPoint.x -= directionRadius; if (areClose(leftPoint, handPoint, detectRange)) { state->set(MAGNIFYLEFT); // Counterclockwise is decrease magnification magnifyAmount -= abs(displacement_x + displacement_y); startTime = getTimeIn100NSIntervals(); return; } if (showOverlays) { clearOverlay(); drawText ((xRes/3), (yRes/10), L"Clockwise = zoom in", 56); drawText ((xRes/3), (yRes*9/10), L"Counter-Clockwise = zoom out", 56); int ulx; int uly = (yRes/2) - (boxSmall/2); if (hand == RIGHT) { ulx = (xRes*3/4) - (boxSmall/2); } else { ulx = (xRes/4) - (boxSmall/2); } // Vert drawRectangle (ulx, uly - overlayCircleRadius, boxSmall, boxSmall, 1); drawRectangle (ulx, uly + overlayCircleRadius, boxSmall, boxSmall, 0); // Horiz drawRectangle (ulx - overlayCircleRadius, uly, boxSmall, boxSmall, 0); drawRectangle (ulx + overlayCircleRadius, uly, boxSmall, boxSmall, 0); } // Otherwise, keep looking (until the timeout) break; case MAGNIFYDOWN: spinePoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_SPINE]; centerPoint = spinePoint; if (hand == RIGHT) { handPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT]; centerPoint.x += centerRightOver; // Add velocity getDifference(handPoint, prevSkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT], displacement_x, displacement_y); } else { handPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_LEFT]; centerPoint.x -= centerLeftOver; // Add velocity getDifference(handPoint, prevSkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_LEFT], displacement_x, displacement_y); } // Place the direction arrows // upPoint = centerPoint; // upPoint.y += directionRadius; // if (areClose(upPoint, handPoint, detectRange)) // { // state->set(MAGNIFYUP); // return; // } // downPoint = centerPoint; // downPoint.y -= directionRadius; // if (areClose(downPoint, handPoint, detectRange)) // { // state->set(MAGNIFYDOWN); // startTime = getTimeIn100NSIntervals(); // return; // } rightPoint = centerPoint; rightPoint.x += directionRadius; if (areClose(rightPoint, handPoint, detectRange)) { state->set(MAGNIFYRIGHT); // Counterclockwise is increase magnification magnifyAmount -= abs(displacement_x + displacement_y); startTime = getTimeIn100NSIntervals(); return; } leftPoint = centerPoint; leftPoint.x -= directionRadius; if (areClose(leftPoint, handPoint, detectRange)) { state->set(MAGNIFYLEFT); // Clockwise is decrease magnification magnifyAmount += abs(displacement_x + displacement_y); startTime = getTimeIn100NSIntervals(); return; } if (showOverlays) { clearOverlay(); drawText ((xRes/3), (yRes/10), L"Clockwise = zoom in", 56); drawText ((xRes/3), (yRes*9/10), L"Counter-Clockwise = zoom out", 56); int ulx; int uly = (yRes/2) - (boxSmall/2); if (hand == RIGHT) { ulx = (xRes*3/4) - (boxSmall/2); } else { ulx = (xRes/4) - (boxSmall/2); } // Vert drawRectangle (ulx, uly - overlayCircleRadius, boxSmall, boxSmall, 0); drawRectangle (ulx, uly + overlayCircleRadius, boxSmall, boxSmall, 1); // Horiz drawRectangle (ulx - overlayCircleRadius, uly, boxSmall, boxSmall, 0); drawRectangle (ulx + overlayCircleRadius, uly, boxSmall, boxSmall, 0); } // Otherwise, keep looking (until the timeout) break; case MAGNIFYLEFT: spinePoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_SPINE]; centerPoint = spinePoint; if (hand == RIGHT) { handPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT]; centerPoint.x += centerRightOver; // Add velocity getDifference(handPoint, prevSkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT], displacement_x, displacement_y); } else { handPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_LEFT]; centerPoint.x -= centerLeftOver; // Add velocity getDifference(handPoint, prevSkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_LEFT], displacement_x, displacement_y); } // Place the direction arrows upPoint = centerPoint; upPoint.y += directionRadius; if (areClose(upPoint, handPoint, detectRange)) { state->set(MAGNIFYUP); // Clockwise is increase magnification magnifyAmount += abs(displacement_x + displacement_y); return; } downPoint = centerPoint; downPoint.y -= directionRadius; if (areClose(downPoint, handPoint, detectRange)) { state->set(MAGNIFYDOWN); // Counterclockwise is decrease magnification magnifyAmount -= abs(displacement_x + displacement_y); startTime = getTimeIn100NSIntervals(); return; } // rightPoint = centerPoint; // rightPoint.x += directionRadius; // if (areClose(rightPoint, handPoint, detectRange)) // { // state->set(MAGNIFYRIGHT); // // Clockwise is increase magnification // magnifyAmount += abs(displacement_x + displacement_y); // startTime = getTimeIn100NSIntervals(); // return; // } // leftPoint = centerPoint; // leftPoint.x -= directionRadius; // if (areClose(leftPoint, handPoint, detectRange)) // { // state->set(MAGNIFYLEFT); // // Counterclockwise is decrease magnification // magnifyAmount -= abs(displacement_x + displacement_y); // startTime = getTimeIn100NSIntervals(); // return; // } if (showOverlays) { clearOverlay(); drawText ((xRes/3), (yRes/10), L"Clockwise = zoom in", 56); drawText ((xRes/3), (yRes*9/10), L"Counter-Clockwise = zoom out", 56); int ulx; int uly = (yRes/2) - (boxSmall/2); if (hand == RIGHT) { ulx = (xRes*3/4) - (boxSmall/2); } else { ulx = (xRes/4) - (boxSmall/2); } // Vert drawRectangle (ulx, uly - overlayCircleRadius, boxSmall, boxSmall, 0); drawRectangle (ulx, uly + overlayCircleRadius, boxSmall, boxSmall, 0); // Horiz drawRectangle (ulx - overlayCircleRadius, uly, boxSmall, boxSmall, 1); drawRectangle (ulx + overlayCircleRadius, uly, boxSmall, boxSmall, 0); } // Otherwise, keep looking (until the timeout) break; case MAGNIFYRIGHT: spinePoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_SPINE]; centerPoint = spinePoint; if (hand == RIGHT) { handPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT]; centerPoint.x += centerRightOver; // Add velocity getDifference(handPoint, prevSkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_RIGHT], displacement_x, displacement_y); } else { handPoint = SkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_LEFT]; centerPoint.x -= centerLeftOver; // Add velocity getDifference(handPoint, prevSkeletonData.SkeletonPositions[NUI_SKELETON_POSITION_HAND_LEFT], displacement_x, displacement_y); } // Place the direction arrows upPoint = centerPoint; upPoint.y += directionRadius; if (areClose(upPoint, handPoint, detectRange)) { // Counterclockwise is decrease magnification magnifyAmount -= abs(displacement_x + displacement_y); state->set(MAGNIFYUP); return; } downPoint = centerPoint; downPoint.y -= directionRadius; if (areClose(downPoint, handPoint, detectRange)) { state->set(MAGNIFYDOWN); // Clockwise is increase magnification magnifyAmount += abs(displacement_x + displacement_y); startTime = getTimeIn100NSIntervals(); return; } // rightPoint = centerPoint; // rightPoint.x += directionRadius; // if (areClose(rightPoint, handPoint, detectRange)) // { // state->set(MAGNIFYRIGHT); // // Clockwise is increase magnification // magnifyAmount += abs(displacement_x + displacement_y); // startTime = getTimeIn100NSIntervals(); // return; // } // leftPoint = centerPoint; // leftPoint.x -= directionRadius; // if (areClose(leftPoint, handPoint, detectRange)) // { // state->set(MAGNIFYLEFT); // // Counterclockwise is decrease magnification // magnifyAmount -= abs(displacement_x + displacement_y); // startTime = getTimeIn100NSIntervals(); // return; // } if (showOverlays) { clearOverlay(); drawText ((xRes/3), (yRes/10), L"Clockwise = zoom in", 56); drawText ((xRes/3), (yRes*9/10), L"Counter-Clockwise = zoom out", 56); int ulx; int uly = (yRes/2) - (boxSmall/2); if (hand == RIGHT) { ulx = (xRes*3/4) - (boxSmall/2); } else { ulx = (xRes/4) - (boxSmall/2); } // Vert drawRectangle (ulx, uly - overlayCircleRadius, boxSmall, boxSmall, 0); drawRectangle (ulx, uly + overlayCircleRadius, boxSmall, boxSmall, 0); // Horiz drawRectangle (ulx - overlayCircleRadius, uly, boxSmall, boxSmall, 0); drawRectangle (ulx + overlayCircleRadius, uly, boxSmall, boxSmall, 1); } // Otherwise, keep looking (until the timeout) break; } }
int main(int argc, char * argv[]) { //checking for desired number of threads if (argc != 1) { if (strcmp(argv[1],"-t") || (threads = atoi(argv[2])) < 2) { printf("Usage: %s [-t <NUMBER_OF_THREADS>]\n Default Number of Threads: 2\n" , argv[0]); exit(-1); } printf("Pthreads and OpenMP Calculations will be done with %i threads.\n", threads); } struct timeval start, end; matrix firsts[MAX_TEST_CASES]; matrix seconds[MAX_TEST_CASES]; matrix results[MAX_TEST_CASES]; //parses all Testmatrices and stores them in two arrays // int num; //the actual number of testcases printf("Reading matrices from InputFile...\n"); for (int i = 0; i < MAX_TEST_CASES; ++i) { int end = parseMatrices(PATH_TO_TESTS, i, &firsts[i], &seconds[i]); if (end == 0) { printf("Parsing went wrong\n"); exit(0); } } FILE* performance; //first, sequential computation printf("Sequential calculation...\n"); gettimeofday(&start, NULL); for (int i = 0; i < MAX_TEST_CASES; ++i) { sequential(&firsts[i], &seconds[i], &results[i]); } gettimeofday(&end, NULL); //prints the results of sequential computation to file printf("Printing results...\n"); for (int i = 0; i < MAX_TEST_CASES; ++i) { if(!printMatrix(&results[i], PATH_TO_RESULTS)) { printf("Theres a problem with the output stream.\n"); exit(0); } } printf("Sequential calculation complete. Check %s for results\n" , PATH_TO_RESULTS); performance = fopen(PATH_TO_TIMES, "w"); fprintf(performance, "Sequential Implementation took %.3lf seconds for all testcases.\n" , getDifference(start, end)); //openMP Implementation is up next matrix ompresults[MAX_TEST_CASES]; printf("OpenMP calculation...\n"); gettimeofday(&start, NULL); for (int i = 0; i < MAX_TEST_CASES; ++i) { openMP(&(firsts[i]), &(seconds[i]), &(ompresults[i]), threads); } gettimeofday(&end, NULL); for (int i = 0; i < MAX_TEST_CASES; ++i) { if(!compareMatrices(&results[i], &ompresults[i])) { printf("OMP-Implementation has faults!"); exit(0); } } fprintf(performance, "OpenMP-Implementation took %.3lf seconds for all testcases.\n" , getDifference(start, end)); //lastly, pthreads implementation matrix ptresults[MAX_TEST_CASES]; printf("Posix-Threads calculation...\n"); gettimeofday(&start, NULL); for (int i = 0; i < MAX_TEST_CASES; ++i) { multithreaded(&firsts[i], &seconds[i], &ptresults[i], threads); } gettimeofday(&end, NULL); for (int i = 0; i < MAX_TEST_CASES; ++i) { if(!compareMatrices(&results[i], &ptresults[i])) { printf("Pthread-Implementation has faults!"); exit(0); } } fprintf(performance, "Pthreads-Implementation took %.3lf seconds for all testcases.\n" , getDifference(start, end)); //cleaning up printf("Cleaning up...\n"); fclose(performance); for (int i = 0; i < MAX_TEST_CASES; ++i) { free(firsts[i].values); free(seconds[i].values); free(results[i].values); free(ompresults[i].values); free(ptresults[i].values); } printf("All done, see %s for a summarization of each implementation's performance.\n" , PATH_TO_TIMES); exit(0); }