equal
deleted
inserted
replaced
65 public delegate void PushHandler(object o, PushEventArgs e); |
65 public delegate void PushHandler(object o, PushEventArgs e); |
66 //Il s'agit de la fonction permettant d'appeler les fonctions des événements Jump. |
66 //Il s'agit de la fonction permettant d'appeler les fonctions des événements Jump. |
67 public delegate void JumpHandler(object o, JumpEventArgs e); |
67 public delegate void JumpHandler(object o, JumpEventArgs e); |
68 //Il s'agit de la fonction permettant d'appeler les fonctions des événements de proximité. |
68 //Il s'agit de la fonction permettant d'appeler les fonctions des événements de proximité. |
69 public delegate void UserPositionHandler(object o, UserPositionEventArgs e); |
69 public delegate void UserPositionHandler(object o, UserPositionEventArgs e); |
|
70 //Il s'agit de la fonctoin permettant de notifier le serveur en cas de changement de mode. |
|
71 public delegate void ModChangeHandler(object o, ModChangeEventArgs e); |
70 |
72 |
71 public class KinectMain |
73 public class KinectMain |
72 { |
74 { |
73 //Gestionnaire de ressources. |
75 //Gestionnaire de ressources. |
74 private ResourceManager rm; |
76 private ResourceManager rm; |
92 private float minDistHands; |
94 private float minDistHands; |
93 private float maxDistHands; |
95 private float maxDistHands; |
94 private float minDist; |
96 private float minDist; |
95 private float maxDist; |
97 private float maxDist; |
96 private float zeroPoint; |
98 private float zeroPoint; |
|
99 private int imagesToShow; |
97 |
100 |
98 //Temps de rafraichissement pour le timer (Détection de gesture dans le serveur TUIO). |
101 //Temps de rafraichissement pour le timer (Détection de gesture dans le serveur TUIO). |
99 private int timerElapsing; |
102 private int timerElapsing; |
100 |
103 |
101 //Serveur TUIO pour la connexion du Middleware vers le Front Atelier. |
104 //Serveur TUIO pour la connexion du Middleware vers le Front Atelier. |
112 public static event PushHandler PushEvent; |
115 public static event PushHandler PushEvent; |
113 //L'événement jump. |
116 //L'événement jump. |
114 public static event JumpHandler JumpEvent; |
117 public static event JumpHandler JumpEvent; |
115 //L'événement l'utilisateur se déplace dans la zone de détection. |
118 //L'événement l'utilisateur se déplace dans la zone de détection. |
116 public static event UserPositionHandler UserPositionEvent; |
119 public static event UserPositionHandler UserPositionEvent; |
|
120 //L'événement on change de mode. |
|
121 public static event ModChangeHandler ModChangeEvent; |
117 |
122 |
118 private string connexionHost; |
123 private string connexionHost; |
119 private int connexionPort; |
124 private int connexionPort; |
120 |
125 |
121 /* |
126 /* |
140 maxDist = 4.0f; |
145 maxDist = 4.0f; |
141 zeroPoint = 1.7f; |
146 zeroPoint = 1.7f; |
142 connexionHost = "127.0.0.1"; |
147 connexionHost = "127.0.0.1"; |
143 connexionPort = 80; |
148 connexionPort = 80; |
144 timerElapsing = 1000; |
149 timerElapsing = 1000; |
|
150 imagesToShow = 25; |
145 } |
151 } |
146 |
152 |
147 //On crée la fenêtre de debug. |
153 //On crée la fenêtre de debug. |
148 debug = new Debug.DebugWindow(this); |
154 debug = new Debug.DebugWindow(this); |
149 |
155 |
236 JumpEvent += new JumpHandler(jumpListener.ShowOnScreen); |
242 JumpEvent += new JumpHandler(jumpListener.ShowOnScreen); |
237 |
243 |
238 //Fonction appelée lorsque l'utilisateur se déplace dans la zone de détection. |
244 //Fonction appelée lorsque l'utilisateur se déplace dans la zone de détection. |
239 UserPositionListener userPositionListener = new UserPositionListener(); |
245 UserPositionListener userPositionListener = new UserPositionListener(); |
240 UserPositionEvent += new UserPositionHandler(userPositionListener.ShowOnScreen); |
246 UserPositionEvent += new UserPositionHandler(userPositionListener.ShowOnScreen); |
|
247 |
|
248 //Fonction appelée lorsqu'on change de mode. |
|
249 ModChangeListener modChangeListener = new ModChangeListener(); |
|
250 ModChangeEvent += new ModChangeHandler(modChangeListener.ShowOnScreen); |
241 |
251 |
242 //On connecte le serveur à l'adresse locale sur le port 80. |
252 //On connecte le serveur à l'adresse locale sur le port 80. |
243 server = new Server(connexionHost, connexionPort, timerElapsing, debug); |
253 server = new Server(connexionHost, connexionPort, timerElapsing, debug); |
244 } |
254 } |
245 |
255 |
445 //Si l'utilisateur se déplace dans la zone de détection. |
455 //Si l'utilisateur se déplace dans la zone de détection. |
446 //On traite le problème en plusieurs limites, on discrétise la zone. |
456 //On traite le problème en plusieurs limites, on discrétise la zone. |
447 if (first.TrackingState == SkeletonTrackingState.Tracked) |
457 if (first.TrackingState == SkeletonTrackingState.Tracked) |
448 { |
458 { |
449 float proximity = userPositionDetector.CalcProximity(first.Position.Z); |
459 float proximity = userPositionDetector.CalcProximity(first.Position.Z); |
|
460 int numberOfImages = userPositionDetector.ImagesToShow(proximity, imagesToShow); |
450 |
461 |
451 if (proximity > 0f) |
462 if (proximity > 0f) |
452 { |
463 { |
453 UserPositionEventArgs userPositionEvent = new UserPositionEventArgs(debug, server, proximity); |
464 UserPositionEventArgs userPositionEvent = new UserPositionEventArgs(debug, server, proximity, numberOfImages); |
454 OnUserPositionEvent(userPositionEvent); |
465 OnUserPositionEvent(userPositionEvent); |
455 } |
466 } |
456 else |
467 else |
457 { |
468 { |
458 Console.Out.WriteLine("FAIL"); |
|
459 debug.hideSkeleton(); |
469 debug.hideSkeleton(); |
460 } |
470 } |
461 } |
471 } |
462 |
472 |
463 //Dessine le squelette dans le debug. |
473 //Dessine le squelette dans le debug. |
545 */ |
555 */ |
546 public static void OnUserPositionEvent(UserPositionEventArgs e) |
556 public static void OnUserPositionEvent(UserPositionEventArgs e) |
547 { |
557 { |
548 if (UserPositionEvent != null) |
558 if (UserPositionEvent != null) |
549 UserPositionEvent(new object(), e); |
559 UserPositionEvent(new object(), e); |
|
560 } |
|
561 |
|
562 /* |
|
563 * Initialise l'événement et fait appel aux fonctions du listener quand on change de mode. |
|
564 */ |
|
565 public static void OnModChangeEvent(ModChangeEventArgs e) |
|
566 { |
|
567 if (ModChangeEvent != null) |
|
568 ModChangeEvent(new object(), e); |
550 } |
569 } |
551 |
570 |
552 /* |
571 /* |
553 * Méthode de chargement des paramètres (position du champ de recherche...). |
572 * Méthode de chargement des paramètres (position du champ de recherche...). |
554 */ |
573 */ |
562 maxDist = (float)double.Parse(ConfigurationManager.AppSettings["maxDistance"]); |
581 maxDist = (float)double.Parse(ConfigurationManager.AppSettings["maxDistance"]); |
563 zeroPoint = (float)double.Parse(ConfigurationManager.AppSettings["zeroPoint"]); |
582 zeroPoint = (float)double.Parse(ConfigurationManager.AppSettings["zeroPoint"]); |
564 connexionHost = ConfigurationManager.AppSettings["connexionHost"]; |
583 connexionHost = ConfigurationManager.AppSettings["connexionHost"]; |
565 connexionPort = int.Parse(ConfigurationManager.AppSettings["connexionPort"]); |
584 connexionPort = int.Parse(ConfigurationManager.AppSettings["connexionPort"]); |
566 timerElapsing = int.Parse(ConfigurationManager.AppSettings["timerElapsing"]); |
585 timerElapsing = int.Parse(ConfigurationManager.AppSettings["timerElapsing"]); |
|
586 imagesToShow = int.Parse(ConfigurationManager.AppSettings["imagesToShow"]); |
567 } |
587 } |
568 catch (Exception) |
588 catch (Exception) |
569 { |
589 { |
570 return false; |
590 return false; |
571 } |
591 } |
572 |
592 |
573 if (maxDistHands <= 0f || minDistHands <= 0f || maxDistHands > maxDist || minDistHands > maxDist || |
593 if (maxDistHands <= 0f || minDistHands <= 0f || maxDistHands > maxDist || minDistHands > maxDist || |
574 minDistHands >= maxDistHands || zeroPoint < maxDistHands || minDistHands < minDist || |
594 minDistHands >= maxDistHands || zeroPoint < maxDistHands || minDistHands < minDist || |
575 zeroPoint >= maxDist || connexionPort < 0 || timerElapsing < 0) |
595 zeroPoint >= maxDist || connexionPort < 0 || timerElapsing < 0 || imagesToShow < 1) |
576 { |
596 { |
577 debug.ExceptionLbl.Content = rm.GetString("loadParametersIncorrect"); |
597 debug.ExceptionLbl.Content = rm.GetString("loadParametersIncorrect"); |
578 return false; |
598 return false; |
579 } |
599 } |
580 return true; |
600 return true; |
604 config.AppSettings.Settings.Add("connexionHost", connexionHost); |
624 config.AppSettings.Settings.Add("connexionHost", connexionHost); |
605 config.AppSettings.Settings.Remove("connexionPort"); |
625 config.AppSettings.Settings.Remove("connexionPort"); |
606 config.AppSettings.Settings.Add("connexionPort", connexionPort.ToString()); |
626 config.AppSettings.Settings.Add("connexionPort", connexionPort.ToString()); |
607 config.AppSettings.Settings.Remove("timerElapsing"); |
627 config.AppSettings.Settings.Remove("timerElapsing"); |
608 config.AppSettings.Settings.Add("timerElapsing", timerElapsing.ToString()); |
628 config.AppSettings.Settings.Add("timerElapsing", timerElapsing.ToString()); |
|
629 config.AppSettings.Settings.Remove("imagesToShow"); |
|
630 config.AppSettings.Settings.Add("imagesToShow", imagesToShow.ToString()); |
609 |
631 |
610 //Sauvegarde la configuration. |
632 //Sauvegarde la configuration. |
611 config.Save(ConfigurationSaveMode.Modified); |
633 config.Save(ConfigurationSaveMode.Modified); |
612 ConfigurationManager.RefreshSection("appSettings"); |
634 ConfigurationManager.RefreshSection("appSettings"); |
613 } |
635 } |
621 } |
643 } |
622 public void setMaxDistHands(float max) |
644 public void setMaxDistHands(float max) |
623 { |
645 { |
624 maxDistHands = max; |
646 maxDistHands = max; |
625 } |
647 } |
|
648 public void setMinDist(float min) |
|
649 { |
|
650 minDist = min; |
|
651 } |
|
652 public void setMaxDist(float max) |
|
653 { |
|
654 maxDist = max; |
|
655 } |
|
656 public void setZeroPoint(float zero) |
|
657 { |
|
658 zeroPoint = zero; |
|
659 } |
626 public void setConnexionHost(String host) |
660 public void setConnexionHost(String host) |
627 { |
661 { |
628 connexionHost = host; |
662 connexionHost = host; |
629 } |
663 } |
630 public void setConnexionPort(int port) |
664 public void setConnexionPort(int port) |
633 } |
667 } |
634 public void setTimerElapsing(int time) |
668 public void setTimerElapsing(int time) |
635 { |
669 { |
636 timerElapsing = time; |
670 timerElapsing = time; |
637 } |
671 } |
|
672 public void setImagesToShow(int _imagesToShow) |
|
673 { |
|
674 imagesToShow = _imagesToShow; |
|
675 } |
638 |
676 |
639 public float getMinDistHands() |
677 public float getMinDistHands() |
640 { |
678 { |
641 return minDistHands; |
679 return minDistHands; |
642 } |
680 } |
643 public float getMaxDistHands() |
681 public float getMaxDistHands() |
644 { |
682 { |
645 return maxDistHands; |
683 return maxDistHands; |
646 } |
684 } |
|
685 public float getMinDist() |
|
686 { |
|
687 return minDist; |
|
688 } |
|
689 public float getMaxDist() |
|
690 { |
|
691 return maxDist; |
|
692 } |
|
693 public float getZeroPoint() |
|
694 { |
|
695 return zeroPoint; |
|
696 } |
647 public String getConnexionHost() |
697 public String getConnexionHost() |
648 { |
698 { |
649 return connexionHost; |
699 return connexionHost; |
650 } |
700 } |
651 public int getConnexionPort() |
701 public int getConnexionPort() |
653 return connexionPort; |
703 return connexionPort; |
654 } |
704 } |
655 public int getTimerElapsing() |
705 public int getTimerElapsing() |
656 { |
706 { |
657 return timerElapsing; |
707 return timerElapsing; |
|
708 } |
|
709 public int getImagesToShow() |
|
710 { |
|
711 return imagesToShow; |
658 } |
712 } |
659 } |
713 } |
660 } |
714 } |