You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

93 lines
2.1 KiB

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