コード例 #1
0
        /// <summary>
        /// Called when BodyCapture detects a new body.
        /// </summary>
        /// <param name="id">Unique ID of the body.</param>
        private void Body_OnDetected(ulong id)
        {
            Log.Information($"Body detected, creating body elements (Body={id}).");

            _bodyElements[id] = null;

            _network
            .Create(_kinectElement.Id, Util.CreateElementData($"Body {id}"))
            .ContinueWith(task =>
            {
                var rootElement = task.Result;

                Log.Information($"Created body root element (Body={id} Element={rootElement.Id}).");

                // Double check the body didn't disappear during the network op
                if (!_bodyElements.ContainsKey(id))
                {
                    Log.Information($"Matching body already gone. Destroying (Body={id} Element={rootElement.Id}).");
                    _network.Destroy(rootElement.Id);
                    return;
                }

                var bodyElements         = new BodyElements();
                bodyElements.RootElement = rootElement;

                var jointCreates = new Task <ElementData> [_trackList.Length];
                Log.Information($"Creating {jointCreates.Length} joint elements (Body={id}).");
                for (int i = 0, len = _trackList.Length; i < len; i++)
                {
                    var jointType   = _trackList[i];
                    jointCreates[i] = _network.Create(rootElement.Id,
                                                      Util.CreateElementData(jointType.ToString(), _assetMap[jointType]));
                }

                Task
                .WhenAll(jointCreates)
                .ContinueWith(_ =>
                {
                    for (int i = 0, len = _trackList.Length; i < len; i++)
                    {
                        var element = jointCreates[i].Result;
                        Log.Information($"Created joint element (Body={id}, Element={element.Id})");

                        bodyElements.JointElements[_trackList[i]] = element;
                    }

                    Log.Information($"All joint elements created (Body={id})");

                    _bodyElements[id] = bodyElements;
                });
            });
        }
コード例 #2
0
        /// <summary>
        /// Called when BodyCapture detects a new body.
        /// </summary>
        /// <param name="id">Unique ID of the body.</param>
        private void Body_OnDetected(ulong id)
        {
            Log.Information($"Body detected, creating body & joint elements (Body={id}).");

            // Register the slot, but don't populate until elements are created on the network.
            _bodyElements[id] = null;

            var bodyElements = Util.CreateBodyElements($"Body {id}", _assetMap);

            _network
            .Create(_kinectElement.Id, bodyElements.RootElement)
            .ContinueWith(task =>
            {
                var rootElement = task.Result;

                Log.Information($"Created body root element (Body={id} Element={rootElement.Id}).");

                // Double check the body didn't disappear during the network op
                if (!_bodyElements.ContainsKey(id))
                {
                    Log.Information($"Matching body already gone. Destroying (Body={id} Element={rootElement.Id}).");
                    _network.Destroy(rootElement.Id);
                    return;
                }

                _bodyElements[id] = bodyElements;
            });
        }