1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Net;
- using System.Net.Sockets;
- using bbiwarg.Recognition.TouchRecognition;
- using bbiwarg.Utility;
- using TUIO;
- namespace bbiwarg.Server
- {
- class TuioCommunicator
- {
- private TuioServer server;
- private Dictionary<int, TuioCursor> cursors;
- public TuioCommunicator(string host, int port)
- {
- server = new TuioServer(host, port);
- cursors = new Dictionary<int, TuioCursor>();
- }
- public void touchDown(object sender, TouchEventArgs tea)
- {
- TuioCursor cursor = server.addTuioCursor(tea.RelativePosition.X, tea.RelativePosition.Y);
- cursors.Add(tea.TrackID, cursor);
- }
- public void touchMove(object sender, TouchEventArgs tea)
- {
- server.updateTuioCursor(cursors[tea.TrackID], tea.RelativePosition.X, tea.RelativePosition.Y);
- }
- public void touchUp(object sender, TouchEventArgs tea)
- {
- server.removeTuioCursor(cursors[tea.TrackID]);
- cursors.Remove(tea.TrackID);
- }
- public void close()
- {
- server.close();
- }
- public void initFrame()
- {
- server.initFrame();
- }
- public void commitFrame()
- {
- server.commitFrame();
- }
- public void reset()
- {
- foreach (int id in cursors.Keys)
- {
- server.removeTuioCursor(cursors[id]);
- }
- cursors.Clear();
- }
- public static bool tryParseIPAddress(String ipString, out IPAddress ipAddress) {
- return (IPAddress.TryParse(ipString, out ipAddress) && ipAddress.AddressFamily == AddressFamily.InterNetwork);
- }
- public static bool tryParsePort(String portString, out Int16 port) {
- return Int16.TryParse(portString, out port);
- }
- }
- }
|