public SkeletonTrackerData()
 {
     const int jointsNumber = (int)DataConverter.JointType.NumberOfJoints;
     _jointData = new JointData[jointsNumber];
     for (int i = 0; i < jointsNumber; i++)
     {
         _jointData[i] = new JointData();
         _jointData[i].JointId = (DataConverter.JointType)i;
     }
 }
        /// <summary>
        /// Decodes the skeleton data received from the data stream into joint positions.
        /// </summary>
        public static void DecodeSkeletonData(string data, JointData[] jointsData)
        {

            //Console.WriteLine(Converter.EncodeInfo("DecodeSkeletonData in operation..."));

            const int jointsNumber = (int)JointType.NumberOfJoints;
            //Console.WriteLine(Converter.EncodeInfo(jointsNumber + " total joints..."));
            if (jointsData == null || jointsData.Length != jointsNumber)
            {
                throw new Exception("DecodeSkeletonData is expecting a JointData[] buffer big enough to hold the data.");
            }

            for (int i = 0; i < jointsData.Length; i++)
            {
                jointsData[i].State = TrackingState.NotTracked;
            }

            string[] tokens = data.Split(' ');
            const int elementsNumber = 9;
            for (int i = 0; i < tokens.Length / elementsNumber; i++)
            {
                int jointId = int.Parse(tokens[i * elementsNumber], CultureInfo.InvariantCulture);
                jointsData[jointId].State = (TrackingState)int.Parse(tokens[i * elementsNumber + 1], CultureInfo.InvariantCulture);
                jointsData[jointId].PositionX = float.Parse(tokens[i * elementsNumber + 2], CultureInfo.InvariantCulture);
                jointsData[jointId].PositionY = float.Parse(tokens[i * elementsNumber + 3], CultureInfo.InvariantCulture);
                jointsData[jointId].PositionZ = float.Parse(tokens[i * elementsNumber + 4], CultureInfo.InvariantCulture);
                jointsData[jointId].QuaternionX = float.Parse(tokens[i * elementsNumber + 5], CultureInfo.InvariantCulture);
                jointsData[jointId].QuaternionY = float.Parse(tokens[i * elementsNumber + 6], CultureInfo.InvariantCulture);
                jointsData[jointId].QuaternionZ = float.Parse(tokens[i * elementsNumber + 7], CultureInfo.InvariantCulture);
                jointsData[jointId].QuaternionW = float.Parse(tokens[i * elementsNumber + 8], CultureInfo.InvariantCulture);
             }
        }
 private BodyData SetupBodyData(int userId)
 {
     var bodyData = new BodyData();
     bodyData.UserId = userId;
     const int jointsNumber = (int)DataConverter.JointType.NumberOfJoints;
     var jointData = new JointData[jointsNumber];
     for (int i = 0; i < jointsNumber; i++)
     {
         jointData[i] = new JointData();
         jointData[i].JointId = (DataConverter.JointType)i;
     }
     bodyData.JointData = jointData;
     return bodyData;
 }
        /// <summary>
        /// Encodes skeleton data to transmission.
        /// </summary>
        public static string EncodeSkeletonData(JointData[] jointsData)
        {
            if (jointsData == null)
            {
                return EncodeError("EncodeSkeletonData: joint data is null.");
            }

            _stringBuilder.Remove(0, _stringBuilder.Length);
            _stringBuilder.Append(SkeletonFrameType + "|");
            foreach (var jointData in jointsData)
            {
                if (jointData.State == TrackingState.NotTracked)
                {
                    continue;
                }

                // state x y z qx qy qz qw 
                _stringBuilder.AppendFormat(CultureInfo.InvariantCulture, "{0} {1} {2} {3} {4} {5} {6} {7} {8} ",
                                            (int)jointData.JointId, (int)jointData.State, jointData.PositionX, jointData.PositionY, jointData.PositionZ,
                                            jointData.QuaternionX, jointData.QuaternionY, jointData.QuaternionZ, jointData.QuaternionW);
            }
            return _stringBuilder.ToString();
        }