예제 #1
0
	/// mono-behavior update (called once per frame)
	public void Update () 
    {
        if (m_contextManager.Valid == false || m_contextManager.UserSkeletonValid == false)
            return; // we can do nothing.
        // we go over all existing players and make sure they are still legal. 
        // If it is illegal (i.e. the user no longer exists) we mark it as such.
        // when this loop finishes m_players will have only legal players
        foreach (InternalSkeleton player in m_players)
        {
            if(player.UniqueID<0)
                continue; // already illegal
            int userID = m_contextManager.UserGenrator.GetNIUserId(player.UniqueID);
            if (userID < 0 || userID != player.UserID)
            {
                Debug.Log("Lose one");
                player.UniqueID = -1; // invalidate!
            }
        }
        // now we need to make sure all users are translated to players. We will go over all users
        // in the user generator and try to make sure we have a player for them.
        
        // get the list of users
        IList<int> userList=m_contextManager.UserGenrator.Users;

        // for each user we try to find if it is already in (i.e. valid) and if not we will position it
        foreach (int uniqueID in userList)
        {
            if(uniqueID<0)
                continue; // an invalid user
            InternalSkeleton playerToAdd=null; // holds the first free player (this is where we will add the new user if it does not exist)
            bool foundUser=false; // will be changed to true if we find the user in the player list
            foreach (InternalSkeleton player in m_players)
            {
                if (player.UniqueID == uniqueID)
                {
                    foundUser = true;
                    break;
                }
                if (playerToAdd == null && player.UniqueID < 0)
                    playerToAdd = player;
            }
            if(foundUser)
                continue; // the user exists, no need to do anything.
            if (playerToAdd == null)
            {
                playerToAdd = m_nextSkeleton;
                // note InternalSkeleton is a class so we can change it directly
                if (playerToAdd.InitInternalSkeleton(m_contextManager.UserGenrator, uniqueID))
                {
                    Debug.Log("adding a new player. Count=" + m_players.Count);
                    m_players.Add(playerToAdd);
                    m_nextSkeleton = new InternalSkeleton();
                }
            }
            else playerToAdd.InitInternalSkeleton(m_contextManager.UserGenrator, uniqueID);
        }
    }
예제 #2
0
 /// recalculates the initial transforms of all joints. This should be done when some (or all)
 /// initial transforms are irrelevant (e.g. the initial calibration had no leg information but
 /// we want them so we will recalc everything accordingly).
 /// @param playerID a running number of the player ID (player 1 is 0, player 2 is 1 etc.)
 public void RecalcAllInitialTransforms(int playerID)
 {
     if (playerID < 0 || playerID >= m_players.Count)
         return; // no such player
     InternalSkeleton player = m_players[playerID];
     if (player.UniqueID < 0)
         return; // no info for the player
     m_players[playerID].InitInternalSkeleton(m_contextManager.UserGenrator, player.UniqueID);
 }
예제 #3
0
 /// returns the skeleton transformation that was set when the user was initially added to the list
 /// of users for a specific joint.
 /// @param playerID a running number of the player ID (player 1 is 0, player 2 is 1 etc.)
 /// @param joint the joint we want the transform of this.
 /// @param[out] skelTransform the skeleton transformation
 /// @return will return true if we found the joint for that player and false otherwise.
 public bool GetJointInitialTransform(int playerID, SkeletonJoint joint, out SkeletonJointTransformation skelTransform)
 {
     skelTransform = m_internalTransformation;
     if (playerID < 0 || playerID >= m_players.Count)
         return false;
     InternalSkeleton player=m_players[playerID];
     if (player.UniqueID < 0)
         return false;
     List<SkeletonJoint> jointList = player.JointsIDs;
     if (jointList == null)
         return false; // no joint!
     for (int i = 0; i < jointList.Count; i++)
     {
         if (jointList[i] == joint)
         {
             skelTransform = player.JointTransforms[i];
             return true;
         }
     }
     return false;
 }