-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLeapObjectiveC.h
4903 lines (4797 loc) · 168 KB
/
LeapObjectiveC.h
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/******************************************************************************\
* Copyright (C) 2012-2013 Leap Motion, Inc. All rights reserved. *
* Leap Motion proprietary and confidential. Not for distribution. *
* Use subject to the terms of the Leap Motion SDK Agreement available at *
* https://developer.leapmotion.com/sdk_agreement, or another agreement *
* between Leap Motion and you, your company or other organization. *
\******************************************************************************/
#import <Foundation/Foundation.h>
/*************************************************************************
This wrapper works by doing a deep copy of the bulk of the hand and finger
hierarchy as soon as you the user requests `[controller frame]`. This is
enables us to set up the appropriate linkage between LeapHand and
LeapPointable ObjectiveC objects.
The motions API forced our hand to move the Frame and Hand objects towards
thin wrappers. Each now contains a pointer to its corresponding C++ object.
The screen API brought Pointable objects to wrap and keep around a C++
Leap::Pointable object as well.
Because the wrapped C++ object is kept around, attributes such as position
and velocity now have their ObjectiveC objects created lazily.
Major Leap API features supported in this wrapper today:
* Obtaining data through both polling (LeapController only) as well as
through callbacks
* Waiting for single-threaded event callbacks through NSNotification objects
(LeapListener), in addition to ObjectiveC delegates (LeapDelegate)
* Getting lists of hands, fingers, tools, or pointables from a frame or hand
(e.g. `[frame hands]`, `[frame tools]`, or `[hand fingers]`)
* Getting hands, fingers, tools, or pointables a frame or hand by ID
(e.g. `[frame hand:ID]`, `[frame tool:ID]`, or `[hand finger:ID]`)
* Querying back up the hierarchy, e.g. `[finger hand]` or `[hand frame]`
* Various hand/finger/tool properties: direction, palmNormal, sphereRadius,
and more
* LeapVector math helper functions: pitch, roll, yaw, vector add, scalar
multiply, dot product, cross product, LeapMatrix, and more
* Motions (translation/rotation/scale) from LeapHand and LeapFrame classes
* LeapGesture events, including swipe, circle, screen tap, and key tap
* LeapScreen location/orientation/size as well as intersection/projection
* LeapConfig class for configuring gesture recognition parameters
Notes:
* Class names are prefixed by Leap, although LM and LPM were considered.
Users may change the prefix locally, for example:
sed -i '.bak' 's/Leap\([A-NP-Z]\)/LPM\1/g' LeapObjectiveC.*
# above regexp matches LeapController, LeapVector, not LeapObjectiveC
* Requires XCode 4.2+, relies on Automatic Reference Counting (ARC),
minimum target OS X 10.7
* Contributions are welcome. Contact us via https://developer.leapmotion.com
*************************************************************************/
//////////////////////////////////////////////////////////////////////////
//VECTOR
/**
* The LeapVector class represents a three-component mathematical vector or point
* such as a direction or position in three-dimensional space.
*
* The Leap software employs a right-handed Cartesian coordinate system.
* Values given are in units of real-world millimeters. The origin is centered
* at the center of the Leap device. The x- and z-axes lie in the horizontal
* plane, with the x-axis running parallel to the long edge of the device.
* The y-axis is vertical, with positive values increasing upwards (in contrast
* to the downward orientation of most computer graphics coordinate systems).
* The z-axis has positive values increasing away from the computer screen.
*
* <img src="../docs/images/Leap_Axes.png"/>
*
* @available Since 1.0
*/
@interface LeapVector : NSObject
/**
* Creates a new LeapVector with the specified component values.
*
* @example Vector_Constructor_1.txt
*
* @param x The horizontal component.
* @param y The vertical component.
* @param z The depth component.
* @available Since 1.0
*/
- (id)initWithX:(float)x y:(float)y z:(float)z;
/**
* Copies the specified LeapVector.
*
* @example Vector_Constructor_2.txt
*
* @param vector The LeapVector to copy.
* @available Since 1.0
*/
- (id)initWithVector:(const LeapVector *)vector;
- (NSString *)description;
/**
* The magnitude, or length, of this vector.
*
* @example Vector_Magnitude.txt
*
* The magnitude is the L2 norm, or Euclidean distance between the origin and
* the point represented by the (x, y, z) components of this LeapVector object.
*
* @returns The length of this vector.
* @available Since 1.0
*/
@property (nonatomic, getter = magnitude, readonly)float magnitude;
- (float)magnitude;
/**
* The square of the magnitude, or length, of this vector.
*
* @example Vector_Magnitude_Squared.txt
*
* @returns The square of the length of this vector.
* @available Since 1.0
*/
@property (nonatomic, getter = magnitudeSquared, readonly)float magnitudeSquared;
- (float)magnitudeSquared;
/**
* The distance between the point represented by this LeapVector
* object and a point represented by the specified LeapVector object.
*
* @example Vector_DistanceTo.txt
*
* @param vector A LeapVector object.
* @returns The distance from this point to the specified point.
* @available Since 1.0
*/
- (float)distanceTo:(const LeapVector *)vector;
/**
* The angle between this vector and the specified vector in radians.
*
* @example Vector_AngleTo.txt
*
* The angle is measured in the plane formed by the two vectors. The
* angle returned is always the smaller of the two conjugate angles.
* Thus `[A angleTo:B] == [B angleTo:A]` and is always a positive
* value less than or equal to pi radians (180 degrees).
*
* If either vector has zero length, then this function returns zero.
*
* <img src="../docs/images/Math_AngleTo.png"/>
*
* @param vector A LeapVector object.
* @returns The angle between this vector and the specified vector in radians.
* @available Since 1.0
*/
- (float)angleTo:(const LeapVector *)vector;
/**
* The pitch angle in radians.
*
* @example Vector_Pitch.txt
*
* Pitch is the angle between the negative z-axis and the projection of
* the vector onto the y-z plane. In other words, pitch represents rotation
* around the x-axis.
* If the vector points upward, the returned angle is between 0 and pi radians
* (180 degrees); if it points downward, the angle is between 0 and -pi radians.
*
* <img src="../docs/images/Math_Pitch_Angle.png"/>
*
* @returns The angle of this vector above or below the horizon (x-z plane).
* @available Since 1.0
*/
@property (nonatomic, getter = pitch, readonly)float pitch;
- (float)pitch;
/**
* The roll angle in radians.
*
* @example Vector_Roll.txt
*
* Roll is the angle between the y-axis and the projection of
* the vector onto the x-y plane. In other words, roll represents rotation
* around the z-axis. If the vector points to the left of the y-axis,
* then the returned angle is between 0 and pi radians (180 degrees);
* if it points to the right, the angle is between 0 and -pi radians.
*
* <img src="../docs/images/Math_Roll_Angle.png"/>
*
* Use this function to get roll angle of the plane to which this vector is a
* normal. For example, if this vector represents the normal to the palm,
* then this function returns the tilt or roll of the palm plane compared
* to the horizontal (x-z) plane.
*
* @returns The angle of this vector to the right or left of the y-axis.
* @available Since 1.0
*/
@property (nonatomic, getter = roll, readonly)float roll;
- (float)roll;
/**
* The yaw angle in radians.
*
* @example Vector_Yaw.txt
*
* Yaw is the angle between the negative z-axis and the projection of
* the vector onto the x-z plane. In other words, yaw represents rotation
* around the y-axis. If the vector points to the right of the negative z-axis,
* then the returned angle is between 0 and pi radians (180 degrees);
* if it points to the left, the angle is between 0 and -pi radians.
*
* <img src="../docs/images/Math_Yaw_Angle.png"/>
*
* @returns The angle of this vector to the right or left of the negative z-axis.
* @available Since 1.0
*/
@property (nonatomic, getter = yaw, readonly)float yaw;
- (float)yaw;
/**
* Adds two vectors.
*
* @example Vector_Plus.txt
*
* @param vector The LeapVector addend.
* @returns The sum of the two LeapVectors.
* @available Since 1.0
*/
- (LeapVector *)plus:(const LeapVector *)vector;
/**
* Subtract a vector from this vector.
*
* @example Vector_Minus.txt
*
* @param vector the LeapVector subtrahend.
* @returns the difference between the two LeapVectors.
* @available Since 1.0
*/
- (LeapVector *)minus:(const LeapVector *)vector;
/**
* Negate this vector.
*
* @example Vector_Negate.txt
*
* @returns The negation of this LeapVector.
* @available Since 1.0
*/
- (LeapVector *)negate;
/**
* Multiply this vector by a number.
*
* @example Vector_Times.txt
*
* @param scalar The scalar factor.
* @returns The product of this LeapVector and a scalar.
* @available Since 1.0
*/
- (LeapVector *)times:(float)scalar;
/**
* Divide this vector by a number.
*
* @example Vector_Divide.txt
*
* @param scalar The scalar divisor;
* @returns The dividend of this LeapVector divided by a scalar.
* @available Since 1.0
*/
- (LeapVector *)divide:(float)scalar;
// not provided: unary assignment operators (plus_equals, minus_equals)
// user should emulate with above operators
/**
* Checks LeapVector equality.
*
* @example Vector_Equals.txt
*
* Vectors are equal if each corresponding component is equal.
* @param vector The LeapVector to compare.
* @returns YES, if the LeapVectors are equal.
* @available Since 1.0
*/
- (BOOL)equals:(const LeapVector *)vector;
// not provided: not_equals
// user should emulate with !v.equals(...)
/**
* The dot product of this vector with another vector.
*
* @example Vector_Dot.txt
*
* The dot product is the magnitude of the projection of this vector
* onto the specified vector.
*
* <img src="../docs/images/Math_Dot.png"/>
*
* @param vector A LeapVector object.
* @returns The dot product of this vector and the specified vector.
* @available Since 1.0
*/
- (float)dot:(const LeapVector *)vector;
/**
* The cross product of this vector and the specified vector.
*
* @example Vector_Cross.txt
*
* The cross product is a vector orthogonal to both original vectors.
* It has a magnitude equal to the area of a parallelogram having the
* two vectors as sides. The direction of the returned vector is
* determined by the right-hand rule. Thus `[A cross:B] ==
* [[B negate] cross:A]`.
*
* <img src="../docs/images/Math_Cross.png"/>
*
* @param vector A LeapVector object.
* @returns The cross product of this vector and the specified vector.
* @available Since 1.0
*/
- (LeapVector *)cross:(const LeapVector *)vector;
/**
* A normalized copy of this vector.
*
* @example Vector_Normalized.txt
*
* A normalized vector has the same direction as the original vector,
* but with a length of one.
*
* @returns A LeapVector object with a length of one, pointing in the same
* direction as this Vector object.
* @available Since 1.0
*/
@property (nonatomic, getter = normalized, readonly)LeapVector *normalized;
- (LeapVector *)normalized;
/**
* Returns an NSArray object containing the vector components in the
* order: x, y, z.
*
* @example Vector_ToNSArray.txt
*
* @available Since 1.0
*/
@property (nonatomic, getter = toNSArray, readonly)NSArray *toNSArray;
- (NSArray *)toNSArray;
/**
* Returns an NSMutableData object containing the vector components as
* consecutive floating point values.
*
* @example Vector_ToFloatPointer.txt
* @available Since 1.0
*/
@property (nonatomic, getter = toFloatPointer, readonly)NSMutableData *toFloatPointer;
- (NSMutableData *)toFloatPointer;
// not provided: toVector4Type
// no templates, and ObjectiveC does not have a common math vector type
/**
* The zero vector: (0, 0, 0)
*
* @example Vector_Zero.txt
* @available Since 1.0
*/
+ (LeapVector *)zero;
/**
* The x-axis unit vector: (1, 0, 0).
*
* @example Vector_XAxis.txt
* @available Since 1.0
*/
+ (LeapVector *)xAxis;
/**
* The y-axis unit vector: (0, 1, 0).
*
* @example Vector_YAxis.txt
* @available Since 1.0
*/
+ (LeapVector *)yAxis;
/**
* The z-axis unit vector: (0, 0, 1).
*
* @example Vector_ZAxis.txt
* @available Since 1.0
*/
+ (LeapVector *)zAxis;
/**
* The unit vector pointing left along the negative x-axis: (-1, 0, 0).
*
* @example Vector_Left.txt
* @available Since 1.0
*/
+ (LeapVector *)left;
/**
* The unit vector pointing right along the positive x-axis: (1, 0, 0).
*
* @example Vector_Right.txt
* @available Since 1.0
*/
+ (LeapVector *)right;
/**
* The unit vector pointing down along the negative y-axis: (0, -1, 0).
*
* @example Vector_Down.txt
* @available Since 1.0
*/
+ (LeapVector *)down;
/**
* The unit vector pointing up along the positive y-axis: (0, 1, 0).
*
* @example Vector_Up.txt
* @available Since 1.0
*/
+ (LeapVector *)up;
/**
* The unit vector pointing forward along the negative z-axis: (0, 0, -1).
*
* @example Vector_Forward.txt
* @available Since 1.0
*/
+ (LeapVector *)forward;
/**
* The unit vector pointing backward along the positive z-axis: (0, 0, 1).
*
* @example Vector_Backward.txt
* @available Since 1.0
*/
+ (LeapVector *)backward;
/**
* The horizontal component.
* @available Since 1.0
*/
@property (nonatomic, assign, readwrite)float x;
/**
* The vertical component.
* @available Since 1.0
*/
@property (nonatomic, assign, readwrite)float y;
/**
* The depth component.
* @available Since 1.0
*/
@property (nonatomic, assign, readwrite)float z;
@end
//////////////////////////////////////////////////////////////////////////
//MATRIX
/**
* The LeapMatrix class represents a transformation matrix.
*
* To use this class to transform a LeapVector, construct a matrix containing the
* desired transformation and then use the [LeapMatrix transformPoint:] or
* [LeapMatrix transformDirection:] functions to apply the transform.
*
* Transforms can be combined by multiplying two or more transform matrices using
* the [LeapMatrix times:] function.
* @available Since 1.0
*/
@interface LeapMatrix : NSObject
/**
* Constructs a transformation matrix from the specified basis and translation vectors.
*
* @example Matrix_Constructor_1.txt
*
* @param xBasis A LeapVector specifying rotation and scale factors for the x-axis.
* @param yBasis A LeapVector specifying rotation and scale factors for the y-axis.
* @param zBasis A LeapVector specifying rotation and scale factors for the z-axis.
* @param origin A LeapVector specifying translation factors on all three axes.
* @available Since 1.0
*/
- (id)initWithXBasis:(const LeapVector *)xBasis yBasis:(const LeapVector *)yBasis zBasis:(const LeapVector *)zBasis origin:(const LeapVector *)origin;
/**
* Constructs a copy of the specified Matrix object.
*
* @example Matrix_Constructor_2.txt
*
* @param matrix the LeapMatrix to copy.
* @available Since 1.0
*/
- (id)initWithMatrix:(LeapMatrix *)matrix;
/**
* Constructs a transformation matrix specifying a rotation around the specified vector.
*
* @example Matrix_Constructor_3.txt
*
* @param axis A LeapVector specifying the axis of rotation.
* @param angleRadians The amount of rotation in radians.
* @available Since 1.0
*/
- (id)initWithAxis:(const LeapVector *)axis angleRadians:(float)angleRadians;
/**
* Constructs a transformation matrix specifying a rotation around the specified vector
* and a translation by the specified vector.
*
* @example Matrix_Constructor_4.txt
*
* @param axis A LeapVector specifying the axis of rotation.
* @param angleRadians The angle of rotation in radians.
* @param translation A LeapVector representing the translation part of the transform.
* @available Since 1.0
*/
- (id)initWithAxis:(const LeapVector *)axis angleRadians:(float)angleRadians translation:(const LeapVector *)translation;
- (NSString *)description;
// not provided: setRotation
// This was mainly an internal helper function for the above constructors
/**
* Transforms a vector with this matrix by transforming its rotation,
* scale, and translation.
*
* Translation is applied after rotation and scale.
*
* @example Matrix_TransformPoint.txt
*
* @param point A LeapVector representing the 3D position to transform.
* @returns A new LeapVector representing the transformed original.
* @available Since 1.0
*/
- (LeapVector *)transformPoint:(const LeapVector *)point;
/**
* Transforms a vector with this matrix by transforming its rotation and
* scale only.
*
* @example Matrix_TransformDirection.txt
*
* @param direction The LeapVector to transform.
* @returns A new LeapVector representing the transformed original.
* @available Since 1.0
*/
- (LeapVector *)transformDirection:(const LeapVector *)direction;
/**
* Performs a matrix inverse if the matrix consists entirely of rigid
* transformations (translations and rotations). If the matrix is not rigid,
* this operation will not represent an inverse.
*
* @example Matrix_rigidInverse.txt
*
* Note that all matricies that are directly returned by the API are rigid.
*
* @returns The rigid inverse of the matrix.
* @available Since 1.0
*/
@property (nonatomic, getter = rigidInverse, readonly)LeapMatrix *rigidInverse;
- (LeapMatrix *)rigidInverse;
/**
* Multiply transform matrices.
*
* @example Matrix_Times.txt
*
* Combines two transformations into a single equivalent transformation.
*
* @param other A LeapMatrix to multiply on the right hand side.
* @returns A new LeapMatrix representing the transformation equivalent to
* applying the other transformation followed by this transformation.
* @available Since 1.0
*/
- (LeapMatrix *)times:(const LeapMatrix *) other;
// not provided: unary assignment operator times_equals
/**
* Compare LeapMatrix equality component-wise.
*
* @example Matrix_Equals.txt
*
* @param other The LeapMatrix object to compare.
* @return YES, if the corresponding elements in the two matrices are equal.
* @available Since 1.0
*/
- (BOOL)equals:(const LeapMatrix *) other;
// not provided: not_equals
/**
* Converts a LeapMatrix object to a 9-element NSArray object.
*
* The elements of the matrix are inserted into the array in row-major order.
*
* @example Matrix_ToNSArray_1.txt
*
* Translation factors are discarded.
* @available Since 1.0
*/
@property (nonatomic, getter = toNSArray3x3, readonly)NSMutableArray *toNSArray3x3;
- (NSMutableArray *)toNSArray3x3;
/**
* Converts a LeapMatrix object to a 16-element NSArray object.
*
* The elements of the matrix are inserted into the array in row-major order.
*
* @example Matrix_ToNSArray_2.txt
*
* @available Since 1.0
*/
@property (nonatomic, getter = toNSArray4x4, readonly)NSMutableArray *toNSArray4x4;
- (NSMutableArray *)toNSArray4x4;
/**
* Returns the identity matrix specifying no translation, rotation, and scale.
*
* @example Matrix_Identity.txt
*
* @returns The identity matrix.
* @available Since 1.0
*/
+ (LeapMatrix *)identity;
/**
* The rotation and scale factors for the x-axis.
*
* @example Matrix_xBasis.txt
*
* @available Since 1.0
*/
@property (nonatomic, strong, readwrite)LeapVector *xBasis;
/**
* The rotation and scale factors for the y-axis.
*
* @example Matrix_yBasis.txt
*
* @available Since 1.0
*/
@property (nonatomic, strong, readwrite)LeapVector *yBasis;
/**
* The rotation and scale factors for the z-axis.
*
* @example Matrix_zBasis.txt
*
* @available Since 1.0
*/
@property (nonatomic, strong, readwrite)LeapVector *zBasis;
/**
* The translation factors for all three axes.
*
* @example Matrix_origin.txt
*
* @available Since 1.0
*/
@property (nonatomic, strong, readwrite)LeapVector *origin;
@end
//////////////////////////////////////////////////////////////////////////
//CONSTANTS
/**
* The constant pi as a single precision floating point number.
* @available Since 1.0
*/
extern const float LEAP_PI;
/**
* The constant ratio to convert an angle measure from degrees to radians.
* Multiply a value in degrees by this constant to convert to radians.
* @available Since 1.0
*/
extern const float LEAP_DEG_TO_RAD;
/**
* The constant ratio to convert an angle measure from radians to degrees.
* Multiply a value in radians by this constant to convert to degrees.
* @available Since 1.0
*/
extern const float LEAP_RAD_TO_DEG;
/**
* The supported types of gestures.
* @available Since 1.0
*/
typedef enum LeapGestureType {
LEAP_GESTURE_TYPE_INVALID = -1, /**< An invalid type. */
LEAP_GESTURE_TYPE_SWIPE = 1, /**< A straight line movement by the hand with fingers extended. */
LEAP_GESTURE_TYPE_CIRCLE = 4, /**< A circular movement by a finger. */
LEAP_GESTURE_TYPE_SCREEN_TAP = 5, /**< A forward tapping movement by a finger. */
LEAP_GESTURE_TYPE_KEY_TAP = 6, /**< A downward tapping movement by a finger. */
} LeapGestureType;
/**
* The possible gesture states.
*/
typedef enum LeapGestureState {
LEAP_GESTURE_STATE_INVALID = -1, /**< An invalid state */
LEAP_GESTURE_STATE_START = 1, /**< The gesture is starting. Just enough has happened to recognize it. */
LEAP_GESTURE_STATE_UPDATE = 2, /**< The gesture is in progress. (Note: not all gestures have updates). */
LEAP_GESTURE_STATE_STOP = 3, /**< The gesture has completed or stopped. */
} LeapGestureState;
/**
* The supported controller policies.
* @available Since 1.0
*/
typedef enum LeapPolicyFlag {
LEAP_POLICY_DEFAULT = 0, /**< The default policy. Since 1.0*/
LEAP_POLICY_BACKGROUND_FRAMES = (1 << 0), /**< Receive background frames. Since 1.0*/
LEAP_POLICY_IMAGES = (1 << 1), /**< Receive raw images from sensor cameras. Since 2.0.5*/
LEAP_POLICY_OPTIMIZE_HMD = (1 << 2), /**< Optimize the tracking for head-mounted device. Since 2.1.3*/
} LeapPolicyFlag;
/**
* Defines the values for reporting the state of a Pointable object in relation to
* an adaptive touch plane.
* @available Since 1.0
*/
typedef enum LeapPointableZone {
LEAP_POINTABLE_ZONE_NONE = 0, /**< The Pointable object is too far from
the plane to be considered hovering or touching.*/
LEAP_POINTABLE_ZONE_HOVERING = 1, /**< The Pointable object is close to, but
not touching the plane.*/
LEAP_POINTABLE_ZONE_TOUCHING = 2, /**< The Pointable has penetrated the plane. */
} LeapPointableZone;
/**
* Enumerates the possible image formats.
*
* The [LeapImage format] method returns an item from the LEAP_IMAGE_FORMAT_TYPE enumeration.
* @available Since 2.2.0
*/
typedef enum LeapImageFormatType {
LEAP_IMAGE_FORMAT_TYPE_INFRARED = 0
} LeapImageFormatType;
/**
* Enumerates the joints of a finger.
*
* The joints along the finger are indexed from 0 to 3 (tip to knuckle). The same
* joint identifiers are used for the thumb, even though the thumb has one less
* phalanx bone than the other digits. This puts the base joint (JOINT_MCP) at the
* base of thumb's metacarpal bone.
*
* Pass a member of this enumeration to [LeapPointable jointPosition] to get the
* physical position of that joint.
*
* Note: The term "joint" is applied loosely here and the set of joints includes the
* finger tip even though it is not an anatomical joint.
*
* @available Since 2.0
*/
typedef enum LeapFingerJoint {
/**
* The metacarpophalangeal joint, or knuckle, of the finger.
*
* The metacarpophalangeal joint is located at the base of a finger between
* the metacarpal bone and the first phalanx. The common name for this joint is
* the knuckle.
*
* On a thumb, which has one less phalanx than a finger, this joint index
* identifies the thumb joint near the base of the hand, between the carpal
* and metacarpal bones.
* @available Since 2.0
*/
LEAP_FINGER_JOINT_MCP = 0,
/**
* The proximal interphalangeal joint of the finger. This joint is the middle
* joint of a finger.
*
* The proximal interphalangeal joint is located between the two finger segments
* closest to the hand (the proximal and the intermediate phalanges). On a thumb,
* which lacks an intermediate phalanx, this joint index identifies the knuckle joint
* between the proximal phalanx and the metacarpal bone.
*
* @available Since 2.0
*/
LEAP_FINGER_JOINT_PIP = 1,
/**
* The distal interphalangeal joint of the finger.
* This joint is closest to the tip.
*
* The distal interphalangeal joint is located between the most extreme segment
* of the finger (the distal phalanx) and the middle segment (the intermediate
* phalanx).
*
* @available Since 2.0
*/
LEAP_FINGER_JOINT_DIP = 2,
/**
* The tip of the finger.
* @available Since 2.0
*/
LEAP_FINGER_JOINT_TIP = 3
} LeapFingerJoint;
/**
* Enumerates the names of the fingers.
*
* Members of this enumeration are returned by [LeapFinger type] to identify a
* Finger object.
* @available Since 2.0
*/
typedef enum LeapFingerType {
LEAP_FINGER_TYPE_THUMB = 0, /**< The thumb */
LEAP_FINGER_TYPE_INDEX = 1, /**< The index or forefinger */
LEAP_FINGER_TYPE_MIDDLE = 2, /**< The middle finger */
LEAP_FINGER_TYPE_RING = 3, /**< The ring finger */
LEAP_FINGER_TYPE_PINKY = 4 /**< The pinky or little finger */
} LeapFingerType;
//////////////////////////////////////////////////////////////////////////
//POINTABLE
@class LeapFrame;
@class LeapHand;
@class LeapInteractionBox;
/**
* The LeapPointable class reports the physical characteristics of a detected finger or tool.
*
* Both fingers and tools are classified as LeapPointable objects. Use the
* [LeapPointable isFinger] function to determine whether a pointable object
* represents a finger. Use the [LeapPointable isTool] function to determine
* whether a pointable object represents a tool. The Leap classifies a detected
* entity as a tool when it is thinner, straighter, and longer than a typical finger.
*
* To provide touch emulation, the Leap Motion software associates a floating touch
* plane that adapts to the user's finger movement and hand posture. The Leap Motion
* interprets purposeful movements toward this plane as potential touch points. The
* logic used by the LeapPointable class is the same as that used by the Leap Motion
* software for OS-level touch and mouse input emulation. The LeapPointable class reports
* touch state with the touchZone and touchDistance properties.
*
* Note that LeapPointable objects can be invalid, which means that they do not contain
* valid tracking data and do not correspond to a physical entity. Invalid LeapPointable
* objects can be the result of asking for a pointable object using an ID from an
* earlier frame when no pointable objects with that ID exist in the current frame.
* A pointable object created from the LeapPointable constructor is also invalid.
* Test for validity with the [LeapPointable isValid] function.
* @available Since 1.0
*/
@interface LeapPointable : NSObject
- (NSString *)description;
/**
* A unique ID assigned to this LeapPointable object, whose value remains the
* same across consecutive frames while the tracked finger or tool remains
* visible. If tracking is lost, the
* Leap may assign a new ID when it detects the entity in a future frame.
*
* @example Pointable_id.txt
*
* Use the ID value with the [LeapFrame pointable:] function to find this
* LeapPointable object in future frames.
*
* @example Pointable_get_id.txt
*
* @returns The ID assigned to this LeapPointable object.
* @available Since 1.0
*/
@property (nonatomic, getter = id, readonly)int32_t id;
- (int32_t)id;
/**
* The tip position in millimeters from the Leap origin.
*
* @example Pointable_tipPosition.txt
*
* @returns The LeapVector containing the coordinates of the tip position.
* @available Since 1.0
*/
@property (nonatomic, getter = tipPosition, readonly)LeapVector *tipPosition;
- (LeapVector *)tipPosition;
/**
* The rate of change of the tip position in millimeters/second.
*
* @example Pointable_tipVelocity.txt
*
* @returns The LeapVector containing the coordinates of the tip velocity.
* @available Since 1.0
*/
@property (nonatomic, getter = tipVelocity, readonly)LeapVector *tipVelocity;
- (LeapVector *)tipVelocity;
/**
* The direction in which this finger or tool is pointing.
*
* @example Pointable_direction.txt
*
* The direction is expressed as a unit vector pointing in the same
* direction as the tip.
*
* <img src="../docs/images/Leap_Finger_Model.png"/>
*
* @returns The LeapVector pointing in the same direction as the tip of this
* LeapPointable object.
* @available Since 1.0
*/
@property (nonatomic, getter = direction, readonly)LeapVector *direction;
- (LeapVector *)direction;
/**
* The estimated width of the finger or tool in millimeters.
*
* The reported width is the average width of the visible portion of the
* finger or tool. If the width isn't known,
* then a value of 0 is returned.
*
* @example Pointable_width.txt
*
* @returns The estimated width of this LeapPointable object.
* @available Since 1.0
*/
@property (nonatomic, getter = width, readonly)float width;
- (float)width;
/**
* The estimated length of the finger or tool in millimeters.
*
* The reported length is the visible length of the finger or tool.
* If the length isn't known, then a value of 0 is returned.
*
* @example Pointable_length.txt
*
* @returns The estimated length of this LeapPointable object.
* @available Since 1.0
*/
@property (nonatomic, getter = length, readonly)float length;
- (float)length;
/**
* Whether or not the LeapPointable is classified a finger.
*
* @example Pointable_isFinger.txt
*
* @returns YES, if this LeapPointable is classified as a LeapFinger.
* @available Since 1.0
*/
@property (nonatomic, getter = isFinger, readonly)BOOL isFinger;
- (BOOL)isFinger;
/**
* Whether or not the LeapPointable is classified to be a tool.
*
* @example Pointable_isTool.txt
*
* @returns YES, if this LeapPointable is classified as a LeapTool.
* @available Since 1.0
*/
@property (nonatomic, getter = isTool, readonly)BOOL isTool;
- (BOOL)isTool;
/**
* Whether or not this Pointable is in an extended posture.
*
* @example Pointable_isExtended.txt
*
* A finger is considered extended if it is extended straight from the hand as if
* pointing. A finger is not extended when it is bent down and curled towards the
* palm. Tools are always extended.
*
* @returns True, if the pointable is extended.
* @available Since 2.0
*/
@property (nonatomic, getter = isExtended, readonly)BOOL isExtended;
- (BOOL)isExtended;
/**
* Reports whether this is a valid LeapPointable object.
*
* @example Pointable_isValid.txt
*
* @returns YES, if this LeapPointable object contains valid tracking data.
* @available Since 1.0
*/
@property (nonatomic, getter = isValid, readonly)BOOL isValid;
- (BOOL)isValid;
/**
* The current touch zone of this LeapPointable object.
*
* @example Pointable_touchZone.txt
*
* The Leap Motion software computes the touch zone based on a floating touch
* plane that adapts to the user's finger movement and hand posture. The Leap
* Motion interprets purposeful movements toward this plane as potential touch
* points. When a LeapPointable moves close to the adaptive touch plane, it enters the
* "hovering" zone. When a LeapPointable reaches or passes through the plane, it enters
* the "touching" zone.
*
* The possible states are present in the Zone enum:
*
* **LEAP_POINTABLE_ZONE_NONE** -- The LeapPointable is outside the hovering zone.
*
* **LEAP_POINTABLE_ZONE_HOVERING** -- The LeapPointable is close to, but not touching the touch plane.
*
* **LEAP_POINTABLE_ZONE_TOUCHING** -- The LeapPointable has penetrated the touch plane.
*
* <img src="../docs/images/Leap_Touch_Plane.png"/>
*
* The touchDistance property provides a normalized indication of the distance to
* the touch plane when the LeapPointable is in the hovering or touching zones.
* @available Since 1.0
*/
@property (nonatomic, getter = touchZone, readonly)LeapPointableZone touchZone;
- (LeapPointableZone)touchZone;
/**
* A value proportional to the distance between this LeapPointable object and the
* adaptive touch plane.
*
* @example Pointable_touchDistance.txt
*
* The touch distance is a value in the range [-1, 1]. The value 1.0 indicates the
* LeapPointable is at the far edge of the hovering zone. The value 0 indicates the
* LeapPointable is just entering the touching zone. A value of -1.0 indicates the
* LeapPointable is firmly within the touching zone. Values in between are
* proportional to the distance from the plane. Thus, the touchDistance of 0.5
* indicates that the LeapPointable is halfway into the hovering zone.
*
* You can use the touchDistance value to modulate visual feedback given to the
* user as their fingers close in on a touch target, such as a button.
* @available Since 1.0
*/
@property (nonatomic, getter = touchDistance, readonly)float touchDistance;
- (float)touchDistance;
/**
* The stabilized tip position of this LeapPointable.
*
* @example Pointable_stabilizedTipPosition.txt
*
* Smoothing and stabilization is performed in order to make
* this value more suitable for interaction with 2D content.
* @available Since 1.0
*/
@property (nonatomic, getter = stabilizedTipPosition, readonly)LeapVector *stabilizedTipPosition;
- (LeapVector *)stabilizedTipPosition;
/**
* The duration of time this Pointable has been visible to the Leap Motion Controller.
*
* @example Pointable_timeVisible.txt
*
* @returns The duration (in seconds) that this Pointable has been tracked.
* @available Since 1.0
*/
@property (nonatomic, getter = timeVisible, readonly)float timeVisible;
- (float)timeVisible;
/**
* The LeapFrame associated with this LeapPointable object.
*
* @example Pointable_frame.txt