Project

General

Profile

LeapMotion Scol plugin
scolplugin.cpp
1 /*
2 -----------------------------------------------------------------------------
3 This source file is part of OpenSpace3D
4 For the latest info, see http://www.openspace3d.com
5 
6 Copyright (c) 2012 I-maginer
7 
8 This program is free software; you can redistribute it and/or modify it under
9 the terms of the GNU Lesser General Public License as published by the Free Software
10 Foundation; either version 2 of the License, or (at your option) any later
11 version.
12 
13 This program is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16 
17 You should have received a copy of the GNU Lesser General Public License along with
18 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19 Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20 http://www.gnu.org/copyleft/lesser.txt
21 
22 -----------------------------------------------------------------------------
23 */
24 
25 /*
26  LeapMotion interface for Scol
27  First version : November 2013
28  Author : Bastien BOURINEAU - I-Maginer
29 */
30 
31 #include "sLeapMotion.h"
32 #include <scolPlugin.h>
33 #include <scolMemoryHelper.hpp>
34 
36 #ifdef SCOL_STATIC
37 extern cbmachine ww;
38 extern mmachine mm;
39 #else
40 cbmachine ww;
41 mmachine mm;
42 #endif
43 
44 int OBJ_LEAPMOTION_SCOL;
45 
46 int LEAPMOTION_CONNECTED_CB;
47 int SCOL_LEAPMOTION_CONNECTED_CB = 0;
48 
49 int LEAPMOTION_DISCONNECTED_CB;
50 int SCOL_LEAPMOTION_DISCONNECTED_CB = 1;
51 
52 int LEAPMOTION_CIRCLE_CB;
53 int SCOL_LEAPMOTION_CIRCLE_CB = 2;
54 
55 int LEAPMOTION_SWIPE_CB;
56 int SCOL_LEAPMOTION_SWIPEB_CB = 3;
57 
58 int LEAPMOTION_KEYTAP_CB;
59 int SCOL_LEAPMOTION_KEYTAP_CB = 4;
60 
61 int LEAPMOTION_SCREENTAP_CB;
62 int SCOL_LEAPMOTION_SCREENTAP_CB = 5;
63 
85 int destroyLEAPMOTIONObj(mmachine m, SCOL_PTR_TYPE handsys, int handscol)
86 {
87  // Read the first element of a TAB element (table of object)
88  sLeapMotion* leapObj = MMgetPointer<sLeapMotion*>(m, MTOP(handscol));
89  SAFE_DELETE(leapObj);
90 
91  MMsetPointer(m, MTOP(handscol), NULL);
92 
93  // Display debug message
94  MMechostr(MSKDEBUG, "ObjLeapMotion destroyed.\n");
95  return 0;
96 }
97 
98 
111 int _CRleapMotionDevice(mmachine m)
112 {
113 #ifdef _SCOL_DEBUG_
114  MMechostr(0,"_CRleapMotionDevice\n");
115 #endif
116  // Declare local variables
117  int k = 0;
118 
119  int pUserd = MMpull(m);
120  int pCbkd = MMpull(m);
121  int pUserc = MMpull(m);
122  int pCbkc = MMpull(m);
123 
124  // Get the channel without pulling it (first element in the stack)
125  int channel = MMget(m, 0);
126 
127  // Test the channel
128  if (channel == NIL)
129  {
130  MMechostr(MSKDEBUG, "_CRleapMotionDevice : Channel NIL\n");
131  return 0;
132  }
133 
134  sLeapMotion* leapObj = new sLeapMotion();
135  if (leapObj == NULL)
136  {
137  MMechostr(MSKDEBUG, "_CRleapMotionDevice : leapObj failed\n");
138  MMset(m, 0, NIL);
139  return 0;
140  }
141 
142  // Allocate a space in the stack for a table of joypad object
143  if ((MMpushPointer(m, leapObj) != 0))
144  {
145  SAFE_DELETE(leapObj);
146  MMset(m, 0, NIL);
147  return MERRMEM;
148  }
149 
150  // Create a new scol joypad object
151  k = OBJcreate(m, OBJ_LEAPMOTION_SCOL, SCOL_PTR leapObj, NIL, NULL);
152 
153  if ((k = MMpush(m, pCbkc))) return k; /* reading callback */
154  if ((k = MMpush(m, pUserc))) return k; /* user param */
155  if ((k = OBJaddreflex(m, OBJ_LEAPMOTION_SCOL, SCOL_LEAPMOTION_CONNECTED_CB))) return k;
156 
157  if ((k = MMpush(m, pCbkd))) return k; /* reading callback */
158  if ((k = MMpush(m, pUserd))) return k; /* user param */
159  if ((k = OBJaddreflex(m, OBJ_LEAPMOTION_SCOL, SCOL_LEAPMOTION_DISCONNECTED_CB))) return k;
160 
161  leapObj->Init();
162 
163 #ifdef _SCOL_DEBUG_
164  MMechostr(0,"ok\n");
165 #endif
166 
167  return k;
168 }
169 
177 int _DSleapMotionDevice(mmachine m)
178 {
179 #ifdef _SCOL_DEBUG_
180  MMechostr(MSKDEBUG,"_DSleapMotionDevice\n");
181 #endif
182 
183  int leapMotionTab = MMget(m, 0);
184  if (leapMotionTab == NIL)
185  {
186  MMset(m, 0, NIL);
187  return 0;
188  }
189 
190  OBJdelTM(m, OBJ_LEAPMOTION_SCOL, leapMotionTab);
191  MMset(m, 0, ITOM(0));
192 
193 #ifdef _SCOL_DEBUG_
194  MMechostr(MSKDEBUG,"ok\n");
195 #endif
196  return 0;
197 }
198 
208 int _GetLeapMotionHand(mmachine m)
209 {
210 #ifdef _SCOL_DEBUG_
211  MMechostr(MSKDEBUG,"_GetLeapMotionHand\n");
212 #endif
213 
214  int opt = MMpull(m);
215  int index = MMpull(m);
216  int leapMotionTab = MMget(m, 0);
217  if (leapMotionTab == NIL)
218  {
219  MMset(m, 0, NIL);
220  return 0;
221  }
222 
223  sLeapMotion* leapObj = MMgetPointer<sLeapMotion*>(m, MTOP(leapMotionTab));
224  if (!leapObj)
225  {
226  MMset(m, 0, NIL);
227  return 0;
228  }
229 
230  Vector pos;
231  Vector pyr;
232  Vector vel;
233 
234  if (index == NIL)
235  index = 0;
236  else
237  index = MTOI(index);
238 
239  Hand hand;
240  if (!leapObj->GetHand(index, hand))
241  {
242  MMset(m, 0, NIL);
243  return 0;
244  }
245 
246  bool optim = false;
247  if (MTOI(opt) == 1)
248  optim = true;
249 
250  leapObj->GetHandPosition(hand, optim, pos);
251  leapObj->GetHandOrientation(hand, pyr);
252  leapObj->GetHandVelocity(hand, vel);
253 
254  int ptuple = MMmalloc(m, 3, TYPETAB);
255  if(ptuple==NIL)
256  {
257  MMset(m, 0, NIL);
258  return MERRMEM;
259  }
260  MMstore(m, ptuple, 0, FTOM(pos.x / 1000.0f));
261  MMstore(m, ptuple, 1, FTOM(pos.y / 1000.0f));
262  MMstore(m, ptuple, 2, FTOM(pos.z / 1000.0f));
263 
264  int otuple = MMmalloc(m, 3, TYPETAB);
265  if(otuple==NIL)
266  {
267  MMset(m, 0, NIL);
268  return MERRMEM;
269  }
270  MMstore(m, otuple, 0, FTOM(pyr.x));
271  MMstore(m, otuple, 1, FTOM(pyr.y));
272  MMstore(m, otuple, 2, FTOM(pyr.z));
273 
274  int vtuple = MMmalloc(m, 3, TYPETAB);
275  if(vtuple==NIL)
276  {
277  MMset(m, 0, NIL);
278  return MERRMEM;
279  }
280  MMstore(m, vtuple, 0, FTOM(vel.x / 1000.0f));
281  MMstore(m, vtuple, 1, FTOM(vel.y / 1000.0f));
282  MMstore(m, vtuple, 2, FTOM(vel.z / 1000.0f));
283 
284  int ftuple = MMmalloc(m, 3, TYPETAB);
285  if(ftuple==NIL)
286  {
287  MMset(m, 0, NIL);
288  return MERRMEM;
289  }
290  MMstore(m, ftuple, 0, PTOM(ptuple));
291  MMstore(m, ftuple, 1, PTOM(otuple));
292  MMstore(m, ftuple, 2, PTOM(vtuple));
293 
294  MMset(m, 0, PTOM(ftuple));
295 
296 #ifdef _SCOL_DEBUG_
297  MMechostr(MSKDEBUG,"ok\n");
298 #endif
299  return 0;
300 }
301 
311 int _GetLeapMotionHandExt(mmachine m)
312 {
313 #ifdef _SCOL_DEBUG_
314  MMechostr(MSKDEBUG,"_GetLeapMotionHandExt\n");
315 #endif
316 
317  int opt = MMpull(m);
318  int index = MMpull(m);
319  int leapMotionTab = MMget(m, 0);
320  if (leapMotionTab == NIL)
321  {
322  MMset(m, 0, NIL);
323  return 0;
324  }
325 
326  sLeapMotion* leapObj = MMgetPointer<sLeapMotion*>(m, MTOP(leapMotionTab));
327  if (!leapObj)
328  {
329  MMset(m, 0, NIL);
330  return 0;
331  }
332 
333  Vector pos;
334  Vector pyr;
335  Vector vel;
336  Vector dir;
337  Vector norm;
338 
339  if (index == NIL)
340  index = 0;
341  else
342  index = MTOI(index);
343 
344  Hand hand;
345  if (!leapObj->GetHand(index, hand))
346  {
347  MMset(m, 0, NIL);
348  return 0;
349  }
350 
351  bool optim = false;
352  if (MTOI(opt) == 1)
353  optim = true;
354 
355  leapObj->GetHandPosition(hand, optim, pos);
356  leapObj->GetHandOrientation(hand, pyr);
357  leapObj->GetHandVelocity(hand, vel);
358  leapObj->GetHandDirection(hand, dir);
359  leapObj->GetHandPalmNormal(hand, norm);
360  float confidence = hand.confidence();
361 
362  int ptuple = MMmalloc(m, 3, TYPETAB);
363  if(ptuple==NIL)
364  {
365  MMset(m, 0, NIL);
366  return MERRMEM;
367  }
368  MMstore(m, ptuple, 0, FTOM(pos.x / 1000.0f));
369  MMstore(m, ptuple, 1, FTOM(pos.y / 1000.0f));
370  MMstore(m, ptuple, 2, FTOM(pos.z / 1000.0f));
371 
372  int otuple = MMmalloc(m, 3, TYPETAB);
373  if(otuple==NIL)
374  {
375  MMset(m, 0, NIL);
376  return MERRMEM;
377  }
378  MMstore(m, otuple, 0, FTOM(pyr.x));
379  MMstore(m, otuple, 1, FTOM(pyr.y));
380  MMstore(m, otuple, 2, FTOM(pyr.z));
381 
382  int vtuple = MMmalloc(m, 3, TYPETAB);
383  if(vtuple==NIL)
384  {
385  MMset(m, 0, NIL);
386  return MERRMEM;
387  }
388  MMstore(m, vtuple, 0, FTOM(vel.x / 1000.0f));
389  MMstore(m, vtuple, 1, FTOM(vel.y / 1000.0f));
390  MMstore(m, vtuple, 2, FTOM(vel.z / 1000.0f));
391 
392  int dtuple = MMmalloc(m, 3, TYPETAB);
393  if(dtuple==NIL)
394  {
395  MMset(m, 0, NIL);
396  return MERRMEM;
397  }
398  MMstore(m, dtuple, 0, FTOM(dir.x));
399  MMstore(m, dtuple, 1, FTOM(dir.y));
400  MMstore(m, dtuple, 2, FTOM(dir.z));
401 
402  int ntuple = MMmalloc(m, 3, TYPETAB);
403  if(ntuple==NIL)
404  {
405  MMset(m, 0, NIL);
406  return MERRMEM;
407  }
408  MMstore(m, ntuple, 0, FTOM(norm.x));
409  MMstore(m, ntuple, 1, FTOM(norm.y));
410  MMstore(m, ntuple, 2, FTOM(norm.z));
411 
412  int ftuple = MMmalloc(m, 6, TYPETAB);
413  if(ftuple==NIL)
414  {
415  MMset(m, 0, NIL);
416  return MERRMEM;
417  }
418  MMstore(m, ftuple, 0, PTOM(ptuple));
419  MMstore(m, ftuple, 1, PTOM(otuple));
420  MMstore(m, ftuple, 2, PTOM(vtuple));
421  MMstore(m, ftuple, 3, PTOM(dtuple));
422  MMstore(m, ftuple, 4, PTOM(ntuple));
423  MMstore(m, ftuple, 5, FTOM(confidence));
424 
425  MMset(m, 0, PTOM(ftuple));
426 
427 #ifdef _SCOL_DEBUG_
428  MMechostr(MSKDEBUG,"ok\n");
429 #endif
430  return 0;
431 }
432 
442 int _GetLeapMotionTool(mmachine m)
443 {
444 #ifdef _SCOL_DEBUG_
445  MMechostr(MSKDEBUG,"_GetLeapMotionTool\n");
446 #endif
447 
448  int opt = MMpull(m);
449  int index = MMpull(m);
450  int leapMotionTab = MMget(m, 0);
451  if (leapMotionTab == NIL)
452  {
453  MMset(m, 0, NIL);
454  return 0;
455  }
456 
457  sLeapMotion* leapObj = MMgetPointer<sLeapMotion*>(m, MTOP(leapMotionTab));
458  if (!leapObj)
459  {
460  MMset(m, 0, NIL);
461  return 0;
462  }
463 
464  Vector pos;
465  Vector pyr;
466  Vector vel;
467 
468  if (index == NIL)
469  index = 0;
470  else
471  index = MTOI(index);
472 
473  Tool tool;
474  if (!leapObj->GetTool(index, tool))
475  {
476  MMset(m, 0, NIL);
477  return 0;
478  }
479 
480  bool optim = false;
481  if (MTOI(opt) == 1)
482  optim = true;
483 
484  leapObj->GetToolPosition(tool, optim, pos);
485  leapObj->GetToolOrientation(tool, pyr);
486 
487  int ptuple = MMmalloc(m, 3, TYPETAB);
488  if(ptuple==NIL)
489  {
490  MMset(m, 0, NIL);
491  return MERRMEM;
492  }
493  MMstore(m, ptuple, 0, FTOM(pos.x / 1000.0f));
494  MMstore(m, ptuple, 1, FTOM(pos.y / 1000.0f));
495  MMstore(m, ptuple, 2, FTOM(pos.z / 1000.0f));
496 
497  int otuple = MMmalloc(m, 3, TYPETAB);
498  if(otuple==NIL)
499  {
500  MMset(m, 0, NIL);
501  return MERRMEM;
502  }
503  MMstore(m, otuple, 0, FTOM(pyr.x));
504  MMstore(m, otuple, 1, FTOM(pyr.y));
505  MMstore(m, otuple, 2, FTOM(pyr.z));
506 
507  int vtuple = MMmalloc(m, 3, TYPETAB);
508  if(vtuple==NIL)
509  {
510  MMset(m, 0, NIL);
511  return MERRMEM;
512  }
513  MMstore(m, vtuple, 0, FTOM(vel.x / 1000.0f));
514  MMstore(m, vtuple, 1, FTOM(vel.y / 1000.0f));
515  MMstore(m, vtuple, 2, FTOM(vel.z / 1000.0f));
516 
517  int ftuple = MMmalloc(m, 3, TYPETAB);
518  if(ftuple==NIL)
519  {
520  MMset(m, 0, NIL);
521  return MERRMEM;
522  }
523  MMstore(m, ftuple, 0, PTOM(ptuple));
524  MMstore(m, ftuple, 1, PTOM(otuple));
525  MMstore(m, ftuple, 2, PTOM(vtuple));
526 
527  MMset(m, 0, PTOM(ftuple));
528 
529 #ifdef _SCOL_DEBUG_
530  MMechostr(MSKDEBUG,"ok\n");
531 #endif
532  return 0;
533 }
534 
545 {
546 #ifdef _SCOL_DEBUG_
547  MMechostr(MSKDEBUG,"_GetLeapMotionHandFingers\n");
548 #endif
549 
550  int opt = MMpull(m);
551  int index = MMpull(m);
552  int leapMotionTab = MMget(m, 0);
553  if (leapMotionTab == NIL)
554  {
555  MMset(m, 0, NIL);
556  return 0;
557  }
558 
559  sLeapMotion* leapObj = MMgetPointer<sLeapMotion*>(m, MTOP(leapMotionTab));
560  if (!leapObj)
561  {
562  MMset(m, 0, NIL);
563  return 0;
564  }
565 
566  if (index == NIL)
567  index = 0;
568  else
569  index = MTOI(index);
570 
571  Hand hand;
572  if (!leapObj->GetHand(index, hand))
573  {
574  MMset(m, 0, NIL);
575  return 0;
576  }
577 
578  bool optim = false;
579  if (MTOI(opt) == 1)
580  optim = true;
581 
582  //remove last param
583  MMpull(m);
584 
585  std::vector<SCbData> lfingers = leapObj->GetHandFingers(hand, optim);
586  for (unsigned int i = 0; i < lfingers.size(); i++)
587  {
588  SCbData data = lfingers.at(i);
589 
590  int ptuple = MMmalloc(m, 3, TYPETAB);
591  if(ptuple==NIL)
592  {
593  return MERRMEM;
594  }
595  MMstore(m, ptuple, 0, FTOM(data.svec.x / 1000.0f));
596  MMstore(m, ptuple, 1, FTOM(data.svec.y / 1000.0f));
597  MMstore(m, ptuple, 2, FTOM(data.svec.z / 1000.0f));
598 
599  int otuple = MMmalloc(m, 3, TYPETAB);
600  if(otuple==NIL)
601  {
602  return MERRMEM;
603  }
604  MMstore(m, otuple, 0, FTOM(data.pyr.x));
605  MMstore(m, otuple, 1, FTOM(data.pyr.y));
606  MMstore(m, otuple, 2, FTOM(data.pyr.z));
607 
608  int stuple = MMmalloc(m, 2, TYPETAB);
609  if(stuple==NIL)
610  {
611  return MERRMEM;
612  }
613  MMstore(m, stuple, 0, FTOM(data.screenPos.x));
614  MMstore(m, stuple, 1, FTOM(data.screenPos.y));
615 
616  int ftuple = MMmalloc(m, 4, TYPETAB);
617  if(ftuple==NIL)
618  {
619  MMset(m, 0, NIL);
620  return MERRMEM;
621  }
622  MMstore(m, ftuple, 0, PTOM(ptuple));
623  MMstore(m, ftuple, 1, PTOM(otuple));
624  MMstore(m, ftuple, 2, PTOM(stuple));
625  MMstore(m, ftuple, 3, ITOM(data.id));
626 
627  MMpush(m, PTOM(ftuple));
628  }
629 
630  if(MMpush(m, NIL))
631  return MERRMEM;
632 
633  for (unsigned int i = 0; i < lfingers.size(); i++)
634  {
635  if (MMpush(m, 2*2))
636  return MERRMEM;
637 
638  if (int k=MBdeftab(m))
639  return k;
640  }
641 
642 #ifdef _SCOL_DEBUG_
643  MMechostr(MSKDEBUG,"ok\n");
644 #endif
645  return 0;
646 }
647 
658 {
659 #ifdef _SCOL_DEBUG_
660  MMechostr(MSKDEBUG,"_GetLeapMotionHandFingersWithJoints\n");
661 #endif
662 
663  int opt = MMpull(m);
664  int index = MMpull(m);
665  int leapMotionTab = MMget(m, 0);
666  if (leapMotionTab == NIL)
667  {
668  MMset(m, 0, NIL);
669  return 0;
670  }
671 
672  sLeapMotion* leapObj = MMgetPointer<sLeapMotion*>(m, MTOP(leapMotionTab));
673  if (!leapObj)
674  {
675  MMset(m, 0, NIL);
676  return 0;
677  }
678 
679  if (index == NIL)
680  index = 0;
681  else
682  index = MTOI(index);
683 
684  Hand hand;
685  if (!leapObj->GetHand(index, hand))
686  {
687  MMset(m, 0, NIL);
688  return 0;
689  }
690 
691  bool optim = false;
692  if (MTOI(opt) == 1)
693  optim = true;
694 
695  //remove last param
696  MMpull(m);
697 
698  std::vector<SCbData> lfingers = leapObj->GetHandFingers(hand, optim);
699  for (unsigned int i = 0; i < lfingers.size(); i++)
700  {
701  SCbData data = lfingers.at(i);
702 
703  int ptuple = MMmalloc(m, 3, TYPETAB);
704  if(ptuple==NIL)
705  {
706  return MERRMEM;
707  }
708  MMstore(m, ptuple, 0, FTOM(data.svec.x / 1000.0f));
709  MMstore(m, ptuple, 1, FTOM(data.svec.y / 1000.0f));
710  MMstore(m, ptuple, 2, FTOM(data.svec.z / 1000.0f));
711 
712  int otuple = MMmalloc(m, 3, TYPETAB);
713  if(otuple==NIL)
714  {
715  return MERRMEM;
716  }
717  MMstore(m, otuple, 0, FTOM(data.pyr.x));
718  MMstore(m, otuple, 1, FTOM(data.pyr.y));
719  MMstore(m, otuple, 2, FTOM(data.pyr.z));
720 
721  int stuple = MMmalloc(m, 2, TYPETAB);
722  if(stuple==NIL)
723  {
724  return MERRMEM;
725  }
726  MMstore(m, stuple, 0, FTOM(data.screenPos.x));
727  MMstore(m, stuple, 1, FTOM(data.screenPos.y));
728 
729  // joints vector list
730  for (unsigned int j = 0; j < data.subVecs.size(); j++)
731  {
732  Vector jvec = data.subVecs[j];
733  int jtuple = MMmalloc(m, 3, TYPETAB);
734  if(jtuple==NIL)
735  {
736  return MERRMEM;
737  }
738 
739  MMstore(m, jtuple, 0, FTOM(jvec.x / 1000.0f));
740  MMstore(m, jtuple, 1, FTOM(jvec.y / 1000.0f));
741  MMstore(m, jtuple, 2, FTOM(jvec.z / 1000.0f));
742 
743  MMpush(m, PTOM(jtuple));
744  }
745 
746  if(MMpush(m, NIL))
747  return MERRMEM;
748 
749  for (unsigned int j = 0; j < data.subVecs.size(); j++)
750  {
751  if (MMpush(m, 2*2))
752  return MERRMEM;
753 
754  if (int k=MBdeftab(m))
755  return k;
756  }
757  // joints end
758 
759  int ftuple = MMmalloc(m, 5, TYPETAB);
760  if(ftuple==NIL)
761  {
762  MMset(m, 0, NIL);
763  return MERRMEM;
764  }
765 
766  MMstore(m, ftuple, 0, PTOM(ptuple));
767  MMstore(m, ftuple, 1, PTOM(otuple));
768  MMstore(m, ftuple, 2, PTOM(stuple));
769  MMstore(m, ftuple, 3, MMpull(m));
770  MMstore(m, ftuple, 4, ITOM(data.id));
771 
772  MMpush(m, PTOM(ftuple));
773  }
774 
775  if(MMpush(m, NIL))
776  return MERRMEM;
777 
778  for (unsigned int i = 0; i < lfingers.size(); i++)
779  {
780  if (MMpush(m, 2*2))
781  return MERRMEM;
782 
783  if (int k=MBdeftab(m))
784  return k;
785  }
786 
787 #ifdef _SCOL_DEBUG_
788  MMechostr(MSKDEBUG,"ok\n");
789 #endif
790  return 0;
791 }
792 
809 {
810  return OBJaddreflex(m, OBJ_LEAPMOTION_SCOL, SCOL_LEAPMOTION_CIRCLE_CB);
811 }
812 
813 int getLeapMotionCircleCb(mmachine m, SCOL_PTR_TYPE id, LONG param)
814 {
815  int k = 0;
816  sLeapMotion* leapObj = (sLeapMotion*)id;
817 
818  SCbData* data = (SCbData*)param;
819 
820  if (!leapObj)
821  {
822  delete data;
823  return 0;
824  }
825 
826  // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
827  if (OBJbeginreflex(m, OBJ_LEAPMOTION_SCOL, SCOL_PTR leapObj, SCOL_LEAPMOTION_CIRCLE_CB))
828  {
829  delete data;
830  return 0;
831  }
832 
833  MMpush(m, ITOM(data->state));
834  MMpush(m, ITOM(data->handId));
835  MMpush(m, ITOM(data->id));
836  MMpush(m, FTOM(data->dir));
837  MMpush(m, FTOM(data->fparam));
838  MMpush(m, FTOM(data->progress));
839 
840  k=OBJcallreflex(m, 6);
841 
842  delete data;
843  return k;
844 }
845 
862 {
863  return OBJaddreflex(m, OBJ_LEAPMOTION_SCOL, SCOL_LEAPMOTION_SWIPEB_CB);
864 }
865 
866 int getLeapMotionSwipeCb(mmachine m, SCOL_PTR_TYPE id, LONG param)
867 {
868  int k = 0;
869  sLeapMotion* leapObj = (sLeapMotion*)id;
870 
871  SCbData* data = (SCbData*)param;
872 
873  if (!leapObj)
874  {
875  delete data;
876  return 0;
877  }
878 
879  // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
880  if (OBJbeginreflex(m, OBJ_LEAPMOTION_SCOL, SCOL_PTR leapObj, SCOL_LEAPMOTION_SWIPEB_CB))
881  {
882  delete data;
883  return 0;
884  }
885 
886  int ftuple = MMmalloc(m, 3, TYPETAB);
887  if(ftuple==NIL)
888  {
889  MMset(m, 0, NIL);
890  return MERRMEM;
891  }
892  MMstore(m, ftuple, 0, FTOM(data->vDir.x));
893  MMstore(m, ftuple, 1, FTOM(data->vDir.y));
894  MMstore(m, ftuple, 2, FTOM(data->vDir.z));
895 
896  MMpush(m, ITOM(data->state));
897  MMpush(m, ITOM(data->handId));
898  MMpush(m, ITOM(data->id));
899 
900  MMpush(m, PTOM(ftuple));
901 
902  MMpush(m, FTOM(data->fparam));
903  MMpush(m, FTOM(data->progress));
904 
905  k=OBJcallreflex(m, 6);
906 
907  delete data;
908  return k;
909 }
910 
925 {
926  return OBJaddreflex(m, OBJ_LEAPMOTION_SCOL, SCOL_LEAPMOTION_KEYTAP_CB);
927 }
928 
929 int getLeapMotionKeyTapCb(mmachine m, SCOL_PTR_TYPE id, LONG param)
930 {
931  int k = 0;
932  sLeapMotion* leapObj = (sLeapMotion*)id;
933 
934  SCbData* data = (SCbData*)param;
935 
936  if (!leapObj)
937  {
938  delete data;
939  return 0;
940  }
941 
942  // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
943  if (OBJbeginreflex(m, OBJ_LEAPMOTION_SCOL, SCOL_PTR leapObj, SCOL_LEAPMOTION_KEYTAP_CB))
944  {
945  delete data;
946  return 0;
947  }
948 
949  int ftuple = MMmalloc(m, 3, TYPETAB);
950  if(ftuple==NIL)
951  {
952  MMset(m, 0, NIL);
953  return MERRMEM;
954  }
955  MMstore(m, ftuple, 0, FTOM(data->vDir.x));
956  MMstore(m, ftuple, 1, FTOM(data->vDir.y));
957  MMstore(m, ftuple, 2, FTOM(data->vDir.z));
958 
959  int vtuple = MMmalloc(m, 3, TYPETAB);
960  if(vtuple==NIL)
961  {
962  MMset(m, 0, NIL);
963  return MERRMEM;
964  }
965  MMstore(m, vtuple, 0, FTOM(data->svec.x));
966  MMstore(m, vtuple, 1, FTOM(data->svec.y));
967  MMstore(m, vtuple, 2, FTOM(data->svec.z));
968 
969  MMpush(m, ITOM(data->handId));
970  MMpush(m, ITOM(data->id));
971  MMpush(m, PTOM(ftuple));
972  MMpush(m, PTOM(vtuple));
973 
974  k=OBJcallreflex(m, 4);
975 
976  delete data;
977  return k;
978 }
979 
994 {
995  return OBJaddreflex(m, OBJ_LEAPMOTION_SCOL, SCOL_LEAPMOTION_SCREENTAP_CB);
996 }
997 
998 int getLeapMotionScreenTapCb(mmachine m, SCOL_PTR_TYPE id, LONG param)
999 {
1000  int k = 0;
1001  sLeapMotion* leapObj = (sLeapMotion*)id;
1002 
1003  SCbData* data = (SCbData*)param;
1004 
1005  if (!leapObj)
1006  {
1007  delete data;
1008  return 0;
1009  }
1010 
1011  // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
1012  if (OBJbeginreflex(m, OBJ_LEAPMOTION_SCOL, SCOL_PTR leapObj, SCOL_LEAPMOTION_SCREENTAP_CB))
1013  {
1014  delete data;
1015  return 0;
1016  }
1017 
1018  int ftuple = MMmalloc(m, 3, TYPETAB);
1019  if(ftuple==NIL)
1020  {
1021  MMset(m, 0, NIL);
1022  return MERRMEM;
1023  }
1024  MMstore(m, ftuple, 0, FTOM(data->vDir.x));
1025  MMstore(m, ftuple, 1, FTOM(data->vDir.y));
1026  MMstore(m, ftuple, 2, FTOM(data->vDir.z));
1027 
1028  int vtuple = MMmalloc(m, 3, TYPETAB);
1029  if(vtuple==NIL)
1030  {
1031  MMset(m, 0, NIL);
1032  return MERRMEM;
1033  }
1034  MMstore(m, vtuple, 0, FTOM(data->svec.x));
1035  MMstore(m, vtuple, 1, FTOM(data->svec.y));
1036  MMstore(m, vtuple, 2, FTOM(data->svec.z));
1037 
1038  MMpush(m, ITOM(data->handId));
1039  MMpush(m, ITOM(data->id));
1040  MMpush(m, PTOM(ftuple));
1041  MMpush(m, PTOM(vtuple));
1042 
1043  k=OBJcallreflex(m, 4);
1044 
1045  delete data;
1046  return k;
1047 }
1048 
1058 {
1059 #ifdef _SCOL_DEBUG_
1060  MMechostr(MSKDEBUG,"_GetLeapMotionGrabStrength\n");
1061 #endif
1062 
1063  int index = MMpull(m);
1064  int leapMotionTab = MMget(m, 0);
1065  if (leapMotionTab == NIL)
1066  {
1067  MMset(m, 0, NIL);
1068  return 0;
1069  }
1070 
1071  sLeapMotion* leapObj = MMgetPointer<sLeapMotion*>(m, MTOP(leapMotionTab));
1072  if (!leapObj)
1073  {
1074  MMset(m, 0, NIL);
1075  return 0;
1076  }
1077 
1078  if (index == NIL)
1079  index = 0;
1080  else
1081  index = MTOI(index);
1082 
1083  Hand hand;
1084  if (!leapObj->GetHand(index, hand))
1085  {
1086  MMset(m, 0, NIL);
1087  return 0;
1088  }
1089 
1090  MMset(m, 0, FTOM(hand.grabStrength()));
1091 
1092 #ifdef _SCOL_DEBUG_
1093  MMechostr(MSKDEBUG,"ok\n");
1094 #endif
1095  return 0;
1096 }
1097 
1107 {
1108 #ifdef _SCOL_DEBUG_
1109  MMechostr(MSKDEBUG,"_GetLeapMotionPinchStrength\n");
1110 #endif
1111 
1112  int index = MMpull(m);
1113  int leapMotionTab = MMget(m, 0);
1114  if (leapMotionTab == NIL)
1115  {
1116  MMset(m, 0, NIL);
1117  return 0;
1118  }
1119 
1120  sLeapMotion* leapObj = MMgetPointer<sLeapMotion*>(m, MTOP(leapMotionTab));
1121  if (!leapObj)
1122  {
1123  MMset(m, 0, NIL);
1124  return 0;
1125  }
1126 
1127  if (index == NIL)
1128  index = 0;
1129  else
1130  index = MTOI(index);
1131 
1132  Hand hand;
1133  if (!leapObj->GetHand(index, hand))
1134  {
1135  MMset(m, 0, NIL);
1136  return 0;
1137  }
1138 
1139  MMset(m, 0, FTOM(hand.pinchStrength()));
1140 
1141 #ifdef _SCOL_DEBUG_
1142  MMechostr(MSKDEBUG,"ok\n");
1143 #endif
1144  return 0;
1145 }
1146 
1147 
1157 {
1158 #ifdef _SCOL_DEBUG_
1159  MMechostr(MSKDEBUG,"_SetleapMotionHmdOptimization\n");
1160 #endif
1161 
1162  int state = MMpull(m);
1163  int leapMotionTab = MMget(m, 0);
1164  if (leapMotionTab == NIL)
1165  {
1166  MMset(m, 0, NIL);
1167  return 0;
1168  }
1169 
1170  sLeapMotion* leapObj = MMgetPointer<sLeapMotion*>(m, MTOP(leapMotionTab));
1171  if (!leapObj)
1172  {
1173  MMset(m, 0, NIL);
1174  return 0;
1175  }
1176 
1177  bool bstate = false;
1178  if (state != NIL && MTOI(state) > 0)
1179  bstate = true;
1180 
1181  leapObj->SetTopTrackingEnable(bstate);
1182 
1183  MMset(m, 0, ITOM(0));
1184 
1185 #ifdef _SCOL_DEBUG_
1186  MMechostr(MSKDEBUG,"ok\n");
1187 #endif
1188  return 0;
1189 }
1190 
1191 
1192 /* Callbacks */
1193 int getLeapMotionConnectedCb(mmachine m, SCOL_PTR_TYPE id, LONG param)
1194 {
1195  int k = 0;
1196  sLeapMotion* leapObj = (sLeapMotion*)id;
1197 
1198  if (!leapObj)
1199  return 0;
1200 
1201  // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
1202  if (OBJbeginreflex(m, OBJ_LEAPMOTION_SCOL, SCOL_PTR leapObj, SCOL_LEAPMOTION_CONNECTED_CB))
1203  return 0;
1204 
1205  k=OBJcallreflex(m, 0);
1206  return k;
1207 }
1208 
1209 int getLeapMotionDisconnectedCb(mmachine m, SCOL_PTR_TYPE id, LONG param)
1210 {
1211  int k = 0;
1212  sLeapMotion* leapObj = (sLeapMotion*)id;
1213 
1214  if (!leapObj)
1215  return 0;
1216 
1217  // OBJbeginreflex(mmachine, objecttype, objectptr, cbtype)
1218  if (OBJbeginreflex(m, OBJ_LEAPMOTION_SCOL, SCOL_PTR leapObj, SCOL_LEAPMOTION_DISCONNECTED_CB))
1219  return 0;
1220 
1221  k=OBJcallreflex(m, 0);
1222  return k;
1223 }
1224 
1225 
1226 
1230 char* mLEAPMOTIONname[]=
1231 {
1232  "ObjLeapMotion",
1233 
1234  "_CRleapMotionDevice",
1235  "_DSleapMotionDevice",
1236  "_SetleapMotionHmdOptimization",
1237  "_GetLeapMotionHand",
1238  "_GetLeapMotionHandExt",
1239  "_GetLeapMotionTool",
1240  "_GetLeapMotionHandFingers",
1241  "_GetLeapMotionHandFingersWithJoints",
1242  "_GetLeapMotionGrabStrength",
1243  "_GetLeapMotionPinchStrength",
1244  "_CBLeapMotionCircleGesture",
1245  "_CBLeapMotionSwipeGesture",
1246  "_CBLeapMotionKeyTapGesture",
1247  "_CBLeapMotionScreenTapGesture"
1248 };
1249 
1253 #define NLEAPMOTIONPKG (sizeof(mLEAPMOTIONname)/sizeof(char*))
1254 
1258 int (*mLEAPMOTIONfun[NLEAPMOTIONPKG])(mmachine m)=
1259 {
1260  NULL, //ObjLeapMotion
1261 
1276 };
1277 
1281 int mLEAPMOTIONnarg[NLEAPMOTIONPKG]=
1282 {
1283  TYPTYPE, //ObjLeapMotion
1284 
1285  5, //_CRleapMotionDevice
1286  1, //_DSleapMotionDevice
1287  2, //_SetleapMotionHmdOptimization
1288  3, //_GetLeapMotionHand
1289  3, //_GetLeapMotionHandExt
1290  3, //_GetLeapMotionTool
1291  3, //_GetLeapMotionHandFingers
1292  3, //_GetLeapMotionHandFingersWithJoints
1293  2, //_GetLeapMotionGrabStrength
1294  2, //_GetLeapMotionPinchStrength
1295  3, //_CBLeapMotionCircleGesture
1296  3, //_CBLeapMotionSwipeGesture
1297  3, //_CBLeapMotionKeyTapGesture
1298  3 //_CBLeapMotionScreenTapGesture
1299 };
1300 
1304 char* mLEAPMOTIONtype[NLEAPMOTIONPKG]=
1305 {
1306  NULL, //ObjLeapMotion
1307 
1308  "fun [Chn fun [ObjLeapMotion u0] u1 u0 fun [ObjLeapMotion u2] u3 u2] ObjLeapMotion", //_CRleapMotionDevice
1309  "fun [ObjLeapMotion] I", //_DSleapMotionDevice
1310  "fun [ObjLeapMotion I] I", //_SetleapMotionHmdOptimization
1311  "fun [ObjLeapMotion I I] [[F F F] [F F F] [F F F]]", //_GetLeapMotionHand
1312  "fun [ObjLeapMotion I I] [[F F F] [F F F] [F F F] [F F F] [F F F] F]", //_GetLeapMotionHandExt
1313  "fun [ObjLeapMotion I I] [[F F F] [F F F] [F F F]]", //_GetLeapMotionTool
1314  "fun [ObjLeapMotion I I] [[[F F F] [F F F] [F F] I] r1]", //_GetLeapMotionHandFingers
1315  "fun [ObjLeapMotion I I] [[[F F F] [F F F] [F F] [[F F F] r1] I] r1]", //_GetLeapMotionHandFingersWithJoints
1316  "fun [ObjLeapMotion I] F", //_GetLeapMotionGrabStrength
1317  "fun [ObjLeapMotion I] F", //_GetLeapMotionPinchStrength
1318  "fun [ObjLeapMotion fun [ObjLeapMotion u0 I I I F F F] u1 u0] ObjLeapMotion", //_CBLeapMotionCircleGesture
1319  "fun [ObjLeapMotion fun [ObjLeapMotion u0 I I I [F F F] F F] u1 u0] ObjLeapMotion", //_CBLeapMotionSwipeGesture
1320  "fun [ObjLeapMotion fun [ObjLeapMotion u0 I I [F F F] [F F F]] u1 u0] ObjLeapMotion", //_CBLeapMotionKeyTapGesture
1321  "fun [ObjLeapMotion fun [ObjLeapMotion u0 I I [F F F] [F F F]] u1 u0] ObjLeapMotion" //_CBLeapMotionScreenTapGesture
1322 };
1323 
1324 
1325 // Everything inside _cond and _endcond is ignored by doxygen
1327 
1332 int LoadLEAPMOTION(mmachine m)
1333 {
1334  int k = 0;
1335 
1336  MMechostr(MSKDEBUG,"\n" );
1337  MMechostr(MSKDEBUG," > Loading LEAPMOTION Support\n");
1338 
1339  // Declare a new type of object ("ObjLeapMotion")
1340  OBJ_LEAPMOTION_SCOL = OBJregister(6 /*nb of callback*/, 0, destroyLEAPMOTIONObj, "OBJ_LEAPMOTION_SCOL");
1341  k = PKhardpak(m, "mLEAPMOTION.pkg-1.0", NLEAPMOTIONPKG, mLEAPMOTIONname, mLEAPMOTIONfun, mLEAPMOTIONnarg, mLEAPMOTIONtype);
1342 
1343  LEAPMOTION_CONNECTED_CB = OBJgetUserEvent();
1344  OBJdefEvent(LEAPMOTION_CONNECTED_CB, (int (__cdecl *)(struct Mmachine*, SCOL_PTR_TYPE, LONG))getLeapMotionConnectedCb);
1345 
1346  LEAPMOTION_DISCONNECTED_CB = OBJgetUserEvent();
1347  OBJdefEvent(LEAPMOTION_DISCONNECTED_CB, (int (__cdecl *)(struct Mmachine*, SCOL_PTR_TYPE, LONG))getLeapMotionDisconnectedCb);
1348 
1349  LEAPMOTION_CIRCLE_CB = OBJgetUserEvent();
1350  OBJdefEvent(LEAPMOTION_CIRCLE_CB, (int (__cdecl *)(struct Mmachine*, SCOL_PTR_TYPE, LONG))getLeapMotionCircleCb);
1351 
1352  LEAPMOTION_SWIPE_CB = OBJgetUserEvent();
1353  OBJdefEvent(LEAPMOTION_SWIPE_CB, (int (__cdecl *)(struct Mmachine*, SCOL_PTR_TYPE, LONG))getLeapMotionSwipeCb);
1354 
1355  LEAPMOTION_KEYTAP_CB = OBJgetUserEvent();
1356  OBJdefEvent(LEAPMOTION_KEYTAP_CB, (int (__cdecl *)(struct Mmachine*, SCOL_PTR_TYPE, LONG))getLeapMotionKeyTapCb);
1357 
1358  LEAPMOTION_SCREENTAP_CB = OBJgetUserEvent();
1359  OBJdefEvent(LEAPMOTION_SCREENTAP_CB, (int (__cdecl *)(struct Mmachine*, SCOL_PTR_TYPE, LONG))getLeapMotionScreenTapCb);
1360 
1361  MMechostr(MSKDEBUG," > Successfully Loaded\n\n");
1362  return k;
1363 }
1364 
1365 int CloseLEAPMOTION()
1366 {
1367  MMechostr(MSKDEBUG,"\n" );
1368  MMechostr(MSKDEBUG," > Unloading LEAPMOTION Support\n");
1369 
1370  MMechostr(MSKDEBUG," > Successfully unloaded\n\n");
1371  return 0;
1372 }
1373 
1375 
1376 #ifndef SCOL_STATIC
1377 
1381 extern "C" SCOL_EXPORT int ScolLoadPlugin(mmachine m, cbmachine w)
1382 {
1383  SCOLinitplugin(w);
1384  mm = m;
1385 
1386  return LoadLEAPMOTION(m);
1387 }
1388 
1393 extern "C" SCOL_EXPORT int ScolUnloadPlugin()
1394 {
1395  return CloseLEAPMOTION();
1396 }
1397 #else
1398 
1402 extern "C" SCOL_EXPORT int ScolLeapMotionLoadPlugin(mmachine m, cbmachine w)
1403 {
1404  SCOLinitplugin(w);
1405  mm = m;
1406 
1407  return LoadLEAPMOTION(m);
1408 }
1409 
1414 extern "C" SCOL_EXPORT int ScolLeapMotionUnloadPlugin()
1415 {
1416  return CloseLEAPMOTION();
1417 }
1418 #endif
int _GetLeapMotionPinchStrength(mmachine m)
_GetLeapMotionPinchStrength : Get a LEAPMOTION hand Pinch strengh
int _SetleapMotionHmdOptimization(mmachine m)
_SetleapMotionHmdOptimization : Set the LEAPMOTION Hmd optimization enable or disable ...
int _CBLeapMotionCircleGesture(mmachine m)
_CBLeapMotionCircleGesture : Called on a Circle gesture
Definition: scolplugin.cpp:808
int _GetLeapMotionTool(mmachine m)
_GetLeapMotionTool : Get a LEAPMOTION tool position, orientation and velocity
Definition: scolplugin.cpp:442
int _GetLeapMotionHandFingers(mmachine m)
_GetLeapMotionHandFingers : Get the LEAPMOTION sensor fingers data from a hand
Definition: scolplugin.cpp:544
int _CBLeapMotionScreenTapGesture(mmachine m)
_CBLeapMotionScreenTapGesture : Called on a ScreenTap gesture
Definition: scolplugin.cpp:993
int _GetLeapMotionGrabStrength(mmachine m)
_GetLeapMotionGrabStrength : Get a LEAPMOTION hand Grab strengh
int _GetLeapMotionHandFingersWithJoints(mmachine m)
_GetLeapMotionHandFingersWithJoints : Get the LEAPMOTION sensor fingers data from a hand with finger ...
Definition: scolplugin.cpp:657
int _GetLeapMotionHandExt(mmachine m)
_GetLeapMotionHandExt : Get a LEAPMOTION hand position, orientation, direction and normal ...
Definition: scolplugin.cpp:311
int _CBLeapMotionSwipeGesture(mmachine m)
_CBLeapMotionSwipeGesture : Called on a Swipe gesture
Definition: scolplugin.cpp:861
int _CRleapMotionDevice(mmachine m)
_CRleapMotionDevice : This function create a LEAPMOTION object
Definition: scolplugin.cpp:111
int _DSleapMotionDevice(mmachine m)
_DSleapMotionDevice : Destroy LEAPMOTION object
Definition: scolplugin.cpp:177
int _CBLeapMotionKeyTapGesture(mmachine m)
_CBLeapMotionKeyTapGesture : Called on a KeyTap gesture
Definition: scolplugin.cpp:924
int _GetLeapMotionHand(mmachine m)
_GetLeapMotionHand : Get a LEAPMOTION hand position and orientation
Definition: scolplugin.cpp:208