TuioCommunicator.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. server = new TuioServer(host, port);
  17. cursors = new Dictionary<int, TuioCursor>();
  18. }
  19. public void touchDown(object sender, PalmTouchEventArgs ptea) {
  20. TuioCursor cursor = server.addTuioCursor(ptea.Position.X, ptea.Position.Y);
  21. cursors.Add(ptea.TrackID, cursor);
  22. }
  23. public void touchMove(object sender, PalmTouchEventArgs ptea) {
  24. server.updateTuioCursor(cursors[ptea.TrackID], ptea.Position.X, ptea.Position.Y);
  25. }
  26. public void touchUp(object sender, PalmTouchEventArgs ptea) {
  27. server.removeTuioCursor(cursors[ptea.TrackID]);
  28. cursors.Remove(ptea.TrackID);
  29. }
  30. public void close() {
  31. server.close();
  32. }
  33. public void initFrame() {
  34. server.initFrame();
  35. }
  36. public void commitFrame() {
  37. server.commitFrame();
  38. }
  39. public void reset() {
  40. foreach (int id in cursors.Keys) {
  41. server.removeTuioCursor(cursors[id]);
  42. }
  43. cursors.Clear();
  44. }
  45. }
  46. }