Inheritance: MonoBehaviour
        public void UpdateHand(LeapHand value = null)
        {
            if (value != null)
            {
                hand = value;
            }

            if (hand == null)
            {
                return;
            }

            parts[(int)HandPart.Palm].localPosition = hand.PalmPosition.ToHMDVector3();
            parts[(int)HandPart.Palm].localRotation = hand.Rotation.ToHMDQuaternion();
            for (int fingerIndex = 0; fingerIndex < hand.Fingers.Count; fingerIndex++)
            {
                int index = fingerIndex + FIRST_FINGER_INDEX;
                parts[index].localPosition = hand.Fingers[fingerIndex].TipPosition.ToHMDVector3();
            }

            Quaternion armRotation = hand.Arm.Rotation.ToHMDQuaternion();

            parts[(int)HandPart.Wrist].localPosition = hand.WristPosition.ToHMDVector3();
            parts[(int)HandPart.Wrist].localRotation = armRotation;

            parts[(int)HandPart.Arm].localPosition = hand.Arm.Center.ToHMDVector3();
            parts[(int)HandPart.Arm].localRotation = armRotation;
        }
Exemple #2
0
    // Update is called once per frame
    void Update()
    {
        RigidHand[] handsCatcher = (RigidHand[])GameObject.FindObjectsOfType(typeof(RigidHand));

        foreach (RigidHand hand in handsCatcher)
        {
            LeapHand lHand = new LeapHand(hand);
            if (this.hands[0].handedness == lHand.handedness)
            {
                if (handComp.compareHand(this.hands[0], lHand))
                {
                    this.playershooting.Shoot();
                    Debug.Log("DDDAAALLEEEEE");
                }
            }
            else
            {
                if (handComp.compareHand(this.hands[1], lHand))
                {
                    this.playershooting.Shoot();
                    Debug.Log("EEEEELLAAADDD");
                }
            }
        }
    }
    void Update()
    {
        Frame f = m_leapController.Frame();

        // mark exising hands as stale.
        foreach (KeyValuePair <int, GameObject> h in m_hands)
        {
            h.Value.GetComponent <LeapHand>().m_stale = true;
        }

        // see what hands the leap sees and mark matching hands as not stale.
        for (int i = 0; i < f.Hands.Count; ++i)
        {
            GameObject hand;
            m_hands.TryGetValue(f.Hands[i].Id, out hand);

            // see if hand existed before
            if (hand != null)
            {
                // if it did then just update its position and joint positions.

                hand.transform.position = m_parent.TransformPoint(m_offset + f.Hands[i].PalmPosition.ToUnityScaled());
                hand.transform.forward  = f.Hands[i].Direction.ToUnity();

                LeapHand leapHand = hand.GetComponent <LeapHand>();
                leapHand.m_stale = false;
                leapHand.UpdateFingers(f.Hands[i], m_parent, m_offset);
                leapHand.UpdateKnuckleLanges();
            }
            else
            {
                // else create new hand
                hand = Instantiate(Resources.Load("Prefabs/Hand")) as GameObject;
                // push it into the dictionary.
                m_hands.Add(f.Hands[i].Id, hand);
            }
        }

        // clear out stale hands.
        List <int> staleIDs = new List <int>();

        foreach (KeyValuePair <int, GameObject> h in m_hands)
        {
            if (h.Value.GetComponent <LeapHand>().m_stale)
            {
                Destroy(h.Value);
                // set for removal from dictionary.
                staleIDs.Add(h.Key);
            }
        }
        foreach (int id in staleIDs)
        {
            m_hands.Remove(id);
        }
    }
    //Destroy Unity components of the hand
    public void DestroyHandComponents(LeapHand leapHand)
    {
        Destroy(leapHand.getHandObject());

        DestroyFingerComponents(leapHand.getThumb());

        DestroyFingerComponents(leapHand.getIndex());

        DestroyFingerComponents(leapHand.getMiddle());

        DestroyFingerComponents(leapHand.getRing());

        DestroyFingerComponents(leapHand.getPinky());
    }
