コード例 #1
0
        void OnUserUpdate()
        {
            LookForNewUser();

            m_RemoveUserList.Clear();

            Dictionary <int, OrbbecUser> .Enumerator elem = TrackingUsers.GetEnumerator();
            while (elem.MoveNext())
            {
                OrbbecUser cur = elem.Current.Value;
                cur.Update();
                if (!cur.IsInConfidence())
                {
                    cur.UserID = 0;
                    --CurTrackingUserNum;
                    m_RemoveUserList.AddLast(elem.Current.Key);
                }
            }

            LinkedList <int> .Enumerator removeItem = m_RemoveUserList.GetEnumerator();
            while (removeItem.MoveNext())
            {
                TrackingUsers.Remove(removeItem.Current);
            }
        }
コード例 #2
0
        void LookForNewUser()
        {
            if (CurTrackingUserNum >= MaxTrackingUserNum)
            {
                return;
            }

            int[] UserArray = GetUserArray();

            for (int i = 0; i < UserArray.Length && CurTrackingUserNum < MaxTrackingUserNum; ++i)
            {
                int UserID = UserArray[i];
                if (!IsTrackingUser(UserID))
                {
                    continue;
                }

                if (TrackingUsers.ContainsKey(UserID))
                {
                    continue;
                }

                if (!IsRisingHands(UserID))
                {
                    continue;
                }

                OrbbecUser newUser = new OrbbecUser(UserID);
                TrackingUsers.Add(UserID, newUser);

                ++CurTrackingUserNum;
            }
        }
コード例 #3
0
        //获取新用户
        OrbbecUser GetNewUser()
        {
            OrbbecUser ret = null;

            if (userTable != null && userTable.Count > 0)
            {
                foreach (KeyValuePair <int, OrbbecUser> kv in userTable)
                {
                    tmpUser = kv.Value;

                    if (tmpUser == tplayer1.bindUser || tmpUser == tplayer2.bindUser)
                    {
                        continue;
                    }
                    else
                    {
                        if (OrbbecManager.Instance.IsRisingHands(tmpUser.UserID))
                        {
                            ret = tmpUser;
                            break;
                        }
                    }
                }
            }
            return(ret);
        }
コード例 #4
0
 //得到镜像 转 正常 的骨架信息 世界坐标
 public static Vector3 GetWorldPos(OrbbecUser user, SkeletonType skeletonType)
 {
     if (IsUserActive(user))
     {
         SkeletonType skeletonType2 = OrbbecUtils.GetFlipSkeletonType(skeletonType);
         Vector3      vec           = user.BoneWorldPos[jointToIntDict[skeletonType2]];
         return(vec);
     }
     return(Vector3.zero);
 }
コード例 #5
0
 //得到镜像 转 正常 的骨架的 屏幕百分比数据
 public static Vector3 GetScreenPercentPos(OrbbecUser user, SkeletonType skeletonType)
 {
     if (IsUserActive(user))
     {
         SkeletonType skeletonType2 = OrbbecUtils.GetFlipSkeletonType(skeletonType);
         Vector3      vec           = user.BoneScreenPos[jointToIntDict[skeletonType2]];
         vec = new Vector3(vec.x / depthSize.x, (depthSize.y - vec.y) / depthSize.y, 1f);
         return(vec);
     }
     return(Vector3.zero);
 }
コード例 #6
0
        //取消标定
        public void CancelTracking()
        {
            trackingState   = TrackingState.none;
            trackingTime    = 0f;
            trackingMissCnt = 0;
            _trackingBoneWorldPosDictList.Clear();
            _trackingBoneScreenPercentPosDictList.Clear();
            _trackingBoneWorldPosDict.Clear();
            _trackingBoneScreenPercentPosDict.Clear();

            bindUser = null;
        }
コード例 #7
0
        void OnUserEnter(int UserID)
        {
            if (CurTrackingUserNum >= MaxTrackingUserNum)
            {
                return;
            }

            OrbbecUser newUser = new OrbbecUser(UserID);

            TrackingUsers.Add(UserID, newUser);

            ++CurTrackingUserNum;
        }
コード例 #8
0
 public static bool IsUserActive(OrbbecUser user)
 {
     return((user != null) && (user.UserID != 0) && OrbbecManager.Instance.IsTrackingUser(user.UserID));
 }
コード例 #9
0
        //检测标定
        void TrackingPlayer(OrbbecPlayerOnTracking tplayer)
        {
            //未开始标定,获取新user,启动标定
            if (tplayer.trackingState == OrbbecPlayerOnTracking.TrackingState.none)
            {
                tmpUser = GetNewUser();
                if (tmpUser != null)
                {
                    tplayer.bindUser = tmpUser;
                    tplayer.StartTracking();
                }
            }
            //正在标定,判定是否失去焦点,有焦点则记录信息,失去焦点或不举手则取消标定
            else if (tplayer.trackingState == OrbbecPlayerOnTracking.TrackingState.tracking)
            {
                bool isMissing     = false;
                bool IsRisingHands = false;
                if (OrbbecUtils.IsUserActive(tplayer.bindUser))
                {
                    if (OrbbecManager.Instance.IsRisingHands(tplayer.UserId))
                    {
                        IsRisingHands = true;
                    }
                    else
                    {
                        //允许中途连续丢失3帧举手
                        tplayer.trackingMissCnt++;
                        if (tplayer.trackingMissCnt >= allowTrackingMissCnt)
                        {
                            isMissing = true;
                        }
                    }
                }
                else
                {
                    isMissing = true;
                }

                if (!isMissing)
                {
                    if (IsRisingHands)
                    {
                        tplayer.UpdateTracking(Time.unscaledDeltaTime);                         //lth: 使用unscaledTime以适应游戏中暂停
                        if (tplayer.trackingTime >= needTrackingTime)
                        {
                            tplayer.FinishTracking();
                        }
                    }
                }
                else
                {
                    tplayer.CancelTracking();
                }
            }
            else if (tplayer.trackingState == OrbbecPlayerOnTracking.TrackingState.tracked)
            {
                bool isMissing = false;
                if (!OrbbecUtils.IsUserActive(tplayer.bindUser))
                {
                    isMissing = true;
                }

                if (isMissing)
                {
                    tplayer.CancelTracking();
                }
            }
        }