コード例 #1
0
    // Process the skeleton data
    void ProcessSkeleton()
    {
        List <uint> lostUsers = new List <uint>();

        lostUsers.AddRange(allUsers);

        for (int i = 0; i < KinectWrapper.Constants.NuiSkeletonCount; i++)
        {
            KinectWrapper.NuiSkeletonData skeletonData = skeletonFrame.SkeletonData[i];
            uint userId = skeletonData.dwTrackingID;

            if (skeletonData.eTrackingState == KinectWrapper.NuiSkeletonTrackingState.SkeletonTracked)
            {
                if (!AllPlayersCalibrated)
                {
                    CalibrateUser(userId);
                }

                int stateNotTracked = (int)KinectWrapper.NuiSkeletonPositionTrackingState.NotTracked;

                if (userId == Player1ID)
                {
                    //Debug.Log("user yes:" + userId.ToString()); //Waterstrong
                    // get player position
                    player1Pos   = kinectToWorld.MultiplyPoint3x4(skeletonData.Position);
                    player1Pos.z = -player1Pos.z;

                    //Debug.Log(String.Format("({0}, {1}, {2})", player1Pos.x, player1Pos.y, player1Pos.z));
                    //CalibrationText.guiText.text = String.Format("({0:F1}, {1:F1}, {2:F1})", player1Pos.x, player1Pos.y, player1Pos.z);

                    // get joints rotation
                    for (int j = 0; j < (int)KinectWrapper.NuiSkeletonPositionIndex.Count; j++)
                    {
                        player1JointsTracked[j] = (int)skeletonData.eSkeletonPositionTrackingState[j] != stateNotTracked;

                        if (player1JointsTracked[j])
                        {
                            player1JointsPos[j]   = kinectToWorld.MultiplyPoint3x4(skeletonData.SkeletonPositions[j]);
                            player1JointsPos[j].z = -player1JointsPos[j].z;
                        }
                    }

                    // get joint orientations
                    KinectWrapper.GetSkeletonJointOrientation(ref player1JointsPos, ref player1JointsTracked, ref player1JointsOri);

                    // get player rotation
                    player1Ori = player1JointsOri[(int)KinectWrapper.NuiSkeletonPositionIndex.HipCenter];



                    // Waterstrong Add UI
                    //_adaptiveUi.SetUiCenter(player1JointsPos[(int)KinectWrapper.NuiSkeletonPositionIndex.Head], player1JointsPos[(int)KinectWrapper.NuiSkeletonPositionIndex.HandLeft], player1JointsPos[(int)KinectWrapper.NuiSkeletonPositionIndex.HandRight]);

                    // Waterstrong Add
                    FeatureData featureData = new FeatureData();
                    featureData.SetRelativeJoints(player1JointsPos);
                    MotionType mt = _motion.HandleDataEx(featureData);
                    switch (mt)
                    {
                    case MotionType.Jump:
                        Debug.Log("jump");
                        //SendMessage("DidJumpReachApex", SendMessageOptions.DontRequireReceiver);
                        break;

                    //case MotionType.Left:
                    //    Debug.Log("left");
                    //    break;
                    //case MotionType.Right:
                    //    Debug.Log("right");
                    //    break;
                    default: break;
                    }
                }
                else if (userId == Player2ID)
                {
                    // get player position
                    player2Pos   = kinectToWorld.MultiplyPoint3x4(skeletonData.Position);
                    player2Pos.z = -player2Pos.z;

                    // get joints rotation
                    for (int j = 0; j < (int)KinectWrapper.NuiSkeletonPositionIndex.Count; j++)
                    {
                        player2JointsTracked[j] = (int)skeletonData.eSkeletonPositionTrackingState[j] != stateNotTracked;

                        if (player2JointsTracked[j])
                        {
                            player2JointsPos[j]   = kinectToWorld.MultiplyPoint3x4(skeletonData.SkeletonPositions[j]);
                            player2JointsPos[j].z = -player2JointsPos[j].z;
                        }
                    }

                    // get joint orientations
                    KinectWrapper.GetSkeletonJointOrientation(ref player2JointsPos, ref player2JointsTracked, ref player2JointsOri);

                    // get player rotation
                    player2Ori = player2JointsOri[(int)KinectWrapper.NuiSkeletonPositionIndex.HipCenter];
                }

                lostUsers.Remove(userId);
            }
        }

        // remove the lost users if any
        if (lostUsers.Count > 0)
        {
            foreach (uint userId in lostUsers)
            {
                RemoveUser(userId);
            }

            lostUsers.Clear();
        }
    }
