arnaucube
arnaucube/comunicationLeapPublic Self-hosted repository
comunicationLeap/clientLeap/leapController.js
clientLeap/leapController.jsRaw
 1var hand;
 2var position;
 3var velocity;
 4var direction;
 5
 6var actObj="o2";
 7
 8Leap.loop({enableGestures: true}, function(frame){
 9
10
11
12
13  if(frame.valid && frame.gestures.length > 0){
14    frame.gestures.forEach(function(gesture){
15
16      var clockwise = false;
17      var pointableID = gesture.pointableIds[0];
18      var direction = frame.pointable(pointableID).direction;
19      if((direction)&&(gesture.normal))
20      {
21        var dotProduct = Leap.vec3.dot(direction, gesture.normal);
22      }
23
24      //hand
25      hand = frame.hands[0];
26      if(hand)
27      {
28        position = hand.palmPosition;
29        velocity = hand.palmVelocity;
30        direction = hand.direction;
31      }
32
33        switch (gesture.type){
34          case "circle":
35              console.log("Circle Gesture");
36              //mRotation(o4);
37              if (dotProduct  >  0){
38                console.log("r");
39                RotationR2Server(actObj);
40              }else{
41                console.log("l");
42                RotationL2Server(actObj);
43              }
44              break;
45          case "keyTap":
46              console.log("Key Tap Gesture");
47              AddCube2Server();
48              //mAddCube();
49              break;
50          case "screenTap":
51              console.log("Screen Tap Gesture");
52              ZoomIn2Server();
53              break;
54          case "swipe":
55              console.log("Swipe Gesture");
56              //o4.rotation.x +=0.1;
57              break;
58        }
59    });
60
61    if(frame.hands.length>1)
62    {
63      console.log("twohands");
64    }
65    /*if(frame.hands.length > 0)
66    {//axis rotation
67      var previousFrame = controller.frame(1);
68      var axis = hand.rotationAxis(previousFrame);
69      console.log("Axis of Rotation: (" + axis[0] + ", " + axis[1] + ", " + axis[2] + ")");
70    }*/
71  }
72  if(frame.hands.length > 0)
73  {
74    if(HandAction(frame.hands[0])=="open"){
75    //  ZoomIn2Server();
76    }else if(HandAction(frame.hands[0])=="close"){
77      ZoomOut2Server();
78    }
79  }
80
81
82
83});
84
85
86
87function HandAction(hand){
88  console.log(hand.grabStrength);
89  if(hand.grabStrength > 0.99) return "close";
90    else if (hand.grabStrength < 0.01) return "open";
91
92    return"not detected";
93}