Beispiel #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 & 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;
            });
        }
Beispiel #2
0
        /// <summary>
        /// Called when the Kinect SDK changes its device availability.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        private void SensorOnIsAvailableChanged(object sender, IsAvailableChangedEventArgs args)
        {
            _bodyCapture?.Stop();

            if (args.IsAvailable)
            {
                Log.Information($"Kinect available ({_sensor.UniqueKinectId})");

                _kinectElement = FindKinect(_sensor.UniqueKinectId, _elements);
                if (_kinectElement == null)
                {
                    Log.Warning("No Kinect element found in scene.");
                    return;
                }
                Log.Information($"Kinect element found ({_kinectElement})");

                _assetMap  = BuildTracking(_kinectElement);
                _trackList = _assetMap.Keys.Select(j => j).ToArray();
                if (_trackList.Length == 0)
                {
                    Log.Warning("No tracking desired?");
                    return;
                }
                Log.Information($"Tracking {_trackList.Length} joints " +
                                $"({string.Join(", ", _trackList.Select(j => j.ToString()))})");

                _bodyCapture = new BodyCapture(_sensor, _trackList);
                _bodyCapture.OnBodyDetected += Body_OnDetected;
                _bodyCapture.OnBodyUpdated  += Body_OnUpdated;
                _bodyCapture.OnBodyLost     += Body_OnLost;
                _bodyCapture.Start();

                _active = true;
            }
            else if (_active)
            {
                Log.Information("Lost connection to Kinect.");

                _kinectElement = null;

                // TODO: Reset lookup tables

                foreach (var bodyElements in _bodyElements.Values)
                {
                    if (bodyElements != null)
                    {
                        _network.Destroy(bodyElements.RootElement.Id);
                    }
                }
                _bodyElements.Clear();

                _active = false;
            }
        }