Exemple #5
0
    // Update is called once per frame
    void Update()
    {
        RigidHand[] handsCatcher = (RigidHand[])GameObject.FindObjectsOfType(typeof(RigidHand));
        LeapHand[]  hands        = GetComponent <HandRegister>().hands;

        foreach (RigidHand hand in handsCatcher)
        {
            LeapHand lHand = new LeapHand(hand);

            foreach (LeapHand savedHand in hands)
            {
                if (savedHand.handedness == lHand.handedness)
                {
                    if (handComp.compareHand(savedHand, lHand))
                    {
                        Debug.Log("ITS ALIVE");
                    }
                }
            }
        }
    }
Exemple #6
0
    // assume the current and saved LeapHand has the same Chirality
    public bool compareHand(LeapHand current, LeapHand saved)
    {
        bool result = true;

        if (this.handsVerify.Contains(current.handedness) && this.handsVerify.Contains(saved.handedness))
        {
            if (this.forearmVerify && saved.forearm != null)
            {
                result = result && compareGuidanceWithTHreshold(current.forearm, saved.forearm);
            }

            if (this.palmVerify && saved.palm != null)
            {
                result = result && compareGuidanceWithTHreshold(current.palm, saved.palm);
            }

            if (this.elbowJointVerify && saved.elbowJoint != null)
            {
                result = result && compareGuidanceWithTHreshold(current.elbowJoint, saved.elbowJoint);
            }

            // fingersVerify length can launch exception
            for (int i = 0; i < fingersVerify.Length; i++)
            {
                if (fingersVerify[i])
                {
                    for (int j = 0; j <= 3; ++j)
                    {
                        if (saved.fingers[i, j] != null)
                        {
                            result = result && compareGuidanceWithTHreshold(current.fingers[i, j], saved.fingers[i, j]);
                        }
                    }
                }
            }
        }


        return(result);
    }
        private void DataReady(object sender, FrameEventArgs e)
        {
            if (OnSerializationReady == null)
            {
                return;
            }

            Frame frame = e.frame;

            if (frame == null)
            {
                //OnSerializationReady.Invoke(this, new SerializationEventArgs(LeapSerialization.DataIndex));
                return;
            }

            LeapFrame newFrame = new LeapFrame()
            {
                Id = frame.Id
            };

            List <Hand> hands = frame.Hands;

            int handCount = limitedHandCount == -1 ? hands.Count : Math.Min(limitedHandCount, hands.Count);

            for (int handIndex = 0; handIndex < handCount; handIndex++)
            {
                Hand hand = hands[handIndex];

                List <Finger>     fingers     = hand.Fingers;
                List <LeapFinger> leapFingers = new List <LeapFinger>();
                for (int fingerIndex = 0; fingerIndex < FingerCount; fingerIndex++)
                {
                    Finger     finger     = fingers[fingerIndex];
                    LeapFinger leapFinger = new LeapFinger()
                    {
                        Id          = finger.Id,
                        IsExtended  = fingers[fingerIndex].IsExtended,
                        TimeVisible = fingers[fingerIndex].TimeVisible,
                        Width       = fingers[fingerIndex].Width,
                        Length      = fingers[fingerIndex].Length,
                        TipPosition = fingers[fingerIndex].TipPosition.ToSerialiableVector(),
                        Direction   = fingers[fingerIndex].Direction.ToSerialiableVector(),
                        TipVelocity = fingers[fingerIndex].TipVelocity.ToSerialiableVector()
                                      //StabilizedTipVelocity = fingers[fingerIndex].ToSerialiableVector()
                    };

                    if (readBones)
                    {
                        Bone[]     bones     = fingers[fingerIndex].bones;
                        LeapBone[] leapBones = new LeapBone[BoneCount];
                        for (int boneIndex = 0; boneIndex < BoneCount; boneIndex++)
                        {
                            leapBones[boneIndex] = new LeapBone()
                            {
                                Length    = bones[boneIndex].Length,
                                Width     = bones[boneIndex].Width,
                                Center    = bones[boneIndex].Center.ToSerialiableVector(),
                                Direction = bones[boneIndex].Direction.ToSerialiableVector(),
                                Rotation  = bones[boneIndex].Rotation.ToSerialiableQuaternion()
                            };
                        }
                        leapFinger.bones = leapBones;
                    }

                    leapFingers.Add(leapFinger);
                }

                LeapHand leapHand = new LeapHand()
                {
                    Id            = hand.Id,
                    IsLeft        = hand.IsLeft,
                    Confidence    = hand.Confidence,
                    TimeVisible   = hand.TimeVisible,
                    GrabStrength  = hand.GrabStrength,
                    GrabAngle     = hand.GrabAngle,
                    PinchStrength = hand.PinchStrength,
                    PinchDistance = hand.PinchDistance,
                    PalmWidth     = hand.PalmWidth,
                    PalmPosition  = hand.PalmPosition.ToSerialiableVector(),
                    PalmVelocity  = hand.PalmVelocity.ToSerialiableVector(),
                    Direction     = hand.Direction.ToSerialiableVector(),
                    PalmNormal    = hand.PalmNormal.ToSerialiableVector(),
                    Rotation      = hand.Rotation.ToSerialiableQuaternion(),
                    WristPosition = hand.WristPosition.ToSerialiableVector(),
                    //StabilizedPalmPosition = hand.StabilizedPalmPosition.ToSerialiableVector(),

                    Fingers = leapFingers,
                };

                if (readArm)
                {
                    Arm     arm     = hand.Arm;
                    LeapArm leapArm = new LeapArm()
                    {
                        Length    = arm.Length,
                        Width     = arm.Width,
                        Elbow     = arm.ElbowPosition.ToSerialiableVector(),
                        Wrist     = arm.WristPosition.ToSerialiableVector(),
                        Center    = hand.Arm.Center.ToSerialiableVector(),
                        Direction = hand.Arm.Direction.ToSerialiableVector(),
                        Rotation  = hand.Arm.Rotation.ToSerialiableQuaternion()
                    };

                    leapHand.Arm = leapArm;
                }

                newFrame.Hands.Add(leapHand);
            }

            data.frame = newFrame;

            if (hands.Count > 0)
            {
                OnSerializationReady.Invoke(this, new SerializationEventArgs(LeapData.DataIndex, SerializationUtil.Serialize(data), true));
                sentNoHandTimes = 0;
            }
            else if (SendNoHandMaxCount == -1 || ++sentNoHandTimes <= SendNoHandMaxCount)
            {
                OnSerializationReady.Invoke(this, new SerializationEventArgs(LeapData.DataIndex, SerializationUtil.Serialize(data), true));
            }
        }
