The Interpolation example demonstrates how to request tracking data by timestamp. This involves the following main tasks:
14 #include "ExampleConnection.h"
16 LEAP_CLOCK_REBASER clockSynchronizer;
18 int main(int argc, char** argv) {
19 LEAP_CONNECTION* connHandle = OpenConnection();
25 printf("Connected.\n");
26 //Create the clock synchronizer
27 LeapCreateClockRebaser(&clockSynchronizer);
29 int64_t targetFrameTime = 0;
30 uint64_t targetFrameSize = 0;
33 //Calculate the application time
34 cpuTime = (clock_t).000001 * clock()/CLOCKS_PER_SEC;//microseconds
35 //Synchronize the clocks
36 LeapUpdateRebase(clockSynchronizer, cpuTime, LeapGetNow());
38 //Simulate delay (i.e. processing load, v-sync, etc)
41 //Now get the updated application time
42 cpuTime = (clock_t) .000001 * clock()/CLOCKS_PER_SEC;
44 //Translate application time to Leap time
45 LeapRebaseClock(clockSynchronizer, cpuTime, &targetFrameTime);
47 //Get the buffer size needed to hold the tracking data
48 result = LeapGetFrameSize(*connHandle, targetFrameTime, &targetFrameSize);
49 if(result == eLeapRS_Success){
50 //Allocate enough memory
51 LEAP_TRACKING_EVENT* interpolatedFrame = malloc((size_t)targetFrameSize);
53 result = LeapInterpolateFrame(*connHandle, targetFrameTime, interpolatedFrame, targetFrameSize);
54 if(result == eLeapRS_Success){
56 printf("Frame %lli with %i hands with delay of %lli microseconds.\n",
57 (long long int)interpolatedFrame->tracking_frame_id,
58 interpolatedFrame->nHands,
59 (long long int)LeapGetNow() - interpolatedFrame->info.timestamp);
60 for(uint32_t h = 0; h < interpolatedFrame->nHands; h++){
61 LEAP_HAND* hand = &interpolatedFrame->pHands[h];
62 printf(" Hand id %i is a %s hand with position (%f, %f, %f).\n",
64 (hand->type == eLeapHandType_Left ? "left" : "right"),
65 hand->palm.position.x,
66 hand->palm.position.y,
67 hand->palm.position.z);
69 //Free the allocated buffer when done.
70 free(interpolatedFrame);
73 printf("LeapInterpolateFrame() result was %s.\n", ResultString(result));
77 printf("LeapGetFrameSize() result was %s.\n", ResultString(result));