TuioCommunicator.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using bbiwarg.Recognition.TouchRecognition;
  7. using bbiwarg.Utility;
  8. using TUIO;
  9. namespace bbiwarg.Server
  10. {
  11. class TuioCommunicator
  12. {
  13. private TuioServer server;
  14. private Dictionary<int, TuioCursor> cursors;
  15. public TuioCommunicator(string host, int port)
  16. {
  17. server = new TuioServer(host, port);
  18. cursors = new Dictionary<int, TuioCursor>();
  19. }
  20. public void touchDown(object sender, TouchEventArgs tea)
  21. {
  22. TuioCursor cursor = server.addTuioCursor(tea.RelativePosition.X, tea.RelativePosition.Y);
  23. cursors.Add(tea.TrackID, cursor);
  24. }
  25. public void touchMove(object sender, TouchEventArgs tea)
  26. {
  27. server.updateTuioCursor(cursors[tea.TrackID], tea.RelativePosition.X, tea.RelativePosition.Y);
  28. }
  29. public void touchUp(object sender, TouchEventArgs tea)
  30. {
  31. server.removeTuioCursor(cursors[tea.TrackID]);
  32. cursors.Remove(tea.TrackID);
  33. }
  34. public void close()
  35. {
  36. server.close();
  37. }
  38. public void initFrame()
  39. {
  40. server.initFrame();
  41. }
  42. public void commitFrame()
  43. {
  44. server.commitFrame();
  45. }
  46. public void reset()
  47. {
  48. foreach (int id in cursors.Keys)
  49. {
  50. server.removeTuioCursor(cursors[id]);
  51. }
  52. cursors.Clear();
  53. }
  54. }
  55. }