Esempio n. 1
0
        public static void DetectarCentroPalma(IList <Point> contour, IList <PointF> candidates)
        {
            double[] distances = new double[candidates.Count];

            Parallel.For(0, candidates.Count, (index) =>
            {
                distances[index] = FindMaxDistance(contour, candidates[index]);
            });

            double maxDistance = result == null ? 0 : result.DistanceToContour;
            int    maxIndex    = -1;

            for (int index = 0; index < distances.Length; index++)
            {
                if (distances[index] > maxDistance)
                {
                    maxDistance = distances[index];
                    maxIndex    = index;
                }
            }
            if (maxIndex >= 0)
            {
                result = new Palm(candidates[maxIndex], maxDistance);
            }
        }
Esempio n. 2
0
        public static double FindMaxDistance(IList <Point> contourPoints, PointF candidate)
        {
            double result = double.MaxValue;

            foreach (var point in contourPoints)
            {
                result = Math.Min(PointFunctions.Distance(point.X, point.Y, candidate.X, candidate.Y), result);
            }
            return(result);
        }
Esempio n. 3
0
    // Update is called once per frame
    void Update()
    {
        Hand[] hands = Meta.Hands.GetHands();

        //Debug.Log (hands + ":" + hands.Length);

        if (hands.Length > 0)
        {
            Hand left = Meta.Hands.left;
            //Debug.Log(right);
            if (left != null && left.isValid)
            {
                Palm    lp       = left.palm;
                Vector3 position = lp.position;

                //Debug.Log(right.handOpenness);
                //position.y = 0;

                transform.position = position;

                float angle = Mathf.Atan2(position.z, position.x);

                if (position.y < -0.05)
                {
                    t.GetComponent <PitchTextUpdate>().Back(position.y);
                    gameObject.GetComponent <SocketIOComponent>().Emit("backwards");

                    //t.Fall();
                    //GameObject.Find ("MGUI.Canvas/MGUI.Text").guiText.text = "JJJ";
                    //GameObject.Find ("MGUI.Canvas/MGUI.Text").guiText.GetComponent<TextUpdate>().Fall();
                }
                else if (position.y > 0.01)
                {
                    t.GetComponent <PitchTextUpdate>().Forwards(position.y);
                    gameObject.GetComponent <SocketIOComponent>().Emit("forwards");
                    //t.Rise();
                }
                else
                {
                    t.GetComponent <PitchTextUpdate>().Middle();
                }
                //Debug.Log (angle * 180 / Mathf.PI);
                if (position.x < 0)
                {
                    angle *= -1;
                }

                //gameObject.GetComponent<SocketIOComponent>()
            }
            else               //hand not on screen
            {
                t.GetComponent <PitchTextUpdate>().Err();
            }
        }
    }
Esempio n. 4
0
    // Update is called once per frame
    void Update()
    {
        Hand[] hands = Meta.Hands.GetHands();

        //Debug.Log (hands + ":" + hands.Length);

        if (hands.Length > 0)
        {
            Hand right = Meta.Hands.right;
            //Debug.Log(right);
            if (right != null && right.isValid)
            {
                Palm    rp       = right.palm;
                Vector3 position = rp.position;

                //Debug.Log(right.handOpenness);
                //position.y = 0;
                transform.position = position;

                //t.GetComponent<YawTextUpdate>().Set(position.x);
                if (position.x > 0.05)
                {
                    t.GetComponent <YawTextUpdate>().Right(position.x);
                    gameObject.GetComponent <SocketIOComponent>().Emit("right");
                }
                else if (position.x < -0.05)
                {
                    t.GetComponent <YawTextUpdate>().Left(position.x);
                    gameObject.GetComponent <SocketIOComponent>().Emit("left");
                }
                else
                {
                    t.GetComponent <YawTextUpdate>().Middle();
                }

                //Debug.Log (angle * 180 / Mathf.PI);

                //gameObject.GetComponent<SocketIOComponent>()
            }
            else               //hand not on screen
            {
                t.GetComponent <YawTextUpdate>().Err();
            }
        }

        hands = Meta.Hands.GetHands();
        if (hands.Length == 2 && Meta.Hands.left.isValid && Meta.Hands.right.isValid)          //all hands present and accounted for
        {
            if (Meta.Hands.left.handOpenness > 30 && Meta.Hands.right.handOpenness > 30)       //gotta kill it!
            {
                gameObject.GetComponent <SocketIOComponent>().Emit("kill");
            }
        }
    }
