TuioCommunicator.cs 2.0 KB

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