コード例 #2
0
    // Process the skeleton data
    void ProcessSkeleton()
    {
        List <uint> lostUsers = new List <uint>();

        lostUsers.AddRange(allUsers);

        for (int i = 0; i < KinectWrapper.Constants.NuiSkeletonCount; i++)
        {
            KinectWrapper.NuiSkeletonData skeletonData = skeletonFrame.SkeletonData[i];
            uint userId = skeletonData.dwTrackingID;

            if (skeletonData.eTrackingState == KinectWrapper.NuiSkeletonTrackingState.SkeletonTracked)
            {
                if (!AllPlayersCalibrated)
                {
                    CalibrateUser(userId);
                }

                //int stateNotTracked = (int)KinectWrapper.NuiSkeletonPositionTrackingState.NotTracked; // Waterstrong
                int stateTracked = (int)KinectWrapper.NuiSkeletonPositionTrackingState.Tracked;

                if (userId == Player1ID)
                {
                    // get player position
                    player1Pos   = kinectToWorld.MultiplyPoint3x4(skeletonData.Position);
                    player1Pos.z = -player1Pos.z;

                    //Debug.Log(String.Format("({0}, {1}, {2})", player1Pos.x, player1Pos.y, player1Pos.z));
                    //CalibrationText.guiText.text = String.Format("({0:F1}, {1:F1}, {2:F1})", player1Pos.x, player1Pos.y, player1Pos.z);

                    // get joints rotation
                    for (int j = 0; j < (int)KinectWrapper.NuiSkeletonPositionIndex.Count; j++)
                    {
                        //player1JointsTracked[j] = (int)skeletonData.eSkeletonPositionTrackingState[j] != stateNotTracked; // Waterstrong
                        player1JointsTracked[j] = (int)skeletonData.eSkeletonPositionTrackingState[j] == stateTracked;

                        if (player1JointsTracked[j])
                        {
                            player1JointsPos[j]   = kinectToWorld.MultiplyPoint3x4(skeletonData.SkeletonPositions[j]);
                            player1JointsPos[j].z = -player1JointsPos[j].z;
                        }
                    }

                    // get joint orientations
                    KinectWrapper.GetSkeletonJointOrientation(ref player1JointsPos, ref player1JointsTracked, ref player1JointsOri);

                    // get player rotation
                    player1Ori = player1JointsOri[(int)KinectWrapper.NuiSkeletonPositionIndex.HipCenter];
                }
                else if (userId == Player2ID)
                {
                    // get player position
                    player2Pos   = kinectToWorld.MultiplyPoint3x4(skeletonData.Position);
                    player2Pos.z = -player2Pos.z;

                    // get joints rotation
                    for (int j = 0; j < (int)KinectWrapper.NuiSkeletonPositionIndex.Count; j++)
                    {
                        //player2JointsTracked[j] = (int)skeletonData.eSkeletonPositionTrackingState[j] != stateNotTracked; // Waterstrong
                        player2JointsTracked[j] = (int)skeletonData.eSkeletonPositionTrackingState[j] == stateTracked;
                        if (player2JointsTracked[j])
                        {
                            player2JointsPos[j]   = kinectToWorld.MultiplyPoint3x4(skeletonData.SkeletonPositions[j]);
                            player2JointsPos[j].z = -player2JointsPos[j].z;
                        }
                    }

                    // get joint orientations
                    KinectWrapper.GetSkeletonJointOrientation(ref player2JointsPos, ref player2JointsTracked, ref player2JointsOri);

                    // get player rotation
                    player2Ori = player2JointsOri[(int)KinectWrapper.NuiSkeletonPositionIndex.HipCenter];
                }

                lostUsers.Remove(userId);
            }
        }

        // remove the lost users if any
        if (lostUsers.Count > 0)
        {
            foreach (uint userId in lostUsers)
            {
                RemoveUser(userId);
            }

            lostUsers.Clear();
        }
    }