Esempio n. 5
0
    // Use this for initialization
    void Start()
    {
        PipeClient client = new PipeClient();

        client.StartClient();

        a = new ReadFile();
        a.readFile(client.File_name);
        //a.readFile(@"E:\TestForUnity.csv");

        isPaused  = false;
        isStopped = false;

        lfScript = this.GetComponentInChildren <LittleFinger>();
        lfScript.Set(a.getPoints("mp_lf"), a.getPoints("mn_lf"), a.getPoints("ppn_lf"), a.getPoints("ipn_lf"), a.getPoints("dpn_lf"));

        mfScript = this.GetComponentInChildren <MiddleFinger>();
        mfScript.Set(a.getPoints("mp_mf"), a.getPoints("mn_mf"), a.getPoints("ppn_mf"), a.getPoints("ipn_mf"), a.getPoints("dpn_mf"));

        rfScript = this.GetComponentInChildren <RingFinger>();
        rfScript.Set(a.getPoints("mp_rf"), a.getPoints("mn_rf"), a.getPoints("ppn_rf"), a.getPoints("ipn_rf"), a.getPoints("dpn_rf"));

        ifScript = this.GetComponentInChildren <IndexFinger>();
        ifScript.Set(a.getPoints("mp_if"), a.getPoints("mn_if"), a.getPoints("ppn_if"), a.getPoints("ipn_if"), a.getPoints("dpn_if"));

        tScript = this.GetComponentInChildren <Thumb>();
        tScript.Set(a.getPoints("mn_t"), a.getPoints("ppn_t"), a.getPoints("ipn_t"), a.getPoints("dpn_t"));

        pScript = this.GetComponentInChildren <Palm>();
        pScript.Set(a.getPoints("mp_rf"), a.getPoints("mn_rf"), a.getPoints("mp_mf"), a.getPoints("mn_mf"));

        //lfScript.client = client;

        tScript.setNextFrame(nextFrame);
        lfScript.setNextFrame(nextFrame);
        mfScript.setNextFrame(nextFrame);
        rfScript.setNextFrame(nextFrame);
        ifScript.setNextFrame(nextFrame);
        pScript.setNextFrame(nextFrame);
    }
Esempio n. 6
0
        public static void Run()
        {
            var forearm = new Forearm()
            {
                Description = "Forearm"
            };
            var palm = new Palm()
            {
                Description = "Palm"
            };

            forearm.AddChildren(palm);
            for (int i = 0; i < 5; i++)
            {
                palm.AddChildren(CreateFinger(i));
            }

            Console.Write(forearm.GetStruct());

            Finger CreateFinger(int fingerIndex)
            {
                var finger = new Finger()
                {
                    Description = $"Finger_{fingerIndex}"
                };

                for (int i = 0; i < 3; i++)
                {
                    finger.AddChildren(new Falange()
                    {
                        Description = $"Falange_{i} for {finger.Description}"
                    });
                }
                return(finger);
            }
        }
Esempio n. 7
0
 void Awake()
 {
     hand = transform.root.GetComponent <Palm> ();
 }
