1 | var glMatrix = require("gl-matrix")
|
2 | , vec3 = glMatrix.vec3;
|
3 |
|
4 | /**
|
5 | * Constructs a Pointable object.
|
6 | *
|
7 | * An uninitialized pointable is considered invalid.
|
8 | * Get valid Pointable objects from a Frame or a Hand object.
|
9 | *
|
10 | * @class Pointable
|
11 | * @memberof Leap
|
12 | * @classdesc
|
13 | * The Pointable class reports the physical characteristics of a detected
|
14 | * finger or tool.
|
15 | *
|
16 | * Both fingers and tools are classified as Pointable objects. Use the
|
17 | * Pointable.tool property to determine whether a Pointable object represents a
|
18 | * tool or finger. The Leap classifies a detected entity as a tool when it is
|
19 | * thinner, straighter, and longer than a typical finger.
|
20 | *
|
21 | * Note that Pointable objects can be invalid, which means that they do not
|
22 | * contain valid tracking data and do not correspond to a physical entity.
|
23 | * Invalid Pointable objects can be the result of asking for a Pointable object
|
24 | * using an ID from an earlier frame when no Pointable objects with that ID
|
25 | * exist in the current frame. A Pointable object created from the Pointable
|
26 | * constructor is also invalid. Test for validity with the Pointable.valid
|
27 | * property.
|
28 | */
|
29 | var Pointable = module.exports = function(data) {
|
30 | /**
|
31 | * Indicates whether this is a valid Pointable object.
|
32 | *
|
33 | * @member valid
|
34 | * @type {Boolean}
|
35 | * @memberof Leap.Pointable.prototype
|
36 | */
|
37 | this.valid = true;
|
38 | /**
|
39 | * A unique ID assigned to this Pointable object, whose value remains the
|
40 | * same across consecutive frames while the tracked finger or tool remains
|
41 | * visible. If tracking is lost (for example, when a finger is occluded by
|
42 | * another finger or when it is withdrawn from the Leap field of view), the
|
43 | * Leap may assign a new ID when it detects the entity in a future frame.
|
44 | *
|
45 | * Use the ID value with the pointable() functions defined for the
|
46 | * {@link Frame} and {@link Frame.Hand} classes to find this
|
47 | * Pointable object in future frames.
|
48 | *
|
49 | * @member id
|
50 | * @type {String}
|
51 | * @memberof Leap.Pointable.prototype
|
52 | */
|
53 | this.id = data.id;
|
54 | this.handId = data.handId;
|
55 | /**
|
56 | * The estimated length of the finger or tool in millimeters.
|
57 | *
|
58 | * The reported length is the visible length of the finger or tool from the
|
59 | * hand to tip. If the length isn't known, then a value of 0 is returned.
|
60 | *
|
61 | * @member length
|
62 | * @type {number}
|
63 | * @memberof Leap.Pointable.prototype
|
64 | */
|
65 | this.length = data.length;
|
66 | /**
|
67 | * Whether or not the Pointable is believed to be a tool.
|
68 | * Tools are generally longer, thinner, and straighter than fingers.
|
69 | *
|
70 | * If tool is false, then this Pointable must be a finger.
|
71 | *
|
72 | * @member tool
|
73 | * @type {Boolean}
|
74 | * @memberof Leap.Pointable.prototype
|
75 | */
|
76 | this.tool = data.tool;
|
77 | /**
|
78 | * The estimated width of the tool in millimeters.
|
79 | *
|
80 | * The reported width is the average width of the visible portion of the
|
81 | * tool from the hand to the tip. If the width isn't known,
|
82 | * then a value of 0 is returned.
|
83 | *
|
84 | * Pointable objects representing fingers do not have a width property.
|
85 | *
|
86 | * @member width
|
87 | * @type {number}
|
88 | * @memberof Leap.Pointable.prototype
|
89 | */
|
90 | this.width = data.width;
|
91 | /**
|
92 | * The direction in which this finger or tool is pointing.
|
93 | *
|
94 | * The direction is expressed as a unit vector pointing in the same
|
95 | * direction as the tip.
|
96 | *
|
97 | * ![Finger](images/Leap_Finger_Model.png)
|
98 | * @member direction
|
99 | * @type {number[]}
|
100 | * @memberof Leap.Pointable.prototype
|
101 | */
|
102 | this.direction = data.direction;
|
103 | /**
|
104 | * The tip position in millimeters from the Leap origin.
|
105 | * Stabilized
|
106 | *
|
107 | * @member stabilizedTipPosition
|
108 | * @type {number[]}
|
109 | * @memberof Leap.Pointable.prototype
|
110 | */
|
111 | this.stabilizedTipPosition = data.stabilizedTipPosition;
|
112 | /**
|
113 | * The tip position in millimeters from the Leap origin.
|
114 | *
|
115 | * @member tipPosition
|
116 | * @type {number[]}
|
117 | * @memberof Leap.Pointable.prototype
|
118 | */
|
119 | this.tipPosition = data.tipPosition;
|
120 | /**
|
121 | * The rate of change of the tip position in millimeters/second.
|
122 | *
|
123 | * @member tipVelocity
|
124 | * @type {number[]}
|
125 | * @memberof Leap.Pointable.prototype
|
126 | */
|
127 | this.tipVelocity = data.tipVelocity;
|
128 | /**
|
129 | * The current touch zone of this Pointable object.
|
130 | *
|
131 | * The Leap Motion software computes the touch zone based on a floating touch
|
132 | * plane that adapts to the user's finger movement and hand posture. The Leap
|
133 | * Motion software interprets purposeful movements toward this plane as potential touch
|
134 | * points. When a Pointable moves close to the adaptive touch plane, it enters the
|
135 | * "hovering" zone. When a Pointable reaches or passes through the plane, it enters
|
136 | * the "touching" zone.
|
137 | *
|
138 | * The possible states include:
|
139 | *
|
140 | * * "none" -- The Pointable is outside the hovering zone.
|
141 | * * "hovering" -- The Pointable is close to, but not touching the touch plane.
|
142 | * * "touching" -- The Pointable has penetrated the touch plane.
|
143 | *
|
144 | * The touchDistance value provides a normalized indication of the distance to
|
145 | * the touch plane when the Pointable is in the hovering or touching zones.
|
146 | *
|
147 | * @member touchZone
|
148 | * @type {String}
|
149 | * @memberof Leap.Pointable.prototype
|
150 | */
|
151 | this.touchZone = data.touchZone;
|
152 | /**
|
153 | * A value proportional to the distance between this Pointable object and the
|
154 | * adaptive touch plane.
|
155 | *
|
156 | * ![Touch Distance](images/Leap_Touch_Plane.png)
|
157 | *
|
158 | * The touch distance is a value in the range [-1, 1]. The value 1.0 indicates the
|
159 | * Pointable is at the far edge of the hovering zone. The value 0 indicates the
|
160 | * Pointable is just entering the touching zone. A value of -1.0 indicates the
|
161 | * Pointable is firmly within the touching zone. Values in between are
|
162 | * proportional to the distance from the plane. Thus, the touchDistance of 0.5
|
163 | * indicates that the Pointable is halfway into the hovering zone.
|
164 | *
|
165 | * You can use the touchDistance value to modulate visual feedback given to the
|
166 | * user as their fingers close in on a touch target, such as a button.
|
167 | *
|
168 | * @member touchDistance
|
169 | * @type {number}
|
170 | * @memberof Leap.Pointable.prototype
|
171 | */
|
172 | this.touchDistance = data.touchDistance;
|
173 |
|
174 | /**
|
175 | * How long the pointable has been visible in seconds.
|
176 | *
|
177 | * @member timeVisible
|
178 | * @type {number}
|
179 | * @memberof Leap.Pointable.prototype
|
180 | */
|
181 | this.timeVisible = data.timeVisible;
|
182 | }
|
183 |
|
184 | /**
|
185 | * A string containing a brief, human readable description of the Pointable
|
186 | * object.
|
187 | *
|
188 | * @method toString
|
189 | * @memberof Leap.Pointable.prototype
|
190 | * @returns {String} A description of the Pointable object as a string.
|
191 | */
|
192 | Pointable.prototype.toString = function() {
|
193 | return "Pointable [ id:" + this.id + " " + this.length + "mmx | width:" + this.width + "mm | direction:" + this.direction + ' ]';
|
194 | }
|
195 |
|
196 | /**
|
197 | * Returns the hand which the pointable is attached to.
|
198 | */
|
199 | Pointable.prototype.hand = function(){
|
200 | return this.frame.hand(this.handId);
|
201 | }
|
202 |
|
203 | /**
|
204 | * An invalid Pointable object.
|
205 | *
|
206 | * You can use this Pointable instance in comparisons testing
|
207 | * whether a given Pointable instance is valid or invalid. (You can also use the
|
208 | * Pointable.valid property.)
|
209 |
|
210 | * @static
|
211 | * @type {Leap.Pointable}
|
212 | * @name Invalid
|
213 | * @memberof Leap.Pointable
|
214 | */
|
215 | Pointable.Invalid = { valid: false };
|