コード例 #3
0
    // Process the skeleton data
    void ProcessSkeleton()
    {
        List <uint> lostUsers = new List <uint>();

        lostUsers.AddRange(allUsers);

        // calculate the time since last update
        float currentNuiTime = Time.realtimeSinceStartup;
        float deltaNuiTime   = currentNuiTime - lastNuiTime;

        for (int i = 0; i < KinectWrapper.Constants.NuiSkeletonCount; i++)
        {
            KinectWrapper.NuiSkeletonData skeletonData = skeletonFrame.SkeletonData[i];
            uint userId = skeletonData.dwTrackingID;

            if (skeletonData.eTrackingState == KinectWrapper.NuiSkeletonTrackingState.SkeletonTracked)
            {
                // get the skeleton position
                Vector3 skeletonPos = kinectToWorld.MultiplyPoint3x4(skeletonData.Position);

                if (!AllPlayersCalibrated)
                {
                    // check if this is the closest user
                    bool bClosestUser = true;

                    if (DetectClosestUser)
                    {
                        for (int j = 0; j < KinectWrapper.Constants.NuiSkeletonCount; j++)
                        {
                            if (j != i)
                            {
                                KinectWrapper.NuiSkeletonData skeletonDataOther = skeletonFrame.SkeletonData[j];

                                if ((skeletonDataOther.eTrackingState == KinectWrapper.NuiSkeletonTrackingState.SkeletonTracked) &&
                                    (Mathf.Abs(kinectToWorld.MultiplyPoint3x4(skeletonDataOther.Position).z) < Mathf.Abs(skeletonPos.z)))
                                {
                                    bClosestUser = false;
                                    break;
                                }
                            }
                        }
                    }

                    if (bClosestUser)
                    {
                        CalibrateUser(userId, i + 1, ref skeletonData);
                    }
                }

                if (userId == Player1ID && Mathf.Abs(skeletonPos.z) >= MinUserDistance &&
                    (MaxUserDistance <= 0f || Mathf.Abs(skeletonPos.z) <= MaxUserDistance))
                {
                    player1Index = i;

                    // get player position
                    player1Pos = skeletonPos;

                    // apply tracking state filter first
                    trackingStateFilter[0].UpdateFilter(ref skeletonData);

                    if (UseSelfIntersectionConstraint && selfIntersectionConstraint != null)
                    {
                        selfIntersectionConstraint.Constrain(ref skeletonData);
                    }

                    // get joints' position and rotation
                    for (int j = 0; j < (int)KinectWrapper.NuiSkeletonPositionIndex.Count; j++)
                    {
                        bool playerTracked = IgnoreInferredJoints ? (int)skeletonData.eSkeletonPositionTrackingState[j] == stateTracked :
                                             (Array.BinarySearch(mustBeTrackedJoints, j) >= 0 ? (int)skeletonData.eSkeletonPositionTrackingState[j] == stateTracked :
                                              (int)skeletonData.eSkeletonPositionTrackingState[j] != stateNotTracked);
                        player1JointsTracked[j] = player1PrevTracked[j] && playerTracked;
                        player1PrevTracked[j]   = playerTracked;

                        if (player1JointsTracked[j])
                        {
                            player1JointsPos[j] = kinectToWorld.MultiplyPoint3x4(skeletonData.SkeletonPositions[j]);
                            //player1JointsOri[j] = jointOrients[j].absoluteRotation.rotationMatrix * flipMatrix;
                        }
                    }

                    // calculate joint orientations
                    KinectWrapper.GetSkeletonJointOrientation(ref player1JointsPos, ref player1JointsTracked, ref player1JointsOri);

                    // filter orientation constraints
                    if (UseBoneOrientationsConstraint && boneConstraintsFilter != null)
                    {
                        boneConstraintsFilter.Constrain(ref player1JointsOri, ref player1JointsTracked);
                    }

                    // filter joint orientations.
                    // it should be performed after all joint position modifications.
                    if (UseBoneOrientationsFilter && boneOrientationFilter[0] != null)
                    {
                        boneOrientationFilter[0].UpdateFilter(ref skeletonData, ref player1JointsOri);
                    }

                    // get player rotation
                    player1Ori = player1JointsOri[(int)KinectWrapper.NuiSkeletonPositionIndex.HipCenter];
                }

                lostUsers.Remove(userId);
            }
        }

        // update the nui-timer
        lastNuiTime = currentNuiTime;

        // remove the lost users if any
        if (lostUsers.Count > 0)
        {
            foreach (uint userId in lostUsers)
            {
                RemoveUser(userId);
            }

            lostUsers.Clear();
        }
    }