Esempio n. 8
0
    // Update is called once per frame
    void Update()
    {
        Hand[] hands = Meta.Hands.GetHands();

        //Debug.Log (hands + ":" + hands.Length);

        if (hands.Length > 0)
        {
            Hand right = Meta.Hands.right;
            //Debug.Log(right);
            if (right != null && right.isValid)
            {
                Palm    rp       = right.palm;
                Vector3 position = rp.position;

                //Debug.Log(right.handOpenness);
                //position.y = 0;
                transform.position = position;

                float angle = Mathf.Atan2(position.z, position.x);

                if (position.y < -0.05)
                {
                    t.GetComponent <TextUpdate>().Fall(position.y);
                    gameObject.GetComponent <SocketIOComponent>().Emit("fall");

                    //t.Fall();
                    //GameObject.Find ("MGUI.Canvas/MGUI.Text").guiText.text = "JJJ";
                    //GameObject.Find ("MGUI.Canvas/MGUI.Text").guiText.GetComponent<TextUpdate>().Fall();
                }
                else if (position.y > 0.01)
                {
                    t.GetComponent <TextUpdate>().Rise(position.y);
                    gameObject.GetComponent <SocketIOComponent>().Emit("rise");
                    //t.Rise();
                }
                else
                {
                    t.GetComponent <TextUpdate>().Middle();
                }
                //Debug.Log (angle * 180 / Mathf.PI);
                if (position.x < 0)
                {
                    angle *= -1;
                }

                //gameObject.GetComponent<SocketIOComponent>()
            }
            else               //hand not on screen
            {
                t.GetComponent <TextUpdate>().Err();
            }
        }

        hands = Meta.Hands.GetHands();
        if (hands.Length == 2 && Meta.Hands.left.isValid && Meta.Hands.right.isValid)          //all hands present and accounted for
        {
            if (Meta.Hands.left.handOpenness > 30 && Meta.Hands.right.handOpenness > 30)       //gotta kill it!
            {
                gameObject.GetComponent <SocketIOComponent>().Emit("kill");
            }
        }
    }
Esempio n. 9
0
    public Hand(string type, Vector3 pos)
    {
        _palm   = new Palm(type, pos);
        _thumb  = new Phalanx[2];
        _index  = new Phalanx[3];
        _middle = new Phalanx[3];
        _ring   = new Phalanx[3];
        _little = new Phalanx[3];

        var dir = 0;

        if (type == "left")
        {
            dir = 1;
        }
        else if (type == "right")
        {
            dir = -1;
        }

        for (var i = 0; i < _thumb.Length; ++i)
        {
            var name       = "thumb" + (i + 1);
            var phalanxPos = new Vector3(0, 0, 1);
            var parent     = _palm.Body;
            if (i == 0)
            {
                phalanxPos += _palm.LocalFingerPoints[0] + new Vector3(dir * 0.5f, 0, -0.5f);
            }
            else
            {
                parent = _thumb[i - 1].Body;
            }
            _thumb[i] = new Phalanx(type, name, phalanxPos, parent);
        }
        for (var i = 0; i < _index.Length; ++i)
        {
            var name       = "index" + (i + 1);
            var phalanxPos = new Vector3(0, 0, 1);
            var parent     = _palm.Body;
            if (i == 0)
            {
                phalanxPos += _palm.LocalFingerPoints[1] + new Vector3(0, 0, -0.5f);
            }
            else
            {
                parent = _index[i - 1].Body;
            }
            _index[i] = new Phalanx(type, name, phalanxPos, parent);
        }
        for (var i = 0; i < _middle.Length; ++i)
        {
            var name       = "middle" + (i + 1);
            var phalanxPos = new Vector3(0, 0, 1);
            var parent     = _palm.Body;
            if (i == 0)
            {
                phalanxPos += _palm.LocalFingerPoints[2] + new Vector3(0, 0, -0.5f);
            }
            else
            {
                parent = _middle[i - 1].Body;
            }
            _middle[i] = new Phalanx(type, name, phalanxPos, parent);
        }
        for (var i = 0; i < _ring.Length; ++i)
        {
            var name       = "ring" + (i + 1);
            var phalanxPos = new Vector3(0, 0, 1);
            var parent     = _palm.Body;
            if (i == 0)
            {
                phalanxPos += _palm.LocalFingerPoints[3] + new Vector3(0, 0, -0.5f);
            }
            else
            {
                parent = _ring[i - 1].Body;
            }
            _ring[i] = new Phalanx(type, name, phalanxPos, parent);
        }
        for (var i = 0; i < _little.Length; ++i)
        {
            var name       = "little" + (i + 1);
            var phalanxPos = new Vector3(0, 0, 1);
            var parent     = _palm.Body;
            if (i == 0)
            {
                phalanxPos += _palm.LocalFingerPoints[4] + new Vector3(0, 0, -0.5f);
            }
            else
            {
                parent = _little[i - 1].Body;
            }
            _little[i] = new Phalanx(type, name, phalanxPos, parent);
        }

        var parentArray = new[]
        {
            _thumb[1], _index[2], _index[0], _middle[2], _middle[0], _little[2], _little[0], _ring[2], _ring[0]
        };

        _pressure = new GameObject[12];
        for (var i = 0; i < _pressure.Length; ++i)
        {
            _pressure[i]      = GameObject.CreatePrimitive(PrimitiveType.Quad);
            _pressure[i].name = "P" + (i + 1);
            if (i < parentArray.Length)
            {
                _pressure[i].transform.parent        = parentArray[i].Body.transform;
                _pressure[i].transform.localPosition = new Vector3(0, -0.4001f, 0);
                _pressure[i].transform.localScale    = new Vector3(0.6f, 0.6f, 1);
            }
            else
            {
                _pressure[i].transform.parent     = _palm.Body.transform;
                _pressure[i].transform.localScale = new Vector3(1.8f, 1.8f, 1);
            }
            _pressure[i].transform.localEulerAngles = new Vector3(-90, -90, 0);
        }
        _pressure[9].transform.localPosition  = new Vector3(dir * 1, -0.4001f, -1);
        _pressure[10].transform.localPosition = new Vector3(dir * 1, -0.4001f, 1);
        _pressure[11].transform.localPosition = new Vector3(dir * -1, -0.4001f, 1);
    }
