/// <summary> /// Called when a body frame is received. /// </summary> /// <param name="message">The message.</param> private void OnMessage_BodyFrameArrived(MessageBodyFrameArrived message) { if (m_bodyScene.CountViews <= 0) { return; } if (m_bodyDataModified) { return; } using (BodyFrame bodyFrame = message.BodyFrameArgs.FrameReference.AcquireFrame()) { if (bodyFrame == null) { return; } // Process incoming body frame // 1. Store data in local m_bodyData liste bodyFrame.GetAndRefreshBodyData(m_bodyData); m_bodyDataModified = true; // 2. Modify 3D scene based on the data m_bodyScene.ManipulateSceneAsync((manipulator) => { try { for(int actBodyIndex = 0; actBodyIndex<m_bodyData.Count; actBodyIndex++) { UpdateBodyModel(m_bodyScene, manipulator, m_bodyData[actBodyIndex], actBodyIndex); } } finally { m_bodyDataModified = false; } }); } }
/// <summary> /// Called when a body frame is received. /// </summary> /// <param name="message">The message to be processed.</param> private async void OnMessage_BodyFrameArrived(MessageBodyFrameArrived message) { if (m_isStopped) { return; } if (m_isProcessing) { return; } try { m_isProcessing = true; // Try to get the BodyFrame from the Kinect bool gotData = false; using (var frame = message.BodyFrameArgs.FrameReference.AcquireFrame()) { if (frame != null) { m_bodies.CreateDummyObjectUntilCapacityReached(frame.BodyCount); frame.GetAndRefreshBodyData(m_bodies); gotData = true; } } // Process data if we've got one if (gotData && !m_isStopped) { await SeeingSharpApplication.Current.UISyncContext.PostAsync(() => { this.TrackEngagedPlayersViaHandOverHead(); }); } } finally { m_isProcessing = false; } }