コード例 #4
0
ファイル: KinectManager.cs プロジェクト: Zakifull/DTU
    // Process the skeleton data
    void ProcessSkeleton()
    {
        List <uint> lostUsers = new List <uint>();

        lostUsers.AddRange(_allUsers);

        // calculate the time since last update
        float currentNuiTime = Time.realtimeSinceStartup;
        float deltaNuiTime   = currentNuiTime - _lastNuiTime;

        for (int i = 0; i < KinectWrapper.Constants.NuiSkeletonCount; i++)
        {
            KinectWrapper.NuiSkeletonData skeletonData = _skeletonFrame.SkeletonData[i];
            uint userId = skeletonData.dwTrackingID;

            if (skeletonData.eTrackingState == KinectWrapper.NuiSkeletonTrackingState.SkeletonTracked)
            {
                // get the skeleton position
                Vector3 skeletonPos = _kinectToWorld.MultiplyPoint3x4(skeletonData.Position);

                if (!_allPlayersCalibrated)
                {
                    // check if this is the closest user
                    bool bClosestUser = true;

                    if (DetectClosestUser)
                    {
                        for (int j = 0; j < KinectWrapper.Constants.NuiSkeletonCount; j++)
                        {
                            if (j != i)
                            {
                                KinectWrapper.NuiSkeletonData skeletonDataOther = _skeletonFrame.SkeletonData[j];

                                if ((skeletonDataOther.eTrackingState == KinectWrapper.NuiSkeletonTrackingState.SkeletonTracked) &&
                                    (Mathf.Abs(_kinectToWorld.MultiplyPoint3x4(skeletonDataOther.Position).z) < Mathf.Abs(skeletonPos.z)))
                                {
                                    bClosestUser = false;
                                    break;
                                }
                            }
                        }
                    }

                    if (bClosestUser)
                    {
                        CalibrateUser(userId, i + 1, ref skeletonData);
                    }
                }

                if (userId == _player1Id && Mathf.Abs(skeletonPos.z) >= MinUserDistance &&
                    (MaxUserDistance <= 0f || Mathf.Abs(skeletonPos.z) <= MaxUserDistance))
                {
                    _player1SkeletonIndex = i;

                    // get player position
                    _player1Pos = skeletonPos;


                    // get joints' position and rotation
                    for (int j = 0; j < (int)KinectWrapper.NuiSkeletonPositionIndex.Count; j++)
                    {
                        bool playerTracked = IgnoreInferredJoints ? (int)skeletonData.eSkeletonPositionTrackingState[j] == stateTracked :
                                             (Array.BinarySearch(mustBeTrackedJoints, j) >= 0 ? (int)skeletonData.eSkeletonPositionTrackingState[j] == stateTracked :
                                              (int)skeletonData.eSkeletonPositionTrackingState[j] != stateNotTracked);
                        _player1JointsTracked[j] = _player1PrevTracked[j] && playerTracked;
                        _player1PrevTracked[j]   = playerTracked;

                        if (_player1JointsTracked[j])
                        {
                            _player1JointsPos[j] = _kinectToWorld.MultiplyPoint3x4(skeletonData.SkeletonPositions[j]);
                        }
                    }

                    // calculate joint orientations
                    KinectWrapper.GetSkeletonJointOrientation(ref _player1JointsPos, ref _player1JointsTracked, ref _player1JointsOri);

                    // get player rotation
                    _player1Ori = _player1JointsOri[(int)KinectWrapper.NuiSkeletonPositionIndex.HipCenter];
                }
                else if (userId == _player2Id && Mathf.Abs(skeletonPos.z) >= MinUserDistance &&
                         (MaxUserDistance <= 0f || Mathf.Abs(skeletonPos.z) <= MaxUserDistance))
                {
                    _player2SkeletonIndex = i;

                    // get player position
                    _player2Pos = skeletonPos;

                    // get joints' position and rotation
                    for (int j = 0; j < (int)KinectWrapper.NuiSkeletonPositionIndex.Count; j++)
                    {
                        bool playerTracked = IgnoreInferredJoints ? (int)skeletonData.eSkeletonPositionTrackingState[j] == stateTracked :
                                             (Array.BinarySearch(mustBeTrackedJoints, j) >= 0 ? (int)skeletonData.eSkeletonPositionTrackingState[j] == stateTracked :
                                              (int)skeletonData.eSkeletonPositionTrackingState[j] != stateNotTracked);
                        _player2JointsTracked[j] = _player2PrevTracked[j] && playerTracked;
                        _player2PrevTracked[j]   = playerTracked;

                        if (_player2JointsTracked[j])
                        {
                            _player2JointsPos[j] = _kinectToWorld.MultiplyPoint3x4(skeletonData.SkeletonPositions[j]);
                        }
                    }

                    // calculate joint orientations
                    KinectWrapper.GetSkeletonJointOrientation(ref _player2JointsPos, ref _player2JointsTracked, ref _player2JointsOri);

                    // get player rotation
                    _player2Ori = _player2JointsOri[(int)KinectWrapper.NuiSkeletonPositionIndex.HipCenter];
                }

                lostUsers.Remove(userId);
            }
        }

        // update the nui-timer
        _lastNuiTime = currentNuiTime;

        // remove the lost users if any
        if (lostUsers.Count > 0)
        {
            foreach (uint userId in lostUsers)
            {
                RemoveUser(userId);
            }

            lostUsers.Clear();
        }
    }