leap-motion 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +32 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +1 -0
- data/README.rdoc +79 -0
- data/Rakefile +31 -0
- data/VERSION +1 -0
- data/ext/motion/LeapRuby.cpp +16054 -0
- data/ext/motion/LeapRuby.h +34 -0
- data/ext/motion/extconf.rb +26 -0
- data/ext/motion/swig/Leap.h +4566 -0
- data/ext/motion/swig/Leap.i +799 -0
- data/ext/motion/swig/LeapMath.h +1036 -0
- data/leap-motion.gemspec +28 -0
- data/lib/leap-motion.rb +1 -0
- data/lib/motion/libLeap.dylib +0 -0
- data/samples/test.rb +47 -0
- data/test/helper.rb +17 -0
- metadata +134 -0
@@ -0,0 +1,799 @@
|
|
1
|
+
################################################################################
|
2
|
+
# Copyright (C) 2012-2013 Leap Motion, Inc. All rights reserved. #
|
3
|
+
# Leap Motion proprietary and confidential. Not for distribution. #
|
4
|
+
# Use subject to the terms of the Leap Motion SDK Agreement available at #
|
5
|
+
# https://developer.leapmotion.com/sdk_agreement, or another agreement #
|
6
|
+
# between Leap Motion and you, your company or other organization. #
|
7
|
+
################################################################################
|
8
|
+
|
9
|
+
# usage:
|
10
|
+
# swig -c++ -python -o LeapPython.cpp -interface LeapPython Leap.i
|
11
|
+
# swig -c++ -java -o LeapJava.cpp -package com.leapmotion.leap -outdir com/leapmotion/leap Leap.i
|
12
|
+
# swig -c++ -csharp -o LeapCSharp.cpp -dllimport LeapCSharp -namespace Leap Leap.i
|
13
|
+
# swig -c++ -ruby -o LeapRuby.cpp LeapR.i
|
14
|
+
|
15
|
+
#if SWIGRUBY
|
16
|
+
%module(directors="1", threads="1") "leap::motion"
|
17
|
+
#else
|
18
|
+
%module(directors="1", threads="1") Leap
|
19
|
+
#endif
|
20
|
+
|
21
|
+
#pragma SWIG nowarn=325
|
22
|
+
|
23
|
+
%include "std_string.i"
|
24
|
+
%include "std_vector.i"
|
25
|
+
%include "stdint.i"
|
26
|
+
%include "attribute.i"
|
27
|
+
|
28
|
+
################################################################################
|
29
|
+
# Ignore constructors for internal use only #
|
30
|
+
################################################################################
|
31
|
+
|
32
|
+
%ignore Leap::Pointable::Pointable(PointableImplementation*);
|
33
|
+
%ignore Leap::Pointable::Pointable(FingerImplementation*);
|
34
|
+
%ignore Leap::Pointable::Pointable(ToolImplementation*);
|
35
|
+
%ignore Leap::Finger::Finger(FingerImplementation*);
|
36
|
+
%ignore Leap::Tool::Tool(ToolImplementation*);
|
37
|
+
%ignore Leap::Hand::Hand(HandImplementation*);
|
38
|
+
%ignore Leap::Gesture::Gesture(GestureImplementation*);
|
39
|
+
%ignore Leap::Screen::Screen(ScreenImplementation*);
|
40
|
+
%ignore Leap::Frame::Frame(FrameImplementation*);
|
41
|
+
%ignore Leap::Controller::Controller(ControllerImplementation*);
|
42
|
+
%ignore Leap::Device::Device(DeviceImplementation*);
|
43
|
+
%ignore Leap::InteractionBox::InteractionBox(InteractionBoxImplementation*);
|
44
|
+
|
45
|
+
#####################################################################################
|
46
|
+
# Set Attributes (done after functions are uppercased, but before vars are lowered) #
|
47
|
+
#####################################################################################
|
48
|
+
#TODO: If possible, figure out how to auomatically make any C++ function
|
49
|
+
# that is const and takes no arguments be defined as a property in C#
|
50
|
+
|
51
|
+
%define %constattrib( Class, Type, Name )
|
52
|
+
%attribute( Class, Type, Name, Name )
|
53
|
+
%enddef
|
54
|
+
|
55
|
+
%define %staticattrib(Class, AttributeType, AttributeName)
|
56
|
+
%ignore Class::AttributeName();
|
57
|
+
%ignore Class::AttributeName() const;
|
58
|
+
%immutable Class::AttributeName;
|
59
|
+
%extend Class {
|
60
|
+
AttributeType AttributeName;
|
61
|
+
}
|
62
|
+
%{
|
63
|
+
#define %mangle(Class) ##_## AttributeName ## _get() Class::AttributeName()
|
64
|
+
%}
|
65
|
+
%enddef
|
66
|
+
|
67
|
+
%define %leapattrib( Class, Type, Name )
|
68
|
+
%attributeval(Class, Leap::Type, Name, Name)
|
69
|
+
%enddef
|
70
|
+
|
71
|
+
# Apply language specific caseing
|
72
|
+
#if SWIGCSHARP
|
73
|
+
|
74
|
+
%rename(GestureType) Leap::Gesture::Type;
|
75
|
+
%rename(GestureState) Leap::Gesture::State;
|
76
|
+
%rename("%(camelcase)s") "";
|
77
|
+
|
78
|
+
#elif SWIGPYTHON || SWIGRUBY
|
79
|
+
|
80
|
+
%typemap(varout, noblock=1) SWIGTYPE & {
|
81
|
+
%set_varoutput(SWIG_NewPointerObj(%as_voidptr(&$1()), $descriptor, %newpointer_flags));
|
82
|
+
}
|
83
|
+
%rename(GestureType) Leap::Gesture::Type;
|
84
|
+
%rename(GestureState) Leap::Gesture::State;
|
85
|
+
%rename("%(undercase)s", notregexmatch$name="^[A-Z0-9_]+$") "";
|
86
|
+
|
87
|
+
#endif
|
88
|
+
|
89
|
+
#if SWIGCSHARP || SWIGPYTHON || SWIGRUBY
|
90
|
+
|
91
|
+
%constattrib( Leap::Pointable, int, id );
|
92
|
+
%leapattrib( Leap::Pointable, Hand, hand );
|
93
|
+
%leapattrib( Leap::Pointable, Vector, tipPosition );
|
94
|
+
%leapattrib( Leap::Pointable, Vector, tipVelocity );
|
95
|
+
%leapattrib( Leap::Pointable, Vector, direction );
|
96
|
+
%constattrib( Leap::Pointable, float, width );
|
97
|
+
%constattrib( Leap::Pointable, float, length );
|
98
|
+
%constattrib( Leap::Pointable, bool, isTool );
|
99
|
+
%constattrib( Leap::Pointable, bool, isFinger );
|
100
|
+
%constattrib( Leap::Pointable, bool, isValid );
|
101
|
+
%constattrib( Leap::Pointable, Leap::Pointable::Zone, touchZone )
|
102
|
+
%constattrib( Leap::Pointable, float, touchDistance )
|
103
|
+
%leapattrib( Leap::Pointable, Vector, stabilizedTipPosition )
|
104
|
+
%constattrib( Leap::Pointable, float, timeVisible );
|
105
|
+
%leapattrib( Leap::Pointable, Frame, frame );
|
106
|
+
|
107
|
+
%constattrib( Leap::Hand, int, id );
|
108
|
+
%leapattrib( Leap::Hand, PointableList, pointables );
|
109
|
+
%leapattrib( Leap::Hand, FingerList, fingers );
|
110
|
+
%leapattrib( Leap::Hand, ToolList, tools );
|
111
|
+
%leapattrib( Leap::Hand, Vector, palmPosition );
|
112
|
+
%leapattrib( Leap::Hand, Vector, palmVelocity );
|
113
|
+
%leapattrib( Leap::Hand, Vector, palmNormal );
|
114
|
+
%leapattrib( Leap::Hand, Vector, direction );
|
115
|
+
%constattrib( Leap::Hand, bool, isValid );
|
116
|
+
%leapattrib( Leap::Hand, Vector, sphereCenter );
|
117
|
+
%constattrib( Leap::Hand, float, sphereRadius );
|
118
|
+
%leapattrib( Leap::Hand, Vector, stabilizedPalmPosition )
|
119
|
+
%constattrib( Leap::Hand, float, timeVisible );
|
120
|
+
%leapattrib( Leap::Hand, Frame, frame );
|
121
|
+
|
122
|
+
%constattrib( Leap::Gesture, Leap::Gesture::Type, type )
|
123
|
+
%constattrib( Leap::Gesture, Leap::Gesture::State, state )
|
124
|
+
%constattrib( Leap::Gesture, int32_t, id );
|
125
|
+
%constattrib( Leap::Gesture, int64_t, duration );
|
126
|
+
%constattrib( Leap::Gesture, float, durationSeconds );
|
127
|
+
%leapattrib( Leap::Gesture, Frame, frame );
|
128
|
+
%leapattrib( Leap::Gesture, HandList, hands );
|
129
|
+
%leapattrib( Leap::Gesture, PointableList, pointables );
|
130
|
+
%constattrib( Leap::Gesture, bool, isValid );
|
131
|
+
%leapattrib( Leap::CircleGesture, Vector, center );
|
132
|
+
%leapattrib( Leap::CircleGesture, Vector, normal );
|
133
|
+
%constattrib( Leap::CircleGesture, float, progress );
|
134
|
+
%constattrib( Leap::CircleGesture, float, radius );
|
135
|
+
%leapattrib( Leap::CircleGesture, Pointable, pointable );
|
136
|
+
%leapattrib( Leap::SwipeGesture, Vector, startPosition );
|
137
|
+
%leapattrib( Leap::SwipeGesture, Vector, position );
|
138
|
+
%leapattrib( Leap::SwipeGesture, Vector, direction );
|
139
|
+
%constattrib( Leap::SwipeGesture, float, speed );
|
140
|
+
%leapattrib( Leap::SwipeGesture, Pointable, pointable );
|
141
|
+
%leapattrib( Leap::ScreenTapGesture, Vector, position );
|
142
|
+
%leapattrib( Leap::ScreenTapGesture, Vector, direction );
|
143
|
+
%constattrib( Leap::ScreenTapGesture, float, progress );
|
144
|
+
%leapattrib( Leap::ScreenTapGesture, Pointable, pointable );
|
145
|
+
%leapattrib( Leap::KeyTapGesture, Vector, position );
|
146
|
+
%leapattrib( Leap::KeyTapGesture, Vector, direction );
|
147
|
+
%constattrib( Leap::KeyTapGesture, float, progress );
|
148
|
+
%leapattrib( Leap::KeyTapGesture, Pointable, pointable );
|
149
|
+
|
150
|
+
# Count is made a const attribute in C# but renamed to __len__ in Python
|
151
|
+
#if SWIGCSHARP
|
152
|
+
%constattrib( Leap::PointableList, int, count );
|
153
|
+
%constattrib( Leap::FingerList, int, count );
|
154
|
+
%constattrib( Leap::ToolList, int, count );
|
155
|
+
%constattrib( Leap::HandList, int, count );
|
156
|
+
%constattrib( Leap::GestureList, int, count );
|
157
|
+
%constattrib( Leap::ScreenList, int, count );
|
158
|
+
%constattrib( Leap::DeviceList, int, count );
|
159
|
+
#endif
|
160
|
+
|
161
|
+
%constattrib( Leap::PointableList, bool, isEmpty );
|
162
|
+
%constattrib( Leap::FingerList, bool, isEmpty );
|
163
|
+
%constattrib( Leap::ToolList, bool, isEmpty );
|
164
|
+
%constattrib( Leap::HandList, bool, isEmpty );
|
165
|
+
%constattrib( Leap::GestureList, bool, isEmpty );
|
166
|
+
%constattrib( Leap::ScreenList, bool, isEmpty );
|
167
|
+
%constattrib( Leap::DeviceList, bool, isEmpty );
|
168
|
+
|
169
|
+
// %constattrib( Leap::PointableList, bool, empty );
|
170
|
+
// %constattrib( Leap::FingerList, bool, empty );
|
171
|
+
// %constattrib( Leap::ToolList, bool, empty );
|
172
|
+
// %constattrib( Leap::HandList, bool, empty );
|
173
|
+
// %constattrib( Leap::GestureList, bool, empty );
|
174
|
+
// %constattrib( Leap::ScreenList, bool, empty );
|
175
|
+
// %constattrib( Leap::DeviceList, bool, empty );
|
176
|
+
|
177
|
+
%leapattrib( Leap::PointableList, Pointable, leftmost );
|
178
|
+
%leapattrib( Leap::PointableList, Pointable, rightmost );
|
179
|
+
%leapattrib( Leap::PointableList, Pointable, frontmost );
|
180
|
+
%leapattrib( Leap::FingerList, Finger, leftmost );
|
181
|
+
%leapattrib( Leap::FingerList, Finger, rightmost );
|
182
|
+
%leapattrib( Leap::FingerList, Finger, frontmost );
|
183
|
+
%leapattrib( Leap::ToolList, Tool, leftmost );
|
184
|
+
%leapattrib( Leap::ToolList, Tool, rightmost );
|
185
|
+
%leapattrib( Leap::ToolList, Tool, frontmost );
|
186
|
+
%leapattrib( Leap::HandList, Hand, leftmost );
|
187
|
+
%leapattrib( Leap::HandList, Hand, rightmost );
|
188
|
+
%leapattrib( Leap::HandList, Hand, frontmost );
|
189
|
+
|
190
|
+
%constattrib( Leap::Frame, int64_t, id );
|
191
|
+
%constattrib( Leap::Frame, int64_t, timestamp );
|
192
|
+
%constattrib( Leap::Frame, float, currentFramesPerSecond );
|
193
|
+
%leapattrib( Leap::Frame, PointableList, pointables );
|
194
|
+
%leapattrib( Leap::Frame, FingerList, fingers );
|
195
|
+
%leapattrib( Leap::Frame, ToolList, tools );
|
196
|
+
%leapattrib( Leap::Frame, HandList, hands );
|
197
|
+
%constattrib( Leap::Frame, bool, isValid );
|
198
|
+
%leapattrib( Leap::Frame, InteractionBox, interactionBox );
|
199
|
+
|
200
|
+
%constattrib( Leap::Screen, int32_t, id );
|
201
|
+
%leapattrib( Leap::Screen, Vector, horizontalAxis );
|
202
|
+
%leapattrib( Leap::Screen, Vector, verticalAxis );
|
203
|
+
%leapattrib( Leap::Screen, Vector, bottomLeftCorner );
|
204
|
+
%constattrib( Leap::Screen, int, widthPixels );
|
205
|
+
%constattrib( Leap::Screen, int, heightPixels );
|
206
|
+
%constattrib( Leap::Screen, bool, isValid );
|
207
|
+
|
208
|
+
%constattrib( Leap::Device, float, horizontalViewAngle );
|
209
|
+
%constattrib( Leap::Device, float, verticalViewAngle );
|
210
|
+
%constattrib( Leap::Device, float, range );
|
211
|
+
%constattrib( Leap::Device, bool, isValid );
|
212
|
+
|
213
|
+
%leapattrib( Leap::InteractionBox, Vector, center );
|
214
|
+
%constattrib( Leap::InteractionBox, float, width );
|
215
|
+
%constattrib( Leap::InteractionBox, float, height );
|
216
|
+
%constattrib( Leap::InteractionBox, float, depth );
|
217
|
+
%constattrib( Leap::InteractionBox, bool, isValid );
|
218
|
+
|
219
|
+
#if SWIGCSHARP
|
220
|
+
%csmethodmodifiers Leap::Finger::invalid "public new";
|
221
|
+
%csmethodmodifiers Leap::Tool::invalid "public new";
|
222
|
+
#endif
|
223
|
+
%staticattrib( Leap::Pointable, static const Pointable&, invalid);
|
224
|
+
%staticattrib( Leap::Finger, static const Finger&, invalid);
|
225
|
+
%staticattrib( Leap::Tool, static const Tool&, invalid);
|
226
|
+
%staticattrib( Leap::Hand, static const Hand&, invalid);
|
227
|
+
%staticattrib( Leap::Gesture, static const Gesture&, invalid);
|
228
|
+
%staticattrib( Leap::Screen, static const Screen&, invalid );
|
229
|
+
%staticattrib( Leap::Device, static const Device&, invalid );
|
230
|
+
%staticattrib( Leap::InteractionBox, static const InteractionBox&, invalid );
|
231
|
+
%staticattrib( Leap::Frame, static const Frame&, invalid);
|
232
|
+
|
233
|
+
%constattrib( Leap::Vector, float, magnitude );
|
234
|
+
%constattrib( Leap::Vector, float, magnitudeSquared );
|
235
|
+
%constattrib( Leap::Vector, float, pitch );
|
236
|
+
%constattrib( Leap::Vector, float, roll );
|
237
|
+
%constattrib( Leap::Vector, float, yaw );
|
238
|
+
%leapattrib( Leap::Vector, Vector, normalized );
|
239
|
+
|
240
|
+
%constattrib( Leap::Controller, bool, isConnected );
|
241
|
+
%constattrib( Leap::Controller, bool, hasFocus );
|
242
|
+
%constattrib( Leap::Controller, Controller::PolicyFlag, policyFlags );
|
243
|
+
%leapattrib( Leap::Controller, Config, config );
|
244
|
+
%leapattrib( Leap::Controller, ScreenList, locatedScreens );
|
245
|
+
%leapattrib( Leap::Controller, DeviceList, devices );
|
246
|
+
|
247
|
+
%staticattrib( Leap::Vector, static const Vector&, zero );
|
248
|
+
%staticattrib( Leap::Vector, static const Vector&, xAxis );
|
249
|
+
%staticattrib( Leap::Vector, static const Vector&, yAxis );
|
250
|
+
%staticattrib( Leap::Vector, static const Vector&, zAxis );
|
251
|
+
%staticattrib( Leap::Vector, static const Vector&, forward );
|
252
|
+
%staticattrib( Leap::Vector, static const Vector&, backward );
|
253
|
+
%staticattrib( Leap::Vector, static const Vector&, left );
|
254
|
+
%staticattrib( Leap::Vector, static const Vector&, right );
|
255
|
+
%staticattrib( Leap::Vector, static const Vector&, up );
|
256
|
+
%staticattrib( Leap::Vector, static const Vector&, down );
|
257
|
+
|
258
|
+
%staticattrib( Leap::Matrix, static const Matrix&, identity );
|
259
|
+
|
260
|
+
#endif
|
261
|
+
|
262
|
+
#if SWIGCSHARP
|
263
|
+
|
264
|
+
%rename("%(lowercamelcase)s", %$isvariable) "";
|
265
|
+
%ignore Leap::DEG_TO_RAD;
|
266
|
+
%ignore Leap::RAD_TO_DEG;
|
267
|
+
%ignore Leap::PI;
|
268
|
+
|
269
|
+
SWIG_CSBODY_PROXY(public, public, SWIGTYPE)
|
270
|
+
|
271
|
+
#elif SWIGPYTHON || SWIGRUBY
|
272
|
+
|
273
|
+
%rename("%(camelcase)s", %$isclass) "";
|
274
|
+
%rename("%(camelcase)s", %$isconstructor) "";
|
275
|
+
|
276
|
+
#elif SWIGJAVA
|
277
|
+
|
278
|
+
%ignore Leap::DEG_TO_RAD;
|
279
|
+
%ignore Leap::RAD_TO_DEG;
|
280
|
+
%ignore Leap::PI;
|
281
|
+
|
282
|
+
# Use proper Java enums
|
283
|
+
%include "enums.swg"
|
284
|
+
%javaconst(1);
|
285
|
+
|
286
|
+
SWIG_JAVABODY_PROXY(public, public, SWIGTYPE)
|
287
|
+
|
288
|
+
#endif
|
289
|
+
|
290
|
+
# Ignore C++ streaming operator
|
291
|
+
%ignore operator<<;
|
292
|
+
# Ignore C++ equal operator
|
293
|
+
%ignore operator=;
|
294
|
+
|
295
|
+
#if SWIGPYTHON
|
296
|
+
%begin %{
|
297
|
+
#if defined(_WIN32) && defined(_DEBUG)
|
298
|
+
// Workaround for obscure STL template error
|
299
|
+
#include <vector>
|
300
|
+
// Workaround for non-existent Python debug library
|
301
|
+
#define _TMP_DEBUG _DEBUG
|
302
|
+
#undef _DEBUG
|
303
|
+
#include <Python.h>
|
304
|
+
#define _DEBUG _TMP_DEBUG
|
305
|
+
#undef _TMP_DEBUG
|
306
|
+
#endif
|
307
|
+
#if defined(__APPLE__)
|
308
|
+
#pragma GCC diagnostic ignored "-Wself-assign"
|
309
|
+
#endif
|
310
|
+
%}
|
311
|
+
#endif
|
312
|
+
|
313
|
+
#if SWIGRUBY
|
314
|
+
%begin %{
|
315
|
+
// Ruby specific begin
|
316
|
+
%}
|
317
|
+
#endif
|
318
|
+
|
319
|
+
#if SWIGCSHARP || SWIGJAVA
|
320
|
+
%begin %{
|
321
|
+
#if defined(_WIN32)
|
322
|
+
#include <windows.h>
|
323
|
+
// When dynamically loading the Leap C# DLL, set the DLL search path to look in
|
324
|
+
// the same the directory. This will allow loading the Leap.dll. Create the
|
325
|
+
// Leap C# DLL with the /DELAYLOAD:Leap.dll link option.
|
326
|
+
extern "C" BOOL WINAPI DllMain(
|
327
|
+
_In_ HINSTANCE hinstDLL,
|
328
|
+
_In_ DWORD fdwReason,
|
329
|
+
_In_ LPVOID lpvReserved)
|
330
|
+
{
|
331
|
+
if (lpvReserved == 0) {
|
332
|
+
static TCHAR lpPrevPathName[1024];
|
333
|
+
static BOOL restore = FALSE;
|
334
|
+
|
335
|
+
if (fdwReason == DLL_PROCESS_ATTACH) {
|
336
|
+
TCHAR lpPathName[1024];
|
337
|
+
int len;
|
338
|
+
|
339
|
+
len = GetDllDirectory(static_cast<DWORD>(sizeof(lpPrevPathName) - 1),
|
340
|
+
lpPrevPathName);
|
341
|
+
if (len < 0 && len >= sizeof(lpPrevPathName)) {
|
342
|
+
len = 0;
|
343
|
+
}
|
344
|
+
lpPrevPathName[len] = '\0';
|
345
|
+
len = static_cast<int>(GetModuleFileName(static_cast<HMODULE>(hinstDLL),
|
346
|
+
lpPathName, static_cast<DWORD>(sizeof(lpPathName))));
|
347
|
+
if (len > 0 && len < sizeof(lpPathName)) {
|
348
|
+
for (int i = len; i >= 0; i--) {
|
349
|
+
if (lpPathName[i] == '\\' || lpPathName[i] == '/') {
|
350
|
+
lpPathName[i] = '\0';
|
351
|
+
restore = SetDllDirectory(lpPathName);
|
352
|
+
break;
|
353
|
+
}
|
354
|
+
}
|
355
|
+
}
|
356
|
+
} else if (fdwReason == DLL_PROCESS_DETACH) {
|
357
|
+
if (restore && lpPrevPathName[0] != '\0') {
|
358
|
+
SetDllDirectory(lpPrevPathName);
|
359
|
+
restore = FALSE;
|
360
|
+
}
|
361
|
+
}
|
362
|
+
}
|
363
|
+
return TRUE;
|
364
|
+
}
|
365
|
+
#endif
|
366
|
+
%}
|
367
|
+
#endif
|
368
|
+
|
369
|
+
%typemap(csin, pre=" lock(arg0) {", post=" $csinput.Dispose();\n }") const Leap::Controller& "Controller.getCPtr($csinput)"
|
370
|
+
|
371
|
+
%header %{
|
372
|
+
#define SWIG
|
373
|
+
#include "Leap.h"
|
374
|
+
%}
|
375
|
+
|
376
|
+
%feature("director") Leap::Listener;
|
377
|
+
#if SWIGPYTHON
|
378
|
+
%feature("director:except") {
|
379
|
+
if ($error != NULL) {
|
380
|
+
PyErr_Print();
|
381
|
+
}
|
382
|
+
}
|
383
|
+
#elif SWIGRUBY
|
384
|
+
# TODO - complete
|
385
|
+
#endif
|
386
|
+
|
387
|
+
%pragma(java) jniclasscode=%{
|
388
|
+
static {
|
389
|
+
try {
|
390
|
+
System.loadLibrary("LeapJava");
|
391
|
+
} catch (UnsatisfiedLinkError e) {
|
392
|
+
System.err.println("Native code library failed to load. \n" + e);
|
393
|
+
System.exit(1);
|
394
|
+
}
|
395
|
+
}
|
396
|
+
%}
|
397
|
+
|
398
|
+
################################################################################
|
399
|
+
# Operator overloading #
|
400
|
+
################################################################################
|
401
|
+
|
402
|
+
#if SWIGCSHARP
|
403
|
+
|
404
|
+
%ignore *::operator+=;
|
405
|
+
%ignore *::operator-=;
|
406
|
+
%ignore *::operator*=;
|
407
|
+
%ignore *::operator/=;
|
408
|
+
%ignore *::operator!=;
|
409
|
+
%ignore Leap::Vector::toFloatPointer;
|
410
|
+
%ignore Leap::Matrix::toArray3x3;
|
411
|
+
%ignore Leap::Matrix::toArray4x4;
|
412
|
+
%ignore Leap::FloatArray;
|
413
|
+
|
414
|
+
%rename(Equals) *::operator ==;
|
415
|
+
%rename(_operator_add) *::operator +;
|
416
|
+
%rename(_operator_sub) *::operator -;
|
417
|
+
%rename(_operator_mul) *::operator *;
|
418
|
+
%rename(_operator_div) *::operator /;
|
419
|
+
%rename(_operator_get) *::operator [];
|
420
|
+
%rename(_operator_to_float) *::operator const float*;
|
421
|
+
%csmethodmodifiers *::operator + "private";
|
422
|
+
%csmethodmodifiers *::operator - "private";
|
423
|
+
%csmethodmodifiers *::operator * "private";
|
424
|
+
%csmethodmodifiers *::operator / "private";
|
425
|
+
%csmethodmodifiers *::operator [] "private";
|
426
|
+
%csmethodmodifiers *::operator const float* "private";
|
427
|
+
|
428
|
+
%typemap(cscode) Leap::Vector
|
429
|
+
%{
|
430
|
+
/** Add vectors component-wise. */
|
431
|
+
public static Vector operator + (Vector v1, Vector v2) {
|
432
|
+
return v1._operator_add(v2);
|
433
|
+
}
|
434
|
+
/** Subtract vectors component-wise. */
|
435
|
+
public static Vector operator - (Vector v1, Vector v2) {
|
436
|
+
return v1._operator_sub(v2);
|
437
|
+
}
|
438
|
+
/** Multiply vector by a scalar. */
|
439
|
+
public static Vector operator * (Vector v1, float scalar) {
|
440
|
+
return v1._operator_mul(scalar);
|
441
|
+
}
|
442
|
+
/** Multiply vector by a scalar on the left-hand side. */
|
443
|
+
public static Vector operator * (float scalar, Vector v1) {
|
444
|
+
return v1._operator_mul(scalar);
|
445
|
+
}
|
446
|
+
/** Divide vector by a scalar. */
|
447
|
+
public static Vector operator / (Vector v1, float scalar) {
|
448
|
+
return v1._operator_div(scalar);
|
449
|
+
}
|
450
|
+
/** Negate a vector. */
|
451
|
+
public static Vector operator - (Vector v1) {
|
452
|
+
return v1._operator_sub();
|
453
|
+
}
|
454
|
+
/** Convert this vector to an array of three float values: [x,y,z]. */
|
455
|
+
public float[] ToFloatArray() {
|
456
|
+
return new float[] {x, y, z};
|
457
|
+
}
|
458
|
+
%}
|
459
|
+
%typemap(cscode) Leap::Matrix
|
460
|
+
%{
|
461
|
+
/** Multiply two matrices. */
|
462
|
+
public static Matrix operator * (Matrix m1, Matrix m2) {
|
463
|
+
return m1._operator_mul(m2);
|
464
|
+
}
|
465
|
+
/** Copy this matrix to the specified array of 9 float values in row-major order. */
|
466
|
+
public float[] ToArray3x3(float[] output) {
|
467
|
+
output[0] = xBasis.x; output[1] = xBasis.y; output[2] = xBasis.z;
|
468
|
+
output[3] = yBasis.x; output[4] = yBasis.y; output[5] = yBasis.z;
|
469
|
+
output[6] = zBasis.x; output[7] = zBasis.y; output[8] = zBasis.z;
|
470
|
+
return output;
|
471
|
+
}
|
472
|
+
/** Copy this matrix to the specified array containing 9 double values in row-major order. */
|
473
|
+
public double[] ToArray3x3(double[] output) {
|
474
|
+
output[0] = xBasis.x; output[1] = xBasis.y; output[2] = xBasis.z;
|
475
|
+
output[3] = yBasis.x; output[4] = yBasis.y; output[5] = yBasis.z;
|
476
|
+
output[6] = zBasis.x; output[7] = zBasis.y; output[8] = zBasis.z;
|
477
|
+
return output;
|
478
|
+
}
|
479
|
+
/** Convert this matrix to an array containing 9 float values in row-major order. */
|
480
|
+
public float[] ToArray3x3() {
|
481
|
+
return ToArray3x3(new float[9]);
|
482
|
+
}
|
483
|
+
/** Copy this matrix to the specified array of 16 float values in row-major order. */
|
484
|
+
public float[] ToArray4x4(float[] output) {
|
485
|
+
output[0] = xBasis.x; output[1] = xBasis.y; output[2] = xBasis.z; output[3] = 0.0f;
|
486
|
+
output[4] = yBasis.x; output[5] = yBasis.y; output[6] = yBasis.z; output[7] = 0.0f;
|
487
|
+
output[8] = zBasis.x; output[9] = zBasis.y; output[10] = zBasis.z; output[11] = 0.0f;
|
488
|
+
output[12] = origin.x; output[13] = origin.y; output[14] = origin.z; output[15] = 1.0f;
|
489
|
+
return output;
|
490
|
+
}
|
491
|
+
/** Copy this matrix to the specified array of 16 double values in row-major order. */
|
492
|
+
public double[] ToArray4x4(double[] output) {
|
493
|
+
output[0] = xBasis.x; output[1] = xBasis.y; output[2] = xBasis.z; output[3] = 0.0f;
|
494
|
+
output[4] = yBasis.x; output[5] = yBasis.y; output[6] = yBasis.z; output[7] = 0.0f;
|
495
|
+
output[8] = zBasis.x; output[9] = zBasis.y; output[10] = zBasis.z; output[11] = 0.0f;
|
496
|
+
output[12] = origin.x; output[13] = origin.y; output[14] = origin.z; output[15] = 1.0f;
|
497
|
+
return output;
|
498
|
+
}
|
499
|
+
/** Convert this matrix to an array containing 16 float values in row-major order. */
|
500
|
+
public float[] ToArray4x4() {
|
501
|
+
return ToArray4x4(new float[16]);
|
502
|
+
}
|
503
|
+
%}
|
504
|
+
|
505
|
+
#elif SWIGJAVA
|
506
|
+
|
507
|
+
%ignore *::operator+=;
|
508
|
+
%ignore *::operator-=;
|
509
|
+
%ignore *::operator*=;
|
510
|
+
%ignore *::operator/=;
|
511
|
+
%ignore *::operator!=;
|
512
|
+
%ignore Leap::Vector::toFloatPointer;
|
513
|
+
%ignore Leap::Matrix::toArray3x3;
|
514
|
+
%ignore Leap::Matrix::toArray4x4;
|
515
|
+
%ignore Leap::FloatArray;
|
516
|
+
|
517
|
+
%rename(plus) *::operator+;
|
518
|
+
%rename(minus) *::operator-;
|
519
|
+
%rename(opposite) *::operator-() const;
|
520
|
+
%rename(times) *::operator*;
|
521
|
+
%rename(divide) *::operator/;
|
522
|
+
%rename(get) *::operator [];
|
523
|
+
%rename(equals) *::operator==;
|
524
|
+
|
525
|
+
%typemap(javacode) Leap::Vector
|
526
|
+
%{
|
527
|
+
public float[] toFloatArray() {
|
528
|
+
return new float[] {getX(), getY(), getZ()};
|
529
|
+
}
|
530
|
+
%}
|
531
|
+
%typemap(javacode) Leap::Matrix
|
532
|
+
%{
|
533
|
+
public float[] toArray3x3(float[] output) {
|
534
|
+
output[0] = getXBasis().getX(); output[1] = getXBasis().getY(); output[2] = getXBasis().getZ();
|
535
|
+
output[3] = getYBasis().getX(); output[4] = getYBasis().getY(); output[5] = getYBasis().getZ();
|
536
|
+
output[6] = getZBasis().getX(); output[7] = getZBasis().getY(); output[8] = getZBasis().getZ();
|
537
|
+
return output;
|
538
|
+
}
|
539
|
+
public double[] toArray3x3(double[] output) {
|
540
|
+
output[0] = getXBasis().getX(); output[1] = getXBasis().getY(); output[2] = getXBasis().getZ();
|
541
|
+
output[3] = getYBasis().getX(); output[4] = getYBasis().getY(); output[5] = getYBasis().getZ();
|
542
|
+
output[6] = getZBasis().getX(); output[7] = getZBasis().getY(); output[8] = getZBasis().getZ();
|
543
|
+
return output;
|
544
|
+
}
|
545
|
+
public float[] toArray3x3() {
|
546
|
+
return toArray3x3(new float[9]);
|
547
|
+
}
|
548
|
+
public float[] toArray4x4(float[] output) {
|
549
|
+
output[0] = getXBasis().getX(); output[1] = getXBasis().getY(); output[2] = getXBasis().getZ(); output[3] = 0.0f;
|
550
|
+
output[4] = getYBasis().getX(); output[5] = getYBasis().getY(); output[6] = getYBasis().getZ(); output[7] = 0.0f;
|
551
|
+
output[8] = getZBasis().getX(); output[9] = getZBasis().getY(); output[10] = getZBasis().getZ(); output[11] = 0.0f;
|
552
|
+
output[12] = getOrigin().getX(); output[13] = getOrigin().getY(); output[14] = getOrigin().getZ(); output[15] = 1.0f;
|
553
|
+
return output;
|
554
|
+
}
|
555
|
+
public double[] toArray4x4(double[] output) {
|
556
|
+
output[0] = getXBasis().getX(); output[1] = getXBasis().getY(); output[2] = getXBasis().getZ(); output[3] = 0.0f;
|
557
|
+
output[4] = getYBasis().getX(); output[5] = getYBasis().getY(); output[6] = getYBasis().getZ(); output[7] = 0.0f;
|
558
|
+
output[8] = getZBasis().getX(); output[9] = getZBasis().getY(); output[10] = getZBasis().getZ(); output[11] = 0.0f;
|
559
|
+
output[12] = getOrigin().getX(); output[13] = getOrigin().getY(); output[14] = getOrigin().getZ(); output[15] = 1.0f;
|
560
|
+
return output;
|
561
|
+
}
|
562
|
+
public float[] toArray4x4() {
|
563
|
+
return toArray4x4(new float[16]);
|
564
|
+
}
|
565
|
+
%}
|
566
|
+
|
567
|
+
#elif SWIGPYTHON
|
568
|
+
|
569
|
+
%ignore Leap::Interface::operator=;
|
570
|
+
%ignore Leap::ConstListIterator::operator++;
|
571
|
+
%ignore Leap::Vector::toFloatPointer;
|
572
|
+
%ignore Leap::Matrix::toArray3x3;
|
573
|
+
%ignore Leap::Matrix::toArray4x4;
|
574
|
+
%ignore Leap::FloatArray;
|
575
|
+
|
576
|
+
%rename(__getitem__) *::operator [];
|
577
|
+
|
578
|
+
%extend Leap::Vector {
|
579
|
+
%pythoncode {
|
580
|
+
def to_float_array(self): return [self.x, self.y, self.z]
|
581
|
+
def to_tuple(self): return (self.x, self.y, self.z)
|
582
|
+
%}}
|
583
|
+
%extend Leap::Matrix {
|
584
|
+
%pythoncode {
|
585
|
+
def to_array_3x3(self, output = None):
|
586
|
+
if output is None:
|
587
|
+
output = [0]*9
|
588
|
+
output[0], output[1], output[2] = self.x_basis.x, self.x_basis.y, self.x_basis.z
|
589
|
+
output[3], output[4], output[5] = self.y_basis.x, self.y_basis.y, self.y_basis.z
|
590
|
+
output[6], output[7], output[8] = self.z_basis.x, self.z_basis.y, self.z_basis.z
|
591
|
+
return output
|
592
|
+
def to_array_4x4(self, output = None):
|
593
|
+
if output is None:
|
594
|
+
output = [0]*16
|
595
|
+
output[0], output[1], output[2], output[3] = self.x_basis.x, self.x_basis.y, self.x_basis.z, 0.0
|
596
|
+
output[4], output[5], output[6], output[7] = self.y_basis.x, self.y_basis.y, self.y_basis.z, 0.0
|
597
|
+
output[8], output[9], output[10], output[11] = self.z_basis.x, self.z_basis.y, self.z_basis.z, 0.0
|
598
|
+
output[12], output[13], output[14], output[15] = self.origin.x, self.origin.y, self.origin.z, 1.0
|
599
|
+
return output
|
600
|
+
%}}
|
601
|
+
|
602
|
+
#elif SWIGRUBY
|
603
|
+
|
604
|
+
%ignore Leap::Vector::toFloatPointer;
|
605
|
+
%ignore Leap::Matrix::toArray3x3;
|
606
|
+
%ignore Leap::Matrix::toArray4x4;
|
607
|
+
%ignore Leap::FloatArray;
|
608
|
+
# TODO - complete
|
609
|
+
|
610
|
+
#endif
|
611
|
+
|
612
|
+
################################################################################
|
613
|
+
# List Helpers #
|
614
|
+
################################################################################
|
615
|
+
|
616
|
+
#if SWIGCSHARP
|
617
|
+
|
618
|
+
%define %leap_iterator_helper(BaseType)
|
619
|
+
%typemap(csinterfaces_derived) Leap::BaseType##List "System.Collections.Generic.IEnumerable<BaseType>"
|
620
|
+
%typemap(cscode) Leap::BaseType##List
|
621
|
+
%{
|
622
|
+
private class BaseType##List##Enumerator : System.Collections.Generic.IEnumerator<BaseType> {
|
623
|
+
private BaseType##List _list;
|
624
|
+
private int _index;
|
625
|
+
public BaseType##List##Enumerator(BaseType##List list) {
|
626
|
+
_list = list;
|
627
|
+
_index = -1;
|
628
|
+
}
|
629
|
+
public void Reset() {
|
630
|
+
_index = -1;
|
631
|
+
}
|
632
|
+
public BaseType Current {
|
633
|
+
get {
|
634
|
+
return _list._operator_get(_index);
|
635
|
+
}
|
636
|
+
}
|
637
|
+
object System.Collections.IEnumerator.Current {
|
638
|
+
get {
|
639
|
+
return this.Current;
|
640
|
+
}
|
641
|
+
}
|
642
|
+
public bool MoveNext() {
|
643
|
+
_index++;
|
644
|
+
return (_index < _list.Count);
|
645
|
+
}
|
646
|
+
public void Dispose() {
|
647
|
+
//No cleanup needed
|
648
|
+
}
|
649
|
+
}
|
650
|
+
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
|
651
|
+
return this.GetEnumerator();
|
652
|
+
}
|
653
|
+
public System.Collections.Generic.IEnumerator<BaseType> GetEnumerator() {
|
654
|
+
return new BaseType##List##Enumerator(this);
|
655
|
+
}
|
656
|
+
public BaseType this[int index] {
|
657
|
+
get { return _operator_get(index); }
|
658
|
+
}
|
659
|
+
%}
|
660
|
+
%enddef
|
661
|
+
|
662
|
+
#elif SWIGJAVA
|
663
|
+
|
664
|
+
%define %leap_iterator_helper(BaseType)
|
665
|
+
%typemap(javainterfaces) Leap::BaseType##List "Iterable<BaseType>"
|
666
|
+
%typemap(javacode) Leap::BaseType##List
|
667
|
+
%{
|
668
|
+
public class BaseType##ListIterator implements java.util.Iterator<BaseType> {
|
669
|
+
int index = 0;
|
670
|
+
@Override public boolean hasNext() {
|
671
|
+
return index < count();
|
672
|
+
}
|
673
|
+
@Override public BaseType next() {
|
674
|
+
return get(index++);
|
675
|
+
}
|
676
|
+
@Override public void remove() {
|
677
|
+
}
|
678
|
+
}
|
679
|
+
@Override public java.util.Iterator<BaseType> iterator() {
|
680
|
+
return new BaseType##ListIterator();
|
681
|
+
}
|
682
|
+
%}
|
683
|
+
%enddef
|
684
|
+
|
685
|
+
#elif SWIGPYTHON
|
686
|
+
|
687
|
+
%define %leap_iterator_helper(BaseType)
|
688
|
+
%rename(__len__) Leap::BaseType##List::count;
|
689
|
+
%extend Leap::BaseType##List {
|
690
|
+
%pythoncode {
|
691
|
+
def __iter__(self):
|
692
|
+
_pos = 0
|
693
|
+
while _pos < len(self):
|
694
|
+
yield self[_pos]
|
695
|
+
_pos += 1
|
696
|
+
%}}
|
697
|
+
%enddef
|
698
|
+
|
699
|
+
#elif SWIGRUBY
|
700
|
+
|
701
|
+
%define %leap_iterator_helper(BaseType)
|
702
|
+
%enddef
|
703
|
+
|
704
|
+
#else
|
705
|
+
|
706
|
+
%define %leap_iterator_helper(BaseType)
|
707
|
+
%enddef
|
708
|
+
|
709
|
+
#endif
|
710
|
+
|
711
|
+
%define %leap_list_helper(BaseType)
|
712
|
+
%ignore Leap::BaseType##List::BaseType##List(const ListBaseImplementation<BaseType>&);
|
713
|
+
%ignore Leap::BaseType##List::const_iterator;
|
714
|
+
%ignore Leap::BaseType##List::begin() const;
|
715
|
+
%ignore Leap::BaseType##List::end() const;
|
716
|
+
%leap_iterator_helper(BaseType)
|
717
|
+
%enddef
|
718
|
+
|
719
|
+
%leap_list_helper(Pointable);
|
720
|
+
%leap_list_helper(Finger);
|
721
|
+
%leap_list_helper(Tool);
|
722
|
+
%leap_list_helper(Gesture);
|
723
|
+
%leap_list_helper(Hand);
|
724
|
+
%leap_list_helper(Screen);
|
725
|
+
%leap_list_helper(Device);
|
726
|
+
|
727
|
+
################################################################################
|
728
|
+
# Config Helpers #
|
729
|
+
################################################################################
|
730
|
+
|
731
|
+
#if SWIGPYTHON
|
732
|
+
|
733
|
+
// Use dynamic typing to get or set any type of config value with one function
|
734
|
+
%extend Leap::Config {
|
735
|
+
%pythoncode {
|
736
|
+
def get(self, *args):
|
737
|
+
type = LeapPython.Config_type(self, *args)
|
738
|
+
if type == LeapPython.Config_TYPE_BOOLEAN:
|
739
|
+
return LeapPython.Config_get_bool(self, *args)
|
740
|
+
elif type == LeapPython.Config_TYPE_INT32:
|
741
|
+
return LeapPython.Config_get_int_32(self, *args)
|
742
|
+
elif type == LeapPython.Config_TYPE_FLOAT:
|
743
|
+
return LeapPython.Config_get_float(self, *args)
|
744
|
+
elif type == LeapPython.Config_TYPE_STRING:
|
745
|
+
return LeapPython.Config_get_string(self, *args)
|
746
|
+
return None
|
747
|
+
def set(self, *args):
|
748
|
+
type = LeapPython.Config_type(self, *args[:-1]) # Do not pass value through
|
749
|
+
if type == LeapPython.Config_TYPE_BOOLEAN:
|
750
|
+
return LeapPython.Config_set_bool(self, *args)
|
751
|
+
elif type == LeapPython.Config_TYPE_INT32:
|
752
|
+
return LeapPython.Config_set_int_32(self, *args)
|
753
|
+
elif type == LeapPython.Config_TYPE_FLOAT:
|
754
|
+
return LeapPython.Config_set_float(self, *args)
|
755
|
+
elif type == LeapPython.Config_TYPE_STRING:
|
756
|
+
return LeapPython.Config_set_string(self, *args)
|
757
|
+
return False
|
758
|
+
%}}
|
759
|
+
// Ignore methods that are unnecessary due to get and set functions defined above
|
760
|
+
%feature("shadow") Leap::Config::type(const std::string& key) const %{%}
|
761
|
+
%feature("shadow") Leap::Config::getBool(const std::string& key) const %{%}
|
762
|
+
%feature("shadow") Leap::Config::setBool(const std::string& key, bool value) %{%}
|
763
|
+
%feature("shadow") Leap::Config::getInt32(const std::string& key) const %{%}
|
764
|
+
%feature("shadow") Leap::Config::setInt32(const std::string& key, int32_t value) %{%}
|
765
|
+
%feature("shadow") Leap::Config::getFloat(const std::string& key) const %{%}
|
766
|
+
%feature("shadow") Leap::Config::setFloat(const std::string& key, float value) %{%}
|
767
|
+
%feature("shadow") Leap::Config::getString(const std::string& key) const %{%}
|
768
|
+
%feature("shadow") Leap::Config::setString(const std::string& key, const std::string& value) %{%}
|
769
|
+
|
770
|
+
#elif SWIGRUBY
|
771
|
+
|
772
|
+
# TODO - complete
|
773
|
+
|
774
|
+
#endif
|
775
|
+
|
776
|
+
################################################################################
|
777
|
+
# ToString methods #
|
778
|
+
################################################################################
|
779
|
+
|
780
|
+
#if SWIGCSHARP
|
781
|
+
|
782
|
+
%csmethodmodifiers *::toString "public override";
|
783
|
+
|
784
|
+
#elif SWIGJAVA
|
785
|
+
|
786
|
+
%javamethodmodifiers *::toString "@Override public";
|
787
|
+
|
788
|
+
#elif SWIGPYTHON
|
789
|
+
|
790
|
+
%rename(__str__) *::toString;
|
791
|
+
|
792
|
+
#elif SWIGRUBY
|
793
|
+
|
794
|
+
%rename(to_s) *::toString;
|
795
|
+
|
796
|
+
#endif
|
797
|
+
|
798
|
+
%include "LeapMath.h"
|
799
|
+
%include "Leap.h"
|