middleware/src/MainModule/KinectMain.cs
changeset 15 4b78f179e7ce
child 16 a9ebacd6c089
equal deleted inserted replaced
14:10d5199d9874 15:4b78f179e7ce
       
     1 /*
       
     2 * This file is part of the TraKERS\Middleware package.
       
     3 *
       
     4 * (c) IRI <http://www.iri.centrepompidou.fr/>
       
     5 *
       
     6 * For the full copyright and license information, please view the LICENSE_MIDDLEWARE
       
     7 * file that was distributed with this source code.
       
     8 */
       
     9 
       
    10 /*
       
    11  * Projet : TraKERS
       
    12  * Module : MIDDLEWARE
       
    13  * Sous-Module : Tracking
       
    14  * Classe : KinectMain
       
    15  * 
       
    16  * Auteur : alexandre.bastien@iri.centrepompidou.fr
       
    17  * 
       
    18  * Fonctionnalités : Récupère les trames de données de la Kinect, les squelettes détectés via le SDK 1.0 de Microsoft.
       
    19  * Interprète ces trames de façon à afficher le flux vidéo couleurs, et récupérer la distance de l'utilisateur et les
       
    20  * noeuds de son squelette. Lance des événements lorsque la main gauche/droite entre dans/quitte le champ.
       
    21  * Envoie des données au sous-module de debug de manière a afficher un retour visuel sur la position de l'utilisateur,
       
    22  * son squelette, la détection de ses mains.
       
    23  * Découpe l'interaction avec le middleware en différents modes.
       
    24  */
       
    25 
       
    26 using System;
       
    27 using System.Collections.Generic;
       
    28 using System.Linq;
       
    29 using System.Windows.Documents;
       
    30 using Microsoft.Kinect;
       
    31 using Trakers.Communication;
       
    32 using Trakers.MainModule.Events;
       
    33 using Trakers.MainModule.Gestures;
       
    34 using Trakers.MainModule.Search;
       
    35 using Trakers.Debug;
       
    36 using System.Windows;
       
    37 
       
    38 namespace Trakers.MainModule
       
    39 {
       
    40     //Il s'agit des fonctions permettant d'appeler les fonctions des événements Main droite/gauche entre/quitte le champ.
       
    41     public delegate void LeftHandTrackedHandler(object o, LeftHandTrackedEventArgs e);
       
    42     public delegate void RightHandTrackedHandler(object o, RightHandTrackedEventArgs e);
       
    43     public delegate void LeftHandQuitHandler(object o, LeftHandQuitEventArgs e);
       
    44     public delegate void RightHandQuitHandler(object o, RightHandQuitEventArgs e);
       
    45     //Il s'agit de la fonction permettant d'appeler les fonctions des événements Swipe left/right/up/down.
       
    46     public delegate void SwipeHandler(object o, SwipeEventArgs e);
       
    47     //Il s'agit de la fonction permettant d'appeler les fonctions des événements Push/Pull.
       
    48     public delegate void PushHandler(object o, PushEventArgs e);
       
    49     //Il s'agit de la fonction permettant d'appeler les fonctions des événements Jump.
       
    50     public delegate void JumpHandler(object o, JumpEventArgs e);
       
    51     //Il s'agit de la fonction permettant d'appeler les fonctions des événements de proximité.
       
    52     public delegate void UserPositionHandler(object o, UserPositionEventArgs e);
       
    53 
       
    54     public class KinectMain
       
    55     {
       
    56         //Fenêtre de debug.
       
    57         private DebugWindow debug;
       
    58         //Squelettes (Il y en a 6 par défaut).
       
    59         private Skeleton[] skeletons;
       
    60         //Caméra infrarouge (sensor) de la Kinect.
       
    61         private KinectSensor kinectSensor;
       
    62 
       
    63         //Détecteur de swipes.
       
    64         private SwipeDetector swipeDetector;
       
    65         //Détecteur de pushes.
       
    66         private PushDetector pushDetector;
       
    67         //Détecteur de jumps.
       
    68         private JumpDetector jumpDetector;
       
    69         //Détecteur de proximité.
       
    70         private UserPositionDetector userPositionDetector;
       
    71 
       
    72         //Serveur TUIO pour la connexion du Middleware vers le Front Atelier.
       
    73         private Server server;
       
    74 
       
    75         //Gestionnaire de modes.
       
    76         private ModeManagement modeManagement;
       
    77 
       
    78         //Les événements des mains pour la recherche.
       
    79         public static event LeftHandTrackedHandler LeftHandTrackedEvent;
       
    80         public static event RightHandTrackedHandler RightHandTrackedEvent;
       
    81         public static event LeftHandQuitHandler LeftHandQuitEvent;
       
    82         public static event RightHandQuitHandler RightHandQuitEvent;
       
    83         //L'événement swipe.
       
    84         public static event SwipeHandler SwipeEvent;
       
    85         //L'événement push.
       
    86         public static event PushHandler PushEvent;
       
    87         //L'événement jump.
       
    88         public static event JumpHandler JumpEvent;
       
    89         //L'événement l'utilisateur se déplace dans la zone de détection.
       
    90         public static event UserPositionHandler UserPositionEvent;
       
    91 
       
    92         /*
       
    93         *  Initialisation de la classe principale.
       
    94         *  Affiche l'écran de debug dans lequel on voit la distance à la Kinect,
       
    95         *  les mains détectées et le squelette de l'utilisateur.
       
    96         */
       
    97         public KinectMain()
       
    98         {
       
    99             //On crée la fenêtre de debug.
       
   100             debug = new DebugWindow();
       
   101 
       
   102             //On crée les détecteurs de gestes.
       
   103             swipeDetector = new SwipeDetector();
       
   104             pushDetector = new PushDetector();
       
   105             jumpDetector = new JumpDetector();
       
   106             //On crée le détecteur de proximité.
       
   107             userPositionDetector = new UserPositionDetector(debug.getMinDist(), debug.getMaxDist(), debug.getZeroPoint(), debug.getMinDistHands(), debug.getMaxDistHands());
       
   108 
       
   109             //On écoute l'événement de clic sur le bouton on/off du debug.
       
   110             //Car on lancera l'intitialisation/fermeture de la kinect.
       
   111             debug.getSwitch().Click += new RoutedEventHandler(Switch_ClickInKinectMain);
       
   112             debug.Loaded += new RoutedEventHandler(Window_LoadedInKinectMain);
       
   113             debug.Closed += new EventHandler(Window_CloseInKinectMain);
       
   114             debug.getQuitMenu().Click += new RoutedEventHandler(Quit_ClickInKinectMain);
       
   115 
       
   116             //On affiche la fenêtre de debug.
       
   117             try
       
   118             {
       
   119                 debug.ShowDialog();
       
   120             }
       
   121             catch(Exception){
       
   122             }
       
   123         }
       
   124 
       
   125         /*
       
   126         *  Initialisation du sensor de la Kinect.
       
   127         */
       
   128         public void KinectInitialization()
       
   129         {
       
   130             try
       
   131             {
       
   132                 //On sélectionne la première kinect détectée.
       
   133                 kinectSensor = KinectSensor.KinectSensors.FirstOrDefault(s => s.Status == KinectStatus.Connected);
       
   134                 //La caméra couleur est activée avec une résolution 640x480 et un framerate de 30 FPS.
       
   135                 kinectSensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
       
   136                 //La caméra de profondeur est activée.
       
   137                 kinectSensor.DepthStream.Enable();
       
   138                 //Le squelette est activé.
       
   139                 kinectSensor.SkeletonStream.Enable();
       
   140 
       
   141                 //Quand le Middleware reçoit des trames de la Kinect, on va dans cette fonction.
       
   142                 kinectSensor.AllFramesReady += new EventHandler<AllFramesReadyEventArgs>(AllFramesReady);
       
   143 
       
   144                 //On applique des paramètres d'ajustement pour le squelette.
       
   145                 TransformSmoothParameters parameters = new TransformSmoothParameters();
       
   146                 parameters.Smoothing = 0.2f;
       
   147                 parameters.Correction = 0.8f;
       
   148                 parameters.Prediction = 0.0f;
       
   149                 parameters.JitterRadius = 0.5f;
       
   150                 parameters.MaxDeviationRadius = 0.5f;
       
   151                 kinectSensor.SkeletonStream.Enable(parameters);
       
   152                 //On démarre la Kinect.
       
   153                 kinectSensor.Start();
       
   154 
       
   155             }
       
   156             catch (System.Exception)
       
   157             {
       
   158                 debug.ShowException("KinectNotConnected");
       
   159             }
       
   160 
       
   161             //Pour les événements main gauche/droite entre dans/quitte le champ, on a 4 listeners.
       
   162             //Fonction appelée lorsque la main gauche entre dans le champ de recherche.
       
   163             LeftHandTrackedListener leftHandTrackedListener = new LeftHandTrackedListener();
       
   164             LeftHandTrackedEvent += new LeftHandTrackedHandler(leftHandTrackedListener.showAndSend);
       
   165 
       
   166             //Fonction appelée lorsque la main droite entre dans le champ de recherche.
       
   167             RightHandTrackedListener rightHandTrackedListener = new RightHandTrackedListener();
       
   168             RightHandTrackedEvent += new RightHandTrackedHandler(rightHandTrackedListener.showAndSend);
       
   169 
       
   170             //Fonction appelée lorsque la main gauche quitte le champ de recherche.
       
   171             LeftHandQuitListener leftHandQuitListener = new LeftHandQuitListener();
       
   172             LeftHandQuitEvent += new LeftHandQuitHandler(leftHandQuitListener.showAndSend);
       
   173 
       
   174             //Fonction appelée lorsque la main droite quitte le champ de recherche.
       
   175             RightHandQuitListener rightHandQuitListener = new RightHandQuitListener();
       
   176             RightHandQuitEvent += new RightHandQuitHandler(rightHandQuitListener.showAndSend);
       
   177 
       
   178             //Fonction appelée lorsque l'utilisateur effectue un Swipe right/left/up/down.
       
   179             SwipeListener swipeListener = new SwipeListener();
       
   180             SwipeEvent += new SwipeHandler(swipeListener.showAndSend);
       
   181 
       
   182             //Fonction appelée lorsque l'utilisateur effectue un Push/Pull.
       
   183             PushListener pushListener = new PushListener();
       
   184             PushEvent += new PushHandler(pushListener.showAndSend);
       
   185 
       
   186             //Fonction appelée lorsque l'utilisateur effectue un Jump.
       
   187             JumpListener jumpListener = new JumpListener();
       
   188             JumpEvent += new JumpHandler(jumpListener.showAndSend);
       
   189 
       
   190             //Fonction appelée lorsque l'utilisateur se déplace dans la zone de détection.
       
   191             UserPositionListener userPositionListener = new UserPositionListener();
       
   192             UserPositionEvent += new UserPositionHandler(userPositionListener.showAndSend);
       
   193 
       
   194             //On connecte le serveur à l'adresse locale sur le port 80.
       
   195             try
       
   196             {
       
   197                 server = new Server(debug.getConnexionHost(), debug.getConnexionPort(), debug.getTimerElapsing());
       
   198                 //On crée le gestionnaire de modes.
       
   199                 modeManagement = new ModeManagement(server, debug, this);
       
   200                 modeManagement.DetectProximityBasedModes(0);
       
   201             }
       
   202             catch (Exception)
       
   203             {
       
   204                 debug.ShowException("serverCantStart");
       
   205             }
       
   206         }
       
   207 
       
   208         /*
       
   209         * Bouton ON/OFF du debug écouté dans KinectMain.
       
   210         */
       
   211         public void Switch_ClickInKinectMain(object sender, RoutedEventArgs e)
       
   212         {
       
   213             Console.Out.WriteLine(debug.getOn());
       
   214             //Si la kinect est allumée.
       
   215             if (debug.getOn())
       
   216             {
       
   217                 //On initialise la Kinect.
       
   218                 KinectInitialization();
       
   219             }
       
   220             else
       
   221             {
       
   222                 //On éteint la Kinect.
       
   223                 KinectClose();
       
   224             }
       
   225         }
       
   226 
       
   227         /*
       
   228          * Méthode associée à l'événement : Quitter via le menu écoutée dans KinectMain.
       
   229          */
       
   230         private void Quit_ClickInKinectMain(object sender, RoutedEventArgs e)
       
   231         {
       
   232             KinectClose();
       
   233             debug.Quit_Click(sender, e);
       
   234         }
       
   235 
       
   236         /*
       
   237          * Permet d'initialiser la Kinect dès que la fenêtre est lancée écoutée dans KinectMain.
       
   238          */
       
   239         private void Window_LoadedInKinectMain(object sender, RoutedEventArgs e)
       
   240         {
       
   241             KinectInitialization();
       
   242         }
       
   243 
       
   244         /*
       
   245         * Fermeture du debug écouté dans KinectMain.
       
   246         */
       
   247         private void Window_CloseInKinectMain(object sender, EventArgs e)
       
   248         {
       
   249             //On éteint la Kinect.
       
   250             KinectClose();
       
   251             debug.Window_Closed(sender, e);
       
   252         }
       
   253 
       
   254         /*
       
   255         *  Fermeture du sensor de la Kinect.
       
   256         */
       
   257         public void KinectClose()
       
   258         {
       
   259             try
       
   260             {
       
   261                 //On stoppe la Kinect.
       
   262                 kinectSensor.Stop();
       
   263                 //On met a zero l'image d'affichage et le serveur.
       
   264                 debug.ShutDownInterface();
       
   265             }
       
   266             catch (System.Exception)
       
   267             {
       
   268                 debug.ShowException("KinectNotConnected");
       
   269             }
       
   270         }
       
   271 
       
   272         /*
       
   273         *  Récupère le premier squelette.
       
   274         */
       
   275         Skeleton GetFirstSkeleton(object sender, AllFramesReadyEventArgs e)
       
   276         {
       
   277             using (SkeletonFrame skeletonFrameData = e.OpenSkeletonFrame())
       
   278             {
       
   279                 if (skeletonFrameData == null)
       
   280                     return null;
       
   281                 if ((skeletons == null) || (skeletons.Length != skeletonFrameData.SkeletonArrayLength))
       
   282                     skeletons = new Skeleton[skeletonFrameData.SkeletonArrayLength];
       
   283                 skeletonFrameData.CopySkeletonDataTo(skeletons);
       
   284 
       
   285                 //On obtient le premier skelette.
       
   286                 Skeleton first = (from s in skeletons where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault();
       
   287 
       
   288                 return first;
       
   289             }
       
   290         }
       
   291 
       
   292         /*
       
   293         *  Récupère le squelette le plus proche.
       
   294         */
       
   295         Skeleton GetNearestSkeleton(object sender, AllFramesReadyEventArgs e)
       
   296         {
       
   297             using (SkeletonFrame skeletonFrameData = e.OpenSkeletonFrame())
       
   298             {
       
   299                 if (skeletonFrameData == null)
       
   300                     return null;
       
   301                 if ((skeletons == null) || (skeletons.Length != skeletonFrameData.SkeletonArrayLength))
       
   302                     skeletons = new Skeleton[skeletonFrameData.SkeletonArrayLength];
       
   303                 skeletonFrameData.CopySkeletonDataTo(skeletons);
       
   304 
       
   305                 Skeleton s;
       
   306                 float minDist = (float)-1.0;
       
   307                 int minID = 0;
       
   308                     
       
   309                 //Pour tous les squelettes.
       
   310                 for(int i = 0 ; i < skeletons.Count() ; i++)
       
   311                 {
       
   312                     s = skeletons.ElementAt(i);
       
   313                     //S'il est tracké.
       
   314                     if(s.TrackingState == SkeletonTrackingState.Tracked)
       
   315                     {
       
   316                         //On récupère sa position et on obtient la distance min et l'ID du squelette qui est à la distance min.
       
   317                         float dist = skeletons.ElementAt(i).Position.Z;
       
   318                         if (minDist == -1)
       
   319                         {
       
   320                             minDist = dist;
       
   321                             minID = i;
       
   322                         }
       
   323                         else if(minDist > dist)
       
   324                         {
       
   325                             minDist = dist;
       
   326                             minID = i;
       
   327                         }
       
   328                     }
       
   329                 }
       
   330 
       
   331                 //On renvoie le skelette le plus proche.
       
   332                 return skeletons.ElementAt(minID);
       
   333             }
       
   334         }
       
   335 
       
   336         /*
       
   337         *  Récupère le squelette le plus proche.
       
   338         */
       
   339         private void AllFramesReady(object sender, AllFramesReadyEventArgs e)
       
   340         {
       
   341             //On ne calcule rien si la fenêtre de debug se ferme.
       
   342             if (debug.isClosing())
       
   343                 return;
       
   344 
       
   345             //On écoute le debug pour savoir si les paramètres ont été modifiés.
       
   346             
       
   347 
       
   348             //On met à jour la vidéo de debug.
       
   349             debug.RefreshVideo(e);
       
   350             //On récupère le premier squelette tracké.
       
   351             //Skeleton first = GetFirstSkeleton(e);
       
   352             //On récupère le plus proche squelette tracké.
       
   353             Skeleton first = GetNearestSkeleton(sender, e);
       
   354             //Si celui-ci n’est pas nul
       
   355             if (first == null)
       
   356                 return;
       
   357             
       
   358             //Si ce squelette est tracké (donc suivi et reconnu par la camera)
       
   359             if (first.TrackingState == SkeletonTrackingState.Tracked)
       
   360             {
       
   361                 //Ensemble des noeuds du squelette.
       
   362                 Joint hipCenter = getJoint(first, JointType.HipCenter), spine = getJoint(first, JointType.Spine), shoulderCenter = getJoint(first, JointType.ShoulderCenter), head = getJoint(first, JointType.Head);
       
   363                 Joint shoulderLeft = getJoint(first, JointType.ShoulderLeft), elbowLeft = getJoint(first, JointType.ElbowLeft), wristLeft = getJoint(first, JointType.WristLeft), handLeft = getJoint(first, JointType.HandLeft);
       
   364                 Joint shoulderRight = getJoint(first, JointType.ShoulderRight), elbowRight = getJoint(first, JointType.ElbowRight), wristRight = getJoint(first, JointType.WristRight), handRight = getJoint(first, JointType.HandRight);
       
   365                 Joint hipLeft = getJoint(first, JointType.HipLeft), kneeLeft = getJoint(first, JointType.KneeLeft), ankleLeft = getJoint(first, JointType.AnkleLeft), footLeft = getJoint(first, JointType.FootLeft);
       
   366                 Joint hipRight = getJoint(first, JointType.HipRight), kneeRight = getJoint(first, JointType.KneeRight), ankleRight = getJoint(first, JointType.AnkleRight), footRight = getJoint(first, JointType.FootRight);
       
   367 
       
   368                 //On construit l'historique des postures.
       
   369                 List<Joint> joints = new List<Joint>();
       
   370                 joints.Clear();
       
   371                 joints.Insert((int)JointType.HipCenter, hipCenter);
       
   372                 joints.Insert((int)JointType.Spine, spine);
       
   373                 joints.Insert((int)JointType.ShoulderCenter, shoulderCenter);
       
   374                 joints.Insert((int)JointType.Head, head);
       
   375                 joints.Insert((int)JointType.ShoulderLeft, shoulderLeft);
       
   376                 joints.Insert((int)JointType.ElbowLeft, elbowLeft);
       
   377                 joints.Insert((int)JointType.WristLeft, wristLeft);
       
   378                 joints.Insert((int)JointType.HandLeft, handLeft);
       
   379                 joints.Insert((int)JointType.ShoulderRight, shoulderRight);
       
   380                 joints.Insert((int)JointType.ElbowRight, elbowRight);
       
   381                 joints.Insert((int)JointType.WristRight, wristRight);
       
   382                 joints.Insert((int)JointType.HandRight, handRight);
       
   383                 joints.Insert((int)JointType.HipLeft, hipLeft);
       
   384                 joints.Insert((int)JointType.KneeLeft, kneeLeft);
       
   385                 joints.Insert((int)JointType.AnkleLeft, ankleLeft);
       
   386                 joints.Insert((int)JointType.FootLeft, footLeft);
       
   387                 joints.Insert((int)JointType.HipRight, hipRight);
       
   388                 joints.Insert((int)JointType.KneeRight, kneeRight);
       
   389                 joints.Insert((int)JointType.AnkleRight, ankleRight);
       
   390                 joints.Insert((int)JointType.FootRight, footRight);
       
   391                 GestureDetector.UpdateSkeletonHistory(joints);
       
   392 
       
   393                 //Si la main gauche est dans le champ, on lance l'événement approprié.
       
   394                 if (handLeft.Position.Z < debug.getMaxDistHands() && handLeft.Position.Z > debug.getMinDistHands())
       
   395                 {
       
   396                     LeftHandTrackedEventArgs leftHandTrackedEvent = new LeftHandTrackedEventArgs(server, debug, handLeft, handLeft.Position.Z);
       
   397                     OnLeftHandTrackedEvent(leftHandTrackedEvent);
       
   398                 }
       
   399                 //Si la main gauche quitte le champ, on lance l'événement approprié.
       
   400                 else
       
   401                 {
       
   402                     LeftHandQuitEventArgs leftHandQuitEvent = new LeftHandQuitEventArgs(server, debug);
       
   403                     OnLeftHandQuitEvent(leftHandQuitEvent);
       
   404                 }
       
   405                 //Si la main droite est dans le champ, on lance l'événement approprié.
       
   406                 if (handRight.Position.Z < debug.getMaxDistHands() && handRight.Position.Z > debug.getMinDistHands())
       
   407                 {
       
   408                     RightHandTrackedEventArgs rightHandTrackedEvent = new RightHandTrackedEventArgs(server, debug, handRight, handRight.Position.Z);
       
   409                     OnRightHandTrackedEvent(rightHandTrackedEvent);
       
   410                 }
       
   411                 //Si la main droite quitte le champ, on lance l'événement approprié.
       
   412                 else
       
   413                 {
       
   414                     RightHandQuitEventArgs rightHandQuitEvent = new RightHandQuitEventArgs(server, debug);
       
   415                     OnRightHandQuitEvent(rightHandQuitEvent);
       
   416                 }
       
   417 
       
   418                 //Si l'utilisateur effectue un swipe left.
       
   419                 if (swipeDetector.CheckForSwipeLeft())
       
   420                 {
       
   421                     SwipeEventArgs swipeEvent = new SwipeEventArgs(server, debug, SwipeDetector.Direction.LEFT);
       
   422                     OnSwipeEvent(swipeEvent);
       
   423                 }
       
   424 
       
   425                 //Si l'utilisateur effectue un swipe right.
       
   426                 if (swipeDetector.CheckForSwipeRight())
       
   427                 {
       
   428                     SwipeEventArgs swipeEvent = new SwipeEventArgs(server, debug, SwipeDetector.Direction.RIGHT);
       
   429                     OnSwipeEvent(swipeEvent);
       
   430                 }
       
   431 
       
   432                 //Enum sur la main qui effectue le geste.
       
   433                 PushDetector.Hand handPush;
       
   434                 //Si l'utilisateur effectue un push.
       
   435                 if ((handPush = pushDetector.CheckForPush()) != PushDetector.Hand.NONE)
       
   436                 {
       
   437                     PushEventArgs pushEvent = new PushEventArgs(server, debug, PushDetector.Direction.PUSH, handPush);
       
   438                     OnPushEvent(pushEvent);
       
   439                 }
       
   440                 //Si l'utilisateur effectue un pull.
       
   441                 if ((handPush = pushDetector.CheckForPull()) != PushDetector.Hand.NONE)
       
   442                 {
       
   443                     PushEventArgs pushEvent = new PushEventArgs(server, debug, PushDetector.Direction.PULL, handPush);
       
   444                     OnPushEvent(pushEvent);
       
   445                 }
       
   446 
       
   447                 //Si l'utilisateur se déplace dans la zone de détection.
       
   448                 //On traite le problème en plusieurs limites, on discrétise la zone.
       
   449                 if (first.TrackingState == SkeletonTrackingState.Tracked)
       
   450                 {
       
   451                     float proximity = userPositionDetector.CalcProximity(first.Position.Z);
       
   452                     int numberOfImages = userPositionDetector.ImagesToShow(proximity, debug.getImagesToShow());
       
   453 
       
   454                     modeManagement.DetectProximityBasedModes(proximity);
       
   455 
       
   456                     if (proximity > 0f)
       
   457                     {
       
   458                         UserPositionEventArgs userPositionEvent = new UserPositionEventArgs(server, debug, proximity, numberOfImages);
       
   459                         OnUserPositionEvent(userPositionEvent);
       
   460                     }
       
   461                     else if(proximity < 10f)
       
   462                     {
       
   463                         debug.hideSkeleton();
       
   464                         modeManagement.DetectProximityBasedModes(0);
       
   465                         LeftHandQuitEventArgs leftHandQuitEvent = new LeftHandQuitEventArgs(server, debug);
       
   466                         OnLeftHandQuitEvent(leftHandQuitEvent);
       
   467                         RightHandQuitEventArgs rightHandQuitEvent = new RightHandQuitEventArgs(server, debug);
       
   468                         OnRightHandQuitEvent(rightHandQuitEvent);
       
   469                     }
       
   470                 }
       
   471 
       
   472                 //Dessine le squelette dans le debug.
       
   473                 debug.drawJoints(first.Joints, first);
       
   474                 debug.showSkeleton(hipCenter, spine, shoulderCenter, head, shoulderLeft, elbowLeft, wristLeft, handLeft, shoulderRight, elbowRight, wristRight, handRight, hipLeft, kneeLeft, ankleLeft, footLeft, hipRight, kneeRight, ankleRight, footRight);
       
   475             }
       
   476             else
       
   477             {
       
   478                 debug.hideSkeleton();
       
   479                 modeManagement.DetectProximityBasedModes(0);
       
   480                 LeftHandQuitEventArgs leftHandQuitEvent = new LeftHandQuitEventArgs(server, debug);
       
   481                 OnLeftHandQuitEvent(leftHandQuitEvent);
       
   482                 RightHandQuitEventArgs rightHandQuitEvent = new RightHandQuitEventArgs(server, debug);
       
   483                 OnRightHandQuitEvent(rightHandQuitEvent);
       
   484             }
       
   485         }
       
   486 
       
   487         /*
       
   488         *  Change l'échelle des coordonnées d'un noeud pour qu'en X et Y il corresponde à la résolution et en Z à la distance à la Kinect.
       
   489         */
       
   490         public Joint getJoint(Skeleton ske, JointType jointID)
       
   491         {
       
   492             return Coding4Fun.Kinect.Wpf.SkeletalExtensions.ScaleTo(ske.Joints[jointID], 600, 400, 0.75f, 0.75f);
       
   493         }
       
   494 
       
   495         /*
       
   496         *  Initialise l'événement et fait appel aux fonctions du listener quand la main gauche entre dans le champ.
       
   497         */
       
   498         public static void OnLeftHandTrackedEvent(LeftHandTrackedEventArgs e)
       
   499         {
       
   500             if (LeftHandTrackedEvent != null)
       
   501                 LeftHandTrackedEvent(new object(), e);
       
   502         }
       
   503 
       
   504         /*
       
   505         *  Initialise l'événement et fait appel aux fonctions du listener quand la main droite entre dans le champ.
       
   506         */
       
   507         public static void OnRightHandTrackedEvent(RightHandTrackedEventArgs e)
       
   508         {
       
   509             if (RightHandTrackedEvent != null)
       
   510                 RightHandTrackedEvent(new object(), e);
       
   511         }
       
   512 
       
   513         /*
       
   514         *  Initialise l'événement et fait appel aux fonctions du listener quand la main gauche quitte le champ.
       
   515         */
       
   516         public static void OnLeftHandQuitEvent(LeftHandQuitEventArgs e)
       
   517         {
       
   518             if (LeftHandQuitEvent != null)
       
   519                 LeftHandQuitEvent(new object(), e);
       
   520         }
       
   521 
       
   522         /*
       
   523         *  Initialise l'événement et fait appel aux fonctions du listener quand la main droite quitte le champ.
       
   524         */
       
   525         public static void OnRightHandQuitEvent(RightHandQuitEventArgs e)
       
   526         {
       
   527             if (RightHandQuitEvent != null)
       
   528                 RightHandQuitEvent(new object(), e);
       
   529         }
       
   530 
       
   531         /*
       
   532         *  Initialise l'événement et fait appel aux fonctions du listener quand l'utilisateur effectue un swipe right.
       
   533         */
       
   534         public static void OnSwipeEvent(SwipeEventArgs e)
       
   535         {
       
   536             if (SwipeEvent != null)
       
   537                 SwipeEvent(new object(), e);
       
   538         }
       
   539 
       
   540         /*
       
   541         *  Initialise l'événement et fait appel aux fonctions du listener quand l'utilisateur effectue un push.
       
   542         */
       
   543         public static void OnPushEvent(PushEventArgs e)
       
   544         {
       
   545             if (PushEvent != null)
       
   546                 PushEvent(new object(), e);
       
   547         }
       
   548 
       
   549         /*
       
   550         *  Initialise l'événement et fait appel aux fonctions du listener quand l'utilisateur effectue un saut.
       
   551         */
       
   552         public static void OnJumpEvent(JumpEventArgs e)
       
   553         {
       
   554             if (JumpEvent != null)
       
   555                 JumpEvent(new object(), e);
       
   556         }
       
   557 
       
   558         /*
       
   559         *  Initialise l'événement et fait appel aux fonctions du listener quand l'utilisateur se déplace
       
   560          *  dans la zone de détection.
       
   561         */
       
   562         public static void OnUserPositionEvent(UserPositionEventArgs e)
       
   563         {
       
   564             if (UserPositionEvent != null)
       
   565                 UserPositionEvent(new object(), e);
       
   566         }
       
   567     }
       
   568 }