-
Notifications
You must be signed in to change notification settings - Fork 14
/
LeapData.cpp
134 lines (115 loc) · 4.14 KB
/
LeapData.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include "LeapData.h"
#include <iostream>
using namespace LeapOsvr;
////////////////////////////////////////////////////////////////////////////////////////////////////////
/*----------------------------------------------------------------------------------------------------*/
LeapData::LeapData(const LEAP_CONNECTION pConnection) : mConnection(pConnection),
mHandSelectL(HandSelector(true)),
mHandSelectR(HandSelector(false)) {
//do nothing...
}
LeapData::~LeapData() {
if (mConnection) {
LeapDestroyConnection(mConnection);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
/*----------------------------------------------------------------------------------------------------*/
bool LeapData::update() {
eLeapRS result;
LEAP_CONNECTION_MESSAGE msg;
result = LeapPollConnection(mConnection, 1000, &msg);
if (LEAP_FAILED(result)) {
//std::cerr << "com_osvr_LeapMotion - LeapData::update(): LeapPollConnection call failed." << std::endl;
return false;
}
switch (msg.type) {
case eLeapEventType_Connection:
// @todo
break;
case eLeapEventType_ConnectionLost:
// @todo
break;
case eLeapEventType_Device:
// @todo
break;
case eLeapEventType_DeviceLost:
// @todo
break;
case eLeapEventType_DeviceFailure:
// @todo
break;
case eLeapEventType_Tracking:
copyFrame(*(msg.tracking_event));
return true;
break;
case eLeapEventType_ImageComplete:
// @todo
break;
case eLeapEventType_ImageRequestError:
// @todo
break;
case eLeapEventType_LogEvent:
// @todo
break;
case eLeapEventType_Policy:
// @todo
break;
case eLeapEventType_ConfigChange:
// @todo
break;
case eLeapEventType_ConfigResponse:
// @todo
break;
default:
// @todo log msg.type?
break;
}
return false;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
/*----------------------------------------------------------------------------------------------------*/
const LEAP_CONNECTION LeapData::getConnection() const {
return mConnection;
}
/*----------------------------------------------------------------------------------------------------*/
const LEAP_TRACKING_EVENT& LeapData::getFrame() const {
return mFrame;
}
/*----------------------------------------------------------------------------------------------------*/
const bool LeapData::hasBestHand(HandSide pSide) const {
return (getBestHandIndex(pSide) != NoHandFound);
}
/*----------------------------------------------------------------------------------------------------*/
const LEAP_HAND& LeapData::getBestHand(HandSide pSide) const {
const int index = getBestHandIndex(pSide);
if (index == NoHandFound) {
throw std::out_of_range("No 'best hand' was found.");
}
return mFrame.pHands[index];
}
const bool LeapData::isConnected() const {
LEAP_CONNECTION_INFO connectionInfo;
eLeapRS result = LeapGetConnectionInfo(mConnection, &connectionInfo);
return LEAP_SUCCEEDED(result) && connectionInfo.status == eLeapConnectionStatus_Connected;
}
const bool LeapData::isDeviceConnected() const {
uint32_t numDevices = 0;
eLeapRS result = LeapGetDeviceList(mConnection, nullptr, &numDevices);
return LEAP_SUCCEEDED(result) && numDevices > 0;
}
////////////////////////////////////////////////////////////////////////////////////////////////////////
/*----------------------------------------------------------------------------------------------------*/
const int LeapData::getBestHandIndex(HandSide pSide) const {
return (pSide == Left ? mHandSelectL : mHandSelectR).getBestHandIndex();
}
void LeapData::copyFrame(const LEAP_TRACKING_EVENT& frame) {
mFrame = frame;
mHands.resize(frame.nHands);
for (uint32_t i = 0; i < frame.nHands; i++) {
mHands[i] = frame.pHands[i];
}
mFrame.pHands = mHands.data();
mHandSelectL.update(mHands);
mHandSelectR.update(mHands);
}