Beispiel #1
0
        /// @brief initializes the class with a new user.
        /// 
        /// initializes the class with a new user (The class is invalid (m_uniqueID<0) until this is done successfully)
        /// @param usersGenerator the users generator which holds the users.
        /// @param uniqueID the uniqueID of the user we should initialize to.
        /// @return true on success and false on failure (making the object invalid, i.e. m_uniqueID<0).
        public bool InitInternalSkeleton(NIUserAndSkeleton usersGenerator, int uniqueID)
        {
            m_uniqueID = -1; // to make sure we are invalid until we are sure we are valid.
            if (usersGenerator.Valid == false)
                return false; // must have a valid users generator to do anything
            m_userID = usersGenerator.GetNIUserId(uniqueID);
            if (m_userID < 0)
                return false; // means the uniqueID was illegal
            if (usersGenerator.GetUserCalibrationState(m_userID) != NIUserAndSkeleton.CalibrationState.calibrated)
                return false; // we only initialize calibrated users as we need the skeleton.           
            int numJoints = 0; // holds the place to position the next joint.
            foreach (SkeletonJoint joint in Enum.GetValues(typeof(SkeletonJoint)))
            {
                if (usersGenerator.Skeleton.IsJointAvailable(joint)==false)
                    continue; // an irrelevant joint.
                // we need to add the joint but we don't want to create a new one unless we need to.
                if (numJoints < m_jointsIDs.Count)
                {
                    m_jointsIDs[numJoints] = joint;
                }
                else
                {
                    m_jointsIDs.Add(joint);
                }

                // we need to add the joint transformation but we don't want to create a new one unless we need to.
                if(numJoints<m_jointsTrans.Count)
                {
                    m_jointsTrans[numJoints]=usersGenerator.Skeleton.GetSkeletonJoint(m_userID, joint);
                }
                else
                {
                    SkeletonJointTransformation skelTrans = usersGenerator.Skeleton.GetSkeletonJoint(m_userID, joint);
                    m_jointsTrans.Add(skelTrans);
                }
                numJoints++;
            }
            if (numJoints < m_jointsIDs.Count)
            {
                for (; numJoints < m_jointsIDs.Count; numJoints++)
                    m_jointsIDs[numJoints] = SkeletonJoint.Invalid;
            }
            m_uniqueID = uniqueID;
            return true;
        }