コード例 #1
0
        void Update()
        {
            //Grab the newest data from the parser
            DataPoint newdata = Parser.grabData();

            //If some new data is present, modify our distances as needed - otherwise ignore
            if (newdata != null)
            {
                //Debug.Log("Non-null data found with tags "+newdata.getFirstId()+" and "+newdata.getSecondId());
                //One of the two tags should be the tracked object
                if (newdata.getFirstId() != TAG_ID && newdata.getSecondId() != TAG_ID)
                {
                    return;
                }
                //The other tag should be an anchor - find which anchor, and set its distance
                for (int i = 0; i < ancs.Length; i++)
                {
                    if (newdata.getFirstId() == ancs[i].id || newdata.getSecondId() == ancs[i].id)
                    {
                        ancs[i].setDist(newdata.getDistance());
                        break;
                    }
                }
            }
            //Run one lateration step (handles lack of new data inside)
            runStep();
        }
コード例 #2
0
        void Update()
        {
            //Grab the newest data from the parser
            DataPoint newdata = Parser.grabData();

            //If some new data is present, modify our distances as needed - otherwise ignore
            if (newdata != null)
            {
                /*//Debug.Log("Non-null data found with tags "+newdata.getFirstId()+" and "+newdata.getSecondId());
                 * //One of the two tags should be the tracked object
                 * if(newdata.getFirstId() != TAG_ID && newdata.getSecondId() != TAG_ID){
                 *      return;
                 * }
                 * //The other tag should be an anchor - find which anchor, and set its distance
                 * for(int i=0;i<rangers.Length;i++){
                 *      if(newdata.getFirstId() == rangers[i].id || newdata.getSecondId() == rangers[i].id){
                 *              rangers[i].setDist(newdata.getDistance());
                 *              break;
                 *      }
                 * }*/
                Ranger firstRanger  = null;
                Ranger secondRanger = null;
                foreach (Ranger ranger in rangers)
                {
                    if (ranger.ID == newdata.getFirstId())
                    {
                        firstRanger = ranger;
                    }
                    else if (ranger.ID == newdata.getSecondId())
                    {
                        secondRanger = ranger;
                    }
                }
                if (firstRanger != null && secondRanger != null)
                {
                    if (firstRanger.anchor && secondRanger.anchor)
                    {
                        firstRanger.setDist(newdata.getSecondId(), newdata.getDistance(), true);
                        secondRanger.setDist(newdata.getFirstId(), newdata.getDistance(), true);
                    }
                    else
                    {
                        if (!firstRanger.anchor)
                        {
                            firstRanger.setDist(newdata.getSecondId(), newdata.getDistance(), false);
                        }
                        if (!secondRanger.anchor)
                        {
                            secondRanger.setDist(newdata.getFirstId(), newdata.getDistance(), false);
                        }
                    }
                }
            }
            //Run one lateration step (handles lack of new data inside)
            runStep();
        }