Exemplo n.º 1
0
    protected PinchState GetNewPinchState()
    {
        HandModel hand_model = GetComponent <HandModel>();

        Leap.Hand leap_hand = hand_model.GetLeapHand();

        Leap.Vector leap_thumb_tip   = leap_hand.Fingers[0].TipPosition;
        float       closest_distance = Mathf.Infinity;

        // Check thumb tip distance to joints on all other fingers.
        // If it's close enough, you're pinching.
        for (int i = 1; i < HandModel.NUM_FINGERS; ++i)
        {
            Leap.Finger finger = leap_hand.Fingers[i];

            for (int j = 0; j < FingerModel.NUM_BONES; ++j)
            {
                Leap.Vector leap_joint_position = finger.Bone((Leap.Bone.BoneType)j).NextJoint;

                float thumb_tip_distance = leap_joint_position.DistanceTo(leap_thumb_tip);
                closest_distance = Mathf.Min(closest_distance, thumb_tip_distance);
            }
        }

        // Scale trigger distance by thumb proximal bone length.
        float proximal_length  = leap_hand.Fingers[0].Bone(Leap.Bone.BoneType.TYPE_PROXIMAL).Length;
        float trigger_distance = proximal_length * grabTriggerDistance;
        float release_distance = proximal_length * releaseTriggerDistance;

        if (closest_distance <= trigger_distance)
        {
            return(PinchState.kPinched);
        }
        if (closest_distance <= release_distance && pinch_state_ != PinchState.kReleased &&
            !ObjectReleaseBreak(current_pinch_position_))
        {
            return(PinchState.kReleasing);
        }
        return(PinchState.kReleased);
    }
Exemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        Frame frame = controller.Frame();

        Debug.Log("Frame Id: " + frame.Id);
        frameCount++;

        HandList hands = frame.Hands;

        for (int i = 0; i < hands.Count; i++)
        {
            Hand        hand         = hands[i];
            Leap.Vector direction    = hand.Direction;
            Leap.Vector palmNormal   = hand.PalmNormal;
            Leap.Vector palmPosition = hand.PalmPosition;
            Leap.Vector handSpeed    = hand.PalmVelocity;


            if (i == 0)
            {
                fdistanceDirection    = direction.DistanceTo(fprevDirection);
                fdistancePalmPosition = palmPosition.DistanceTo(fprevPalmPosition);
                fdistancePalmNormal   = palmNormal.DistanceTo(fprevPalmNormal);
                fdistanceHandVelocity = handSpeed.DistanceTo(fprevHandVelocity);

                fprevDirection    = direction;
                fprevPalmNormal   = palmNormal;
                fprevPalmPosition = palmPosition;
                fprevHandVelocity = handSpeed;
            }
            else if (i == 1)
            {
                sdistanceDirection    = direction.DistanceTo(sprevDirection);
                sdistancePalmPosition = palmPosition.DistanceTo(sprevPalmPosition);
                sdistancePalmNormal   = palmNormal.DistanceTo(sprevPalmNormal);
                sdistanceHandVelocity = handSpeed.DistanceTo(sprevHandVelocity);

                sprevDirection    = direction;
                sprevPalmNormal   = palmNormal;
                sprevPalmPosition = palmPosition;
                sprevHandVelocity = handSpeed;

                Debug.Log("first direction " + fdistanceDirection);
                Debug.Log("second direction " + sdistanceDirection);

                Debug.Log("Direction change = " + (fdistanceDirection - sdistanceDirection));
                directionFile.WriteLine("");
                directionFile.WriteLine("frame id: " + frame.Id);
                directionFile.WriteLine("Direction first: " + fdistanceDirection + " second: " + sdistanceDirection + " diff: " + (fdistanceDirection - sdistanceDirection));
                directionFile.WriteLine("PalmPosition first: " + fdistancePalmPosition + " second: " + sdistancePalmPosition + " diff: " + (fdistancePalmPosition - sdistancePalmPosition));
                directionFile.WriteLine("PalmNormal first: " + fdistancePalmNormal + " second: " + sdistancePalmNormal + " diff: " + (fdistancePalmNormal - sdistancePalmNormal));
                directionFile.WriteLine("Velocity first: " + fdistanceHandVelocity + " second: " + sdistanceHandVelocity + " diff: " + (fdistanceHandVelocity - sdistanceHandVelocity));

                directionFile.WriteLine("");
                float directionChange    = (fdistanceDirection - sdistanceDirection);
                float palmPositionChange = fdistancePalmPosition - sdistancePalmPosition;
                float palmNormalChange   = fdistancePalmNormal - sdistancePalmNormal;
                float velocityChange     = fdistanceHandVelocity - sdistanceHandVelocity;

                if (directionChange < 0.0f)
                {
                    directionChange *= -1.0f;
                }
                if (palmPositionChange < 0.0f)
                {
                    palmPositionChange *= -1.0f;
                }
                if (palmNormalChange < 0.0f)
                {
                    palmNormalChange *= -1.0f;
                }
                if (velocityChange < 0.0f)
                {
                    velocityChange *= -1.0f;
                }

                totalDistance     += directionChange;
                totalPalmPosition += palmPositionChange;
                totalPalmNormal   += palmNormalChange;
                totalVelocity     += velocityChange;
                test_status        = "Status:\n";
                if (directionChange < 0.001)
                {
                    test_status += "Direction OK\n";
                }
                else
                {
                    test_status += "Fix Direction\n";
                }

                if (palmPositionChange < 1.0)
                {
                    test_status += "PalmPosition OK\n";
                }
                else
                {
                    test_status += "Fix PalmPosition\n";
                }

                if (palmNormalChange < 1.0)
                {
                    test_status += "PalmNormal OK\n";
                }
                else
                {
                    test_status += "Fix PalmNormal\n";
                }

                if (velocityChange < 1.0)
                {
                    test_status += "Velocity OK\n";
                }
                else
                {
                    test_status += "Fix Velocity\n";
                }

                float error = totalDistance * 2.0f + totalPalmNormal * 2.0f + totalVelocity + totalPalmPosition * 3.0f;
                error /= (4 * frameCount);

                var message = new SharpOSC.OscMessage("/hand/1", error);
                var sender  = new SharpOSC.UDPSender("127.0.0.1", 55555);
                sender.Send(message);

                if (error > 5.0)
                {
                    status_text.color = Color.red;
                    test_status      += "Not matching";
                    //source.PlayOneShot(buzzSound);
                }
                else
                {
                    status_text.color = Color.green;
                    test_status      += "Matching";
                    //source.PlayOneShot(matchSound);
                }


                status_text.text = test_status;
            }
        }
    }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        Frame frame = controller.Frame();

        Debug.Log("Frame Id: " + frame.Id);
        frameCount++;

        HandList hands = frame.Hands;

        for (int i = 0; i < hands.Count; i++)
        {
            Hand        hand         = hands[i];
            Leap.Vector direction    = hand.Direction;
            Leap.Vector palmNormal   = hand.PalmNormal;
            Leap.Vector palmPosition = hand.PalmPosition;
            Leap.Vector handSpeed    = hand.PalmVelocity;


            if (i == 0)
            {
                fdistanceDirection    = direction.DistanceTo(fprevDirection);
                fdistancePalmPosition = palmPosition.DistanceTo(fprevPalmPosition);
                fdistancePalmNormal   = palmNormal.DistanceTo(fprevPalmNormal);
                fdistanceHandVelocity = handSpeed.DistanceTo(fprevHandVelocity);

                fprevDirection    = direction;
                fprevPalmNormal   = palmNormal;
                fprevPalmPosition = palmPosition;
                fprevHandVelocity = handSpeed;
            }
            else if (i == 1)
            {
                sdistanceDirection    = direction.DistanceTo(sprevDirection);
                sdistancePalmPosition = palmPosition.DistanceTo(sprevPalmPosition);
                sdistancePalmNormal   = palmNormal.DistanceTo(sprevPalmNormal);
                sdistanceHandVelocity = handSpeed.DistanceTo(sprevHandVelocity);

                sprevDirection    = direction;
                sprevPalmNormal   = palmNormal;
                sprevPalmPosition = palmPosition;
                sprevHandVelocity = handSpeed;

                Debug.Log("first direction " + fdistanceDirection);
                Debug.Log("second direction " + sdistanceDirection);

                Debug.Log("Direction change = " + (fdistanceDirection - sdistanceDirection));
                directionFile.WriteLine("");
                directionFile.WriteLine("frame id: " + frame.Id);
                directionFile.WriteLine("Direction first: " + fdistanceDirection + " second: " + sdistanceDirection + " diff: " + (fdistanceDirection - sdistanceDirection));
                directionFile.WriteLine("PalmPosition first: " + fdistancePalmPosition + " second: " + sdistancePalmPosition + " diff: " + (fdistancePalmPosition - sdistancePalmPosition));
                directionFile.WriteLine("PalmNormal first: " + fdistancePalmNormal + " second: " + sdistancePalmNormal + " diff: " + (fdistancePalmNormal - sdistancePalmNormal));
                directionFile.WriteLine("Velocity first: " + fdistanceHandVelocity + " second: " + sdistanceHandVelocity + " diff: " + (fdistanceHandVelocity - sdistanceHandVelocity));

                directionFile.WriteLine("");
                float directionChange    = (fdistanceDirection - sdistanceDirection);
                float palmPositionChange = fdistancePalmPosition - sdistancePalmPosition;
                float palmNormalChange   = fdistancePalmNormal - sdistancePalmNormal;
                float velocityChange     = fdistanceHandVelocity - sdistanceHandVelocity;

                if (directionChange < 0.0f)
                {
                    directionChange *= -1.0f;
                }
                if (palmPositionChange < 0.0f)
                {
                    palmPositionChange *= -1.0f;
                }
                if (palmNormalChange < 0.0f)
                {
                    palmNormalChange *= -1.0f;
                }
                if (velocityChange < 0.0f)
                {
                    velocityChange *= -1.0f;
                }

                totalDistance     += directionChange;
                totalPalmPosition += palmPositionChange;
                totalPalmNormal   += palmNormalChange;
                totalVelocity     += velocityChange;
            }
        }
    }