コード例 #1
0
 /// <summary>
 /// Invoked when a frame completes from the Kinect.
 /// </summary>
 private void Body_OnFrameEnd()
 {
     if (_updates.Count > 0)
     {
         _network.Update(_updates.ToArray());
         _lastUpdate = DateTime.Now;
     }
 }
コード例 #2
0
        /// <summary>
        /// Called when BodyCapture has updated data for a body.
        /// </summary>
        /// <param name="id">Unique ID of the body.</param>
        /// <param name="data">Current data for the body.</param>
        private void Body_OnUpdated(ulong id, BodyCapture.SensorData data)
        {
            if (!_bodyElements.TryGetValue(id, out var bodyElements))
            {
                Log.Error("Body updated, but was never tracked.");
                return;
            }

            if (bodyElements == null)
            {
                return; // This is okay, Elements are in flight.
            }

            if ((DateTime.Now - bodyElements.LastUpdate).TotalMilliseconds < _config.SendIntervalMs)
            {
                return; // Time throttling
            }

            const int stride  = 2;
            var       updates = new ElementActionData[_trackList.Length * stride];

            for (int i = 0, len = _trackList.Length; i < len; i++)
            {
                var jointType = _trackList[i];

                if (!data.JointPositions.ContainsKey(jointType))
                {
                    // If there's invalid data and the body is visible, hide it!
                    if (bodyElements.Visible)
                    {
                        _network.Update(new [] { new ElementActionData
                                                 {
                                                     ElementId  = bodyElements.RootElement.Id,
                                                     Type       = "update",
                                                     SchemaType = "bool",
                                                     Key        = PropVisible,
                                                     Value      = false
                                                 } });
                        bodyElements.Visible = false;
                    }
                    return;
                }

                updates[i * stride] = new ElementActionData
                {
                    ElementId  = bodyElements.JointElements[jointType].Id,
                    Type       = "update",
                    SchemaType = "vec3",
                    Key        = PropPosition,
                    Value      = data.JointPositions[jointType]
                };

                updates[i * stride + 1] = new ElementActionData
                {
                    ElementId  = bodyElements.JointElements[jointType].Id,
                    Type       = "update",
                    SchemaType = "vec3",
                    Key        = PropRotation,
                    Value      = data.JointRotations[jointType]
                };
            }

            // If previously hidden, unhide!
            if (!bodyElements.Visible)
            {
                var tmp = new ElementActionData[updates.Length + 1];
                Array.Copy(updates, tmp, updates.Length);
                updates = tmp;
                updates[updates.Length] = new ElementActionData
                {
                    ElementId  = bodyElements.RootElement.Id,
                    Type       = "update",
                    SchemaType = "bool",
                    Key        = PropVisible,
                    Value      = true
                };
            }

            _network.Update(updates);
            bodyElements.LastUpdate = DateTime.Now;
        }