Exemple #8
0
 void Start()
 {
     controller = GetComponent <HandController>();
     debug      = GetComponent <LiveDebug>();
     hand       = new LeapHand(this, debug);
 }
Exemple #9
0
 private void OnHandUpdate(LeapHand hand)
 {
     grabStrategy.OnHandUpdate(hand);
 }
    //Update hands
    void UpdateHands()
    {
        if (!frame.Hands.IsEmpty)
        {
            foreach (Leap.Hand hand in frame.Hands)
            {
                //If the hand is not in the list, add it to the list
                bool checkHand = false;
                int  handIndex = -1;
                foreach (LeapHand leapHand in handList)
                {
                    if (leapHand.getHand().Id == hand.Id)
                    {
                        checkHand = true;
                        handIndex = handList.IndexOf(leapHand);
                        break;
                    }
                }

                //Check whether it is a new hand
                if (!checkHand)
                {
                    //A new hand
                    LeapHand newHand = new LeapHand(hand);
                    handList.Add(newHand);
                }
                else
                {
                    //An existing hand
                    handList [handIndex].UpdateHand(hand);
                }
            }

            //Check if there is any hand that should be removed
            for (int i = handList.Count - 1; i >= 0; --i)
            {
                LeapHand leapHand = handList [i];

                bool handInclude = false;
                foreach (Hand hand in frame.Hands)
                {
                    if (leapHand.getHand().Id == hand.Id)
                    {
                        handInclude = true;
                        break;
                    }
                }

                //Remove the hand
                if (handInclude == false)
                {
                    DestroyHandComponents(leapHand);
                    handList.Remove(leapHand);
                }
            }
        }
        else
        {
            //Remove all the hands
            foreach (LeapHand leapHand in handList)
            {
                DestroyHandComponents(leapHand);
            }
            handList.Clear();
        }
    }