コード例 #1
0
        void UpdateHandRepresentations(Dictionary <int, HandRepresentation> all_hand_reps, ModelType modelType)
        {
            foreach (Leap.Hand curHand in Provider.CurrentFrame.Hands)
            {
                HandRepresentation rep;
                if (!all_hand_reps.TryGetValue(curHand.Id, out rep))
                {
                    rep = Factory.MakeHandRepresentation(curHand, modelType);
                    if (rep != null)
                    {
                        all_hand_reps.Add(curHand.Id, rep);
                        //float hand_scale = curHand.PalmWidth / rep.handModel.handModelPalmWidth;
                        //rep.handModel.transform.localScale = hand_scale * Vector3.one;
                    }
                }
                if (rep != null)
                {
                    rep.IsMarked = true;
                    //float hand_scale = curHand.PalmWidth / rep.handModel.handModelPalmWidth;
                    //rep.handModel.transform.localScale = hand_scale * Vector3.one;
                    rep.UpdateRepresentation(curHand, modelType);
                    rep.LastUpdatedTime = (int)Provider.CurrentFrame.Timestamp;

                    //Leap.Vector objPos = curHand.PalmPosition;
                    //Vector3 unityPos = objPos.ToUnityScaled();
                    //Vector3 worldPos = this.transform.TransformPoint(unityPos);
                    //Debug.Log(worldPos);

                    HandDistinguisher(curHand);
                }
            }

            //Mark-and-sweep or set difference implementation
            HandRepresentation toBeDeleted = null;

            foreach (KeyValuePair <int, HandRepresentation> r in all_hand_reps)
            {
                if (r.Value != null)
                {
                    if (r.Value.IsMarked)
                    {
                        //Debug.Log("LeapHandController Marking False");
                        r.Value.IsMarked = false;
                    }
                    else
                    {
                        //Initialize toBeDeleted with a value to be deleted
                        //Debug.Log("Finishing");
                        toBeDeleted = r.Value;
                    }
                }
            }
            //Inform the representation that we will no longer be giving it any hand updates
            //because the corresponding hand has gone away
            if (toBeDeleted != null)
            {
                all_hand_reps.Remove(toBeDeleted.HandID);
                toBeDeleted.Finish();
            }
        }
コード例 #2
0
        /**
         * Updates HandRepresentations based in the specified HandRepresentation Dictionary.
         * Active HandRepresentation instances are updated if the hand they represent is still
         * present in the Provider's CurrentFrame; otherwise, the HandRepresentation is removed. If new
         * Leap Hand objects are present in the Leap HandRepresentation Dictionary, new HandRepresentations are
         * created and added to the dictionary.
         */
        void UpdateHandRepresentations(Dictionary <int, HandRepresentation> all_hand_reps, ModelType modelType)
        {
            foreach (Leap.Hand curHand in Provider.CurrentFrame.Hands)
            {
                HandRepresentation rep;
                if (!all_hand_reps.TryGetValue(curHand.Id, out rep))
                {
                    rep = Factory.MakeHandRepresentation(curHand, modelType);
                    if (rep != null)
                    {
                        all_hand_reps.Add(curHand.Id, rep);
                    }
                }
                if (rep != null)
                {
                    rep.IsMarked = true;
                    rep.UpdateRepresentation(curHand, modelType);
                    rep.LastUpdatedTime = (int)Provider.CurrentFrame.Timestamp;
                }
            }

            //Mark-and-sweep to finish unused HandRepresentations
            HandRepresentation toBeDeleted = null;

            foreach (KeyValuePair <int, HandRepresentation> r in all_hand_reps)
            {
                if (r.Value != null)
                {
                    if (r.Value.IsMarked)
                    {
                        r.Value.IsMarked = false;
                    }
                    else
                    {
                        //Initialize toBeDeleted with a value to be deleted
                        //Debug.Log("Finishing");
                        toBeDeleted = r.Value;
                    }
                }
            }
            //Inform the representation that we will no longer be giving it any hand updates
            //because the corresponding hand has gone away
            if (toBeDeleted != null)
            {
                all_hand_reps.Remove(toBeDeleted.HandID);
                toBeDeleted.Finish();
            }
        }