示例#1
0
        /// <summary>
        /// 记录关节信息
        /// </summary>
        /// <param name="jointType"></param>
        /// <param name="Dir"></param>
        public void SetPlayerGestureJointData(GestureType gestureType, KinectInterop.JointType jointType, _Vector3 Dir)
        {
            PlayerGestureJointData playerGestureJoints = new PlayerGestureJointData();

            playerGestureJoints.direction = Dir;
            playerGestureJoints.jointType = jointType;

            switch (gestureType)
            {
            case GestureType.End:
                if (EndJointDirection.ContainsKey(jointType))
                {
                    EndJointDirection[jointType] = playerGestureJoints;
                }
                else
                {
                    EndJointDirection.Add(jointType, playerGestureJoints);
                }
                break;

            case GestureType.Start:
                if (StartJointDirection.ContainsKey(jointType))
                {
                    StartJointDirection[jointType] = playerGestureJoints;
                }
                else
                {
                    StartJointDirection.Add(jointType, playerGestureJoints);
                }
                break;

            default:
                break;
            }
        }
示例#2
0
        /// <summary>
        /// 获取关节信息
        /// </summary>
        /// <returns></returns>
        public PlayerGestureJointData GetPlayerGestureJointData(GestureType gestureType, KinectInterop.JointType jointType)
        {
            PlayerGestureJointData playerGestureJoints = new PlayerGestureJointData();

            if (EndJointDirection.ContainsKey(jointType))
            {
                switch (gestureType)
                {
                case GestureType.End:
                    if (EndJointDirection.ContainsKey(jointType))
                    {
                        playerGestureJoints = EndJointDirection[jointType];
                    }
                    break;

                case GestureType.Start:
                    if (StartJointDirection.ContainsKey(jointType))
                    {
                        playerGestureJoints = StartJointDirection[jointType];
                    }
                    break;

                default:
                    break;
                }
            }

            return(playerGestureJoints);
        }
示例#3
0
        private int GetJointPos(GestureJudgeData gestureJudge, PlayerGestureData playerGestureData, KinectInterop.JointType[] jointTypes)
        {
            for (int i = 0; i < jointTypes.Length; i++)
            {
                if (!KinectManager.Instance.IsInitialized())
                {
                    return(0);
                }
            }
            gesturesValue.Clear();
            for (int i = 0; i < 2; i++)
            {
                Vector3 pos1 = KINECTManager.Instance.GetUserIDJointPos(userID, jointTypes[i], Camera.main, new Rect(0, 0, 1920, 1080));     //实时关节位置
                Vector3 pos2 = KINECTManager.Instance.GetUserIDJointPos(userID, jointTypes[i + 1], Camera.main, new Rect(0, 0, 1920, 1080)); //实时关节位置

                _Vector3 dir = new _Vector3((pos2 - pos1).normalized);

                PlayerGestureJointData EndPlayerGestures = playerGestureData.playerGestureInfo.GetPlayerGestureJointData(
                    PlayerGestureInfo.GestureType.End, jointTypes[i]);                                                     //获取本地储存结束的关节数据
                PlayerGestureJointData StartPlayerGestures = playerGestureData.playerGestureInfo.GetPlayerGestureJointData(
                    PlayerGestureInfo.GestureType.Start, jointTypes[i]);                                                   //获取本地储存开始的关节数据

                float EndAngle   = Vector3.Angle(EndPlayerGestures.direction.Get(), dir.Get());
                float StartAngle = Vector3.Angle(StartPlayerGestures.direction.Get(), dir.Get());

                if (EndAngle <= playerGestureData.playerGestureInfo.offset)
                {
                    gesturesValue.Add(2);
                }
                else if (StartAngle <= playerGestureData.playerGestureInfo.offset)
                {
                    gesturesValue.Add(1);
                }
                else
                {
                    gesturesValue.Add(0);
                }
            }

            if (!gesturesValue.Contains(0) && !gesturesValue.Contains(1))
            {
                return(2);
            }
            else if (!gesturesValue.Contains(0) && !gesturesValue.Contains(2))
            {
                return(1);
            }
            else
            {
                return(0);
            }
        }