Esempio n. 10
0
 public Listener()
 {
     palm        = new Palm();
     handStopped = false;
     bounder     = new InteractionBox();
 }
Esempio n. 11
0
        public void AllocateMeritBadges()
        {
            foreach (MeritBadge badge in MeritBadges.OrderBy(mb => mb.DateEarned).ThenBy(mb => mb.Name))
            {
                bool added = false;
                if (!Star.MbReq.Earned)
                {
                    added = Star.MbReq.Add(badge);
                }
                if (!added && !Life.MbReq.Earned)
                {
                    added = Life.MbReq.Add(badge);
                }
                if (!added && !Star.MbReq.Earned)
                {
                    added = Star.MbReq.AddAny(badge);
                }
                if (!added && !Life.MbReq.Earned)
                {
                    added = Life.MbReq.AddAny(badge);
                }

                bool eagleAdded = false;
                if (!Eagle.MbReq.Earned)
                {
                    eagleAdded = Eagle.MbReq.Add(badge);
                }

                if (!added && !eagleAdded)
                {
                    Palm.PalmType lastPalm = Palm.PalmType.None;
                    foreach (Palm palm in EaglePalms)
                    {
                        lastPalm = palm.Type;
                        if (!added && !palm.MbReq.Earned)
                        {
                            added = palm.MbReq.AddAny(badge);
                        }
                    }
                    if (!added)
                    {
                        Palm.PalmType nextType = Palm.PalmType.None;
                        switch (lastPalm)
                        {
                        case Palm.PalmType.None:
                        case Palm.PalmType.Silver:
                            nextType = Palm.PalmType.Bronze;
                            break;

                        case Palm.PalmType.Bronze:
                            nextType = Palm.PalmType.Gold;
                            break;

                        case Palm.PalmType.Gold:
                            nextType = Palm.PalmType.Silver;
                            break;
                        }
                        var newPalm = new Palm(nextType);
                        added = newPalm.MbReq.AddAny(badge);
                        EaglePalms.Add(newPalm);
                    }
                }
            }
        }