// Use this for initialization void Start() { theHand = GameObject.FindGameObjectWithTag("handControl").GetComponent <HandController>(); Leap.Frame frame = theHand.GetFrame(); // controller is a Controller object Leap.HandList hands = frame.Hands; firstHand = hands[0]; Debug.Log("starting"); }
//1,DISTAL(tip) 2,INTERMEDIATE 3,PROXIMAL // Update is called once per frame void Update() { Leap.Frame frame = controller.GetFrame(); if (gestureOption == 0) { hands = frame.Hands; Leap.Hand hand = hands.Leftmost; //Debug.Log ("here"); if (hand.IsValid && hand.IsLeft) { Leap.FingerList fingers = hand.Fingers; Leap.Vector tipV = fingers[0].TipVelocity; float tipVmag = tipV.Magnitude; //Leap.Vector tipV2 = fingers[1].TipVelocity; Leap.Bone bone = fingers[0].Bone(Leap.Bone.BoneType.TYPE_DISTAL); //Leap.Bone bone2 = fingers[1].Bone (Leap.Bone.BoneType.TYPE_DISTAL); float distFromBoneToPalm = bone.Center.DistanceTo(hand.PalmPosition); float palmDirectionSign = hand.PalmNormal.Dot(vecUpInLeapForm); //Debug.Log (distFromBoneToPalm + " " + palmDirectionSign + " " + tipVmag + " " + hand.Confidence); //Debug.Log (bone.Direction.Pitch); if (distFromBoneToPalm < 70 && palmDirectionSign > 0.5 && tipVmag > 30 && hand.Confidence > 0.7) { getCollidersInARangeAndSendMessage(); } } } else if (gestureOption == 1) { Leap.GestureList gestures = frame.Gestures(); for (int i = 0; i < gestures.Count; i++) { if (gestures[i].Type == Leap.Gesture.GestureType.TYPESWIPE) { if (gestures[i].IsValid && gestures[i].State == Leap.Gesture.GestureState.STATESTOP) { Debug.Log("Yes"); getCollidersInARangeAndSendMessage(); } } } } }
/* React to the New Frame Received from the Leap Motion */ public override void OnFrame(Leap.Controller controller) { // Get Hand from this current Frame InputManager IM = _instance; Leap.HandList hands = controller.Frame().Hands; // Restrict to One Hand Detection if (hands.Count == 1) { // Call Leap Motion Update try { OnLeapMotionUpdate(hands.Frontmost); Debug.Log("Hand Detected"); } catch (Exception e) { Debug.Log(e.ToString()); Debug.Log(e.ToString()); } } else if (IM.currentSimilarity != ASLTest.INVALID_ASL_TEST) { IM.UpdateCurrentSimilarity(ASLTest.INVALID_ASL_TEST); IM.UpdateCurrentLetter(INVALID_ASL_LETTER); /* * //Handle case of Leap Motion with no more detection * IM.currentLetter = INVALID_ASL_LETTER; * IM.similarityHandler(ASLTest.INVALID_ASL_TEST); * IM.letterHandler(INVALID_ASL_LETTER); * IM.currentLetter = INVALID_ASL_LETTER;*/ } // For Debugging Purposes only if (updateDebugLogOnFrame) { Debug.Log("New Frame available"); updateDebugLogOnFrame = false; } }
public override void positionDidUpdate(Leap.HandList hands) { this.hands = hands; if (this.hands.Count == this.NumberOfHandsRequired) { if (isDesiredNumberOfFingersPerHand()) { MotionAverages averages = averageVectorForHands(); if (averages != null) { centerPoint = averages.positionAverage; processTouchVector(); } else { processNonTouch(); } } } }
/* * Check for gestures on each frame */ void Update() { Frame frame = controller.Frame(); //Frame with hands string currentScene = SceneManager.GetActiveScene().name; // Current scene name // One-handed gestures if (frame.Hands.Count == 1) { Leap.HandList hands = frame.Hands; Hand hand0 = hands [0]; // Main scene gestures if (currentScene == "mainScene") { float maxRadius = 50; float x = hand0.PalmPosition.ToUnity().x; float y = hand0.PalmPosition.ToUnity().y; // If fist is closed if (hand0.SphereRadius < maxRadius) { MapNavigation(x, y); } } // Painting and sculpture gestures else if ((currentScene == "paintingScene") || (currentScene == "sculptureScene")) { float minDotProd = 0.85f; float velocityThreshold = 1000; // If hand is tilted if (Mathf.Abs(Vector3.Dot(hand0.PalmNormal.ToUnity(), Vector3.left)) > minDotProd) { if (hand0.PalmVelocity.x < -velocityThreshold) // if moving left { if (handIsMoving == false) { handIsMoving = true; Debug.Log("Next"); Next(currentScene); } } else if (hand0.PalmVelocity.x > velocityThreshold) // if moving right { if (handIsMoving == false) { handIsMoving = true; Debug.Log("Previous"); Previous(currentScene); } } else { handIsMoving = false; } } else { handIsMoving = false; } } } // Two-handed gestures else if (frame.Hands.Count == 2) { Leap.HandList hands = frame.Hands; Hand hand0 = hands [0]; Hand hand1 = hands [1]; Finger index0 = hand0.Fingers [1]; Finger index1 = hand1.Fingers [1]; // number of extended fingers int numExtended = hand0.Fingers.Extended().Count + hand0.Fingers.Extended().Count; // number of fingers int numOfFingers = hand0.Fingers.Count + hand1.Fingers.Count; // are all fingers extended? bool allExtended = numOfFingers == numExtended; if (currentScene == "mainScene") { float angle1 = Vector3.Angle(Vector3.down, hand0.PalmNormal.ToUnity()); float angle2 = Vector3.Angle(Vector3.down, hand1.PalmNormal.ToUnity()); // If both hands are extended facing down if ((angle1 < 45) && (angle2 < 45) && allExtended) { Zoom(hand0, hand1); } else // Stop zooming { if (zoom == true) { cameraPos = camera_.transform.position; } zoom = false; } } else { // exit to main scene Vector index0center = index0.Bone(Leap.Bone.BoneType.TYPE_PROXIMAL).NextJoint; Vector index1center = index1.Bone(Leap.Bone.BoneType.TYPE_PROXIMAL).NextJoint; float index01distance = index0center.DistanceTo(index1center); float minCrossAngle = 1; float maxCrossAngle = 2; float triggerDist = 45; // If both index fingers are extended if (index0.IsExtended && index1.IsExtended && (numExtended == 2)) { float crossAngle = index0.Direction.AngleTo(index1.Direction); // If both fingers are close and approximately form a perpendicular angle if ((crossAngle > minCrossAngle) && (crossAngle < maxCrossAngle) && index01distance < triggerDist) { Exit(); } } } } }
/** * Constructs a Frame object. * * Frame instances created with this constructor are invalid. * Get valid Frame objects by calling the Controller::frame() function. * * \include Frame_Frame.txt * * The only time you should use this constructor is before deserializing * serialized frame data. Call ``Frame::deserialize(string)`` to recreate * a saved Frame. * * @since 1.0 */ public Frame() { _fingers = new FingerList(15); _hands = new HandList(3); _trackedQuad = new TrackedQuad(); }
void Update() { // Debug.Log("before getting object"); theHand = GameObject.FindGameObjectWithTag("handControl").GetComponent <HandController>(); // Debug.Log("before getting frame"); Leap.Frame frame = theHand.GetFrame(); // controller is a Controller object // Debug.Log("before getting hands list"); Leap.HandList hands = frame.Hands; rigidHand = GameObject.FindObjectOfType(typeof(RigidHand)) as RigidHand; float new_pitch = 0; float new_yaw = 0; float new_roll = 0; if (rigidHand != null) { new_pitch = rigidHand.GetPalmRotation().eulerAngles.x; new_yaw = rigidHand.GetPalmRotation().eulerAngles.y; new_roll = rigidHand.GetPalmRotation().eulerAngles.z; } //Debug.Log(rigidHand.GetPalmRotation().eulerAngles.ToString()); //Debug.Log("before"); //if (firstHand != null) //{ // firstHand = hands[0]; Debug.Log("old pitch: " + pitch); Debug.Log("old yaw " + yaw); Debug.Log("old roll " + roll); /* * float new_pitch = firstHand.Direction.Pitch; * float new_yaw = firstHand.Direction.Yaw; * float new_roll = firstHand.Direction.Roll;*/ float pitch_diff = Math.Abs(new_pitch - pitch); float roll_diff = Math.Abs(new_roll - roll); float yaw_diff = Math.Abs(new_yaw - yaw); /*if (pitch_diff > maxAngleThreshold || pitch_diff < minAngleThreshold) * new_pitch = pitch; * if (roll_diff > maxAngleThreshold || roll_diff < minAngleThreshold) * new_roll = roll; * if (yaw_diff > maxAngleThreshold || yaw_diff < minAngleThreshold) * new_yaw = yaw;*/ pitch = new_pitch; roll = new_roll; yaw = new_yaw; Debug.Log("next"); //Leap.Vector test; //test. //test.Pitch = 1; //test.Yaw = 2; //test.Roll = 3; if (Input.GetKey(KeyCode.R)) { nuetPitch = rigidHand.GetPalmRotation().eulerAngles.x; nuetYaw = rigidHand.GetPalmRotation().eulerAngles.y; nuetRoll = rigidHand.GetPalmRotation().eulerAngles.z; } }