Browse Source

Send Touchevents to client

jost_vincent.schultz 11 years ago
parent
commit
17df65d822
2 changed files with 65 additions and 10 deletions
  1. 36 10
      bbiwarg/Server/TUIO/TuioServer.cs
  2. 29 0
      bbiwarg/VideoHandle.cs

+ 36 - 10
bbiwarg/Server/TUIO/TuioServer.cs

@@ -13,25 +13,34 @@ namespace TUIO
     {
         const int MAX_PACKET_SIZE = 65535 - 8;
 
-        OSCTransmitter transmitter = null;
-        String host = "127.0.0.1";
-        int port = 3333;
+        private OSCTransmitter transmitter = null;
+        private String host = "127.0.0.1";
+        private int port = 3333;
+        private long sessionID = 0;
+        private TuioTime currentFrameTime;
 
-        List<TuioCursor> cursorList = new List<TuioCursor>();
-        List<TuioCursor> updatedCursorList;
+        private List<TuioCursor> cursorList;
+        private List<TuioCursor> updatedCursorList;
 
-        public TuioServer() { transmitter = new OSCTransmitter(host, port); }
+        public TuioServer() { init(); }
 
         public TuioServer(int port)
         {
             this.port = port;
-            transmitter = new OSCTransmitter(host, port);
+            init();
         }
 
         public TuioServer(String host, int port)
         {
             this.host = host;
             this.port = port;
+            init();
+        }
+
+        private void init()
+        {
+            TuioTime.initSession();
+            cursorList = new List<TuioCursor>();
             transmitter = new OSCTransmitter(host, port);
         }
 
@@ -43,19 +52,35 @@ namespace TUIO
 
         public TuioCursor addTuioCursor(float x, float y)
         {
-            TuioCursor tcur = new TuioCursor(cursorList.Count, cursorList.Count, x, y);
+            TuioCursor tcur = new TuioCursor(sessionID, cursorList.Count, x, y);
             cursorList.Add(tcur);
             updatedCursorList.Add(tcur);
+
+            sessionID++;
             return tcur;
         }
 
         public void updateTuioCursor(TuioCursor tcur, float xp, float yp)
         {
-            tcur.update(new TuioTime(0, 0), xp, yp);
+            tcur.update(currentFrameTime, xp, yp);
             if (!updatedCursorList.Contains(tcur))
                 updatedCursorList.Add(tcur);
         }
 
+        public void updateTuioCursor(long s_id, float xp, float yp)
+        {
+            TuioCursor tcur;
+            for (int i = 0; i < cursorList.Count; i++)
+            {
+                tcur = cursorList[i];
+                if (tcur.getSessionID() == s_id)
+                {
+                    updateTuioCursor(tcur, xp, yp);
+                    return;
+                }
+            }
+        }
+
         public void removeTuioCursor(TuioCursor tcur)
         {
             cursorList.Remove(tcur);
@@ -64,6 +89,7 @@ namespace TUIO
 
         public void initFrame()
         {
+            currentFrameTime = TuioTime.getSessionTime();
             updatedCursorList = new List<TuioCursor>();
         }
 
@@ -91,7 +117,7 @@ namespace TUIO
                 currentMessage.Append("set");
                 currentMessage.Append((int)cursor.getSessionID());
                 currentMessage.Append((float)cursor.getX());
-                currentMessage.Append((float)cursor.getY()); 
+                currentMessage.Append((float)cursor.getY());
                 currentMessage.Append((float)cursor.getXSpeed());
                 currentMessage.Append((float)cursor.getYSpeed());
                 currentMessage.Append((float)cursor.getMotionAccel());

+ 29 - 0
bbiwarg/VideoHandle.cs

@@ -15,6 +15,7 @@ using bbiwarg.InputProviders;
 using Emgu.CV;
 using Emgu.CV.Structure;
 using bbiwarg.Graphics;
+using TUIO;
 
 namespace bbiwarg
 {
@@ -23,6 +24,9 @@ namespace bbiwarg
         private IInputProvider inputProvider;
         private InputFrame inputFrame;
 
+        private TuioServer server;
+        private TuioCursor currentTouchevent;
+
         public int Width { get; private set; }
         public int Height { get; private set; }
 
@@ -69,11 +73,14 @@ namespace bbiwarg
             inputProvider.start();
             inputProvider.updateFrame();
             processFrameUpdate();
+
+            server = new TuioServer("127.0.0.1", 3333);
         }
 
         public void stop()
         {
             inputProvider.stop();
+            server.close();
         }
 
         public bool sourceIsMovie()
@@ -201,6 +208,28 @@ namespace bbiwarg
             touchTracker.setDetectedTouchEventsThisFrame(touchDetector.TouchEvents, OutputImages[3]);
             Timer.stop("touchTracking");
 
+
+            //send touchevent
+            if (palmTouchDetector != null)
+            {
+                server.initFrame();
+                if (palmTouchDetector.PalmTouchEvents.Count == 1)
+                {
+                    PalmTouchEvent touchEvent = palmTouchDetector.PalmTouchEvents[0];
+                    if (currentTouchevent == null)
+                        currentTouchevent = server.addTuioCursor(touchEvent.RelativePalmPosition.X, touchEvent.RelativePalmPosition.Y);
+                    else
+                        server.updateTuioCursor(currentTouchevent, touchEvent.RelativePalmPosition.X, touchEvent.RelativePalmPosition.Y);
+                }
+                else if (currentTouchevent != null)
+                {
+                    server.removeTuioCursor(currentTouchevent);
+                    currentTouchevent = null;
+                }
+                server.commitFrame();
+            }
+
+
             // touch event visualizer
             if (touchEventVisualizer == null)
                 touchEventVisualizer = new TouchEventVisualizer(Width, Height);