Beispiel #1
0
        private void OnNoUser(object sender, UserEventArg e)
        {
            Trace.WriteLine("No User " + e.BodyId);
            DisengageUser(e.BodyId);

            StateControl.SwitchState(ProgramState.H0_G0_I0);
            try
            {
                userouttimer.Start();
            }
            catch (Exception) { }
        }
Beispiel #2
0
        void Reader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            //Trace.WriteLine("UserLists.Users " + UserLists.Users.Count);

            using (BodyFrame bodyFrame = e.FrameReference.AcquireFrame())
            {
                if (bodyFrame != null)
                {
                    bodyFrame.GetAndRefreshBodyData(UserManager.bodies);

                    List <ulong> trackedIds = new List <ulong>();
                    foreach (Body body in UserManager.bodies)
                    {
                        if (body == null)
                        {
                            continue;
                        }
                        if (body.IsTracked)
                        {
                            trackedIds.Add(body.TrackingId);
                        }
                    }
                    List <ulong> knownIds = new List <ulong>(UserManager.Users.Keys);
                    foreach (ulong id in knownIds)
                    {
                        if (!trackedIds.Contains(id))
                        {
                            if (LastFrameBodyCount == 1)
                            {
                                //invoke no user
                                NoUser.Invoke(null, new UserEventArg(id));
                            }
                            else
                            {
                                LostUser.Invoke(null, new UserEventArg(id));//invoke lost user
                            }
                            UserManager.Users.Remove(id);
                        }
                    }
                    for (int i = 0; i < UserManager.bodies.Length; i++)
                    {
                        if (UserManager.bodies[i] == null)
                        {
                            continue;
                        }
                        if (UserManager.bodies[i].IsTracked)
                        {
                            if (!UserManager.Users.ContainsKey(UserManager.bodies[i].TrackingId))
                            {
                                UserManager.Users[UserManager.bodies[i].TrackingId] = i;
                                if (LastFrameBodyCount == 0)
                                {
                                    //Invoke user in
                                    UserIn.Invoke(null, new UserEventArg(UserManager.bodies[i].TrackingId));
                                }
                                else
                                {
                                    //Invoke found new user
                                    NewUser.Invoke(null, new UserEventArg(UserManager.bodies[i].TrackingId));
                                }
                            }

                            //Trace.WriteLine(body.TrackingId);
                        }
                    }
                    if (UserManager.Users.Count > 0)
                    {
                        gestureDetector.IsPaused = false;
                        ulong closestUser = ChooseClosestSkeletons(UserManager.bodies, 1);
                        if (UserManager.closestUser != closestUser)
                        {
                            UserManager.closestUser = closestUser;
                        }
                        bool isInteractive = UserManager.IsMainUserInteractive;
                        if (UserManager.currentUser != gestureDetector.TrackingId)
                        {
                            gestureDetector.TrackingId = UserManager.currentUser;
                        }
                        if (isInteractive != LastInteractive)
                        {
                            if (isInteractive)
                            {
                                StateControl.SwitchState(ProgramState.H1_G1_I1);
                            }
                            else
                            {
                                StateControl.SwitchState(ProgramState.H1_G0_I0);
                            }

                            LastInteractive = isInteractive;
                        }

                        //updateinterval++;
                        //if (updateinterval >= 60)
                        //{
                        //    foreach (var bd in UserManager.bodies)
                        //    {
                        //        if (bd.TrackingId != 0)
                        //            sqlUpdateUser(bd.TrackingId);
                        //    }
                        //    updateinterval = 0;
                        //}
                    }
                    else
                    {
                        gestureDetector.IsPaused = true;
                    }
                    int maxBodies = kinectSensor.BodyFrameSource.BodyCount;
                    for (int i = 0; i < maxBodies; i++) //control pause and resume hand raise detector
                    {
                        Body  body       = UserManager.bodies[i];
                        ulong trackingId = body.TrackingId;
                        if (trackingId != handRaiseList[i].trackingId)
                        {
                            handRaiseList[i].trackingId = trackingId;
                            handRaiseList[i].isPaused   = trackingId == 0;
                        }
                        handRaiseList[i].Update();
                    }

                    if (UserManager.currentUser != 0 && UserManager.IsMainUserInteractive)  //move mouse control if interactive
                    {
                        handPointer.Update();
                    }
                    LastFrameBodyCount = UserManager.Users.Count;
                    if (ConfigParams.UserView != LastUserView)
                    {
                        if (ConfigParams.UserView)
                        {
                            main.UserView.Opacity = 100;
                        }
                        else
                        {
                            main.UserView.Opacity = 0;
                        }
                        LastUserView = ConfigParams.UserView;
                    }
                    if (ConfigParams.UserView)
                    {
                        userView.DrawBodies();
                    }
                }
            }
        }