/** * The TuioClient starts listening to TUIO messages on the configured UDP port * All reveived TUIO messages are decoded and the resulting TUIO events are broadcasted to all registered TuioListeners */ public void connect() { TuioTime.initSession(); currentTime = new TuioTime(); currentTime.reset(); try { receiver = new OSCReceiver(port); thread = new Thread(new ThreadStart(listen)); thread.Start(); connected = true; } catch (Exception e) { Console.WriteLine("failed to connect to port " + port); Console.WriteLine(e.Message); } }
/** * The TuioClient starts listening to TUIO messages on the configured UDP port * All reveived TUIO messages are decoded and the resulting TUIO events are broadcasted to all registered TuioListeners */ public void connect() { TuioTime.initSession(); currentTime = new TuioTime(); currentTime.reset(); receiver = new OSCReceiver(port); thread = new Thread(new ThreadStart(listen)); // HACK : Set listener thread to background added by frog (@rktut) thread.IsBackground = true; thread.Start(); connected = true; // HACK : Swallowed exception removed by frog (@rktut) }
/** * The TuioClient starts listening to TUIO messages on the configured UDP port * All reveived TUIO messages are decoded and the resulting TUIO events are broadcasted to all registered TuioListeners */ public void connect() { // Debug.Log ("tuio client before init session"); TuioTime.initSession(); currentTime = new TuioTime(); currentTime.reset(); try { receiver = new OSCReceiver(port); connected = true; statusString = "Thread Started"; thread = new Thread(new ThreadStart(listen)); // Debug.Log("tuio client before thread start"); thread.Start(); } catch (Exception e) { Console.WriteLine("failed to connect to port " + port); Console.WriteLine(e.Message); statusString = "failed to connect to port " + port + " " + e.Message; // Debug.Log("ERROR: there was an error trying to connect tuio client"); // Debug.Log(e.Message); } }
/** * The TuioClient starts listening to TUIO messages on the configured UDP port * All reveived TUIO messages are decoded and the resulting TUIO events are broadcasted to all registered TuioListeners */ public void connect() { TuioTime.initSession(); currentTime = new TuioTime(); currentTime.reset(); try { receiver = new OSCReceiver(port); thread = new Thread(new ThreadStart(listen)); thread.Start(); connected = true; } catch (Exception e) { Console.WriteLine("failed to connect to port "+port); Console.WriteLine(e.Message); } }
/** * The OSC callback method where all TUIO messages are received and decoded * and where the TUIO event callbacks are dispatched * * @param message the received OSC message */ private void processMessage(OSCMessage message) { string address = message.Address; ArrayList args = message.Values; string command = (string)args[0]; if (address == "/tuio/2Dobj") { if (command == "set") { if (currentTime.getTotalMilliseconds() == 0) { currentTime = TuioTime.getSessionTime(); } long s_id = (int)args[1]; int f_id = (int)args[2]; float x = (float)args[3]; float y = (float)args[4]; float a = (float)args[5]; float X = (float)args[6]; float Y = (float)args[7]; float A = (float)args[8]; float m = (float)args[9]; float r = (float)args[10]; if (!objectList.ContainsKey(s_id)) { TuioObject addObject = new TuioObject(currentTime, s_id, f_id, x, y, a); objectList.Add(s_id, addObject); for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.addTuioObject(addObject); } } } else { TuioObject updateObject = objectList[s_id]; if ((updateObject.getX() != x) || (updateObject.getY() != y) || (updateObject.getAngle() != a)) { TuioObject tobj = new TuioObject(currentTime, s_id, updateObject.getSymbolID(), x, y, a); tobj.update(currentTime, x, y, a, X, Y, A, m, r); frameObjects.Add(tobj); /*updateObject.update(currentTime,x,y,a,X,Y,A,m,r); * for (int i=0;i<listenerList.Count;i++) { * TuioListener listener = (TuioListener)listenerList[i]; * if (listener!=null) listener.updateTuioObject(updateObject); * }*/ //objectList[s_id] = tobj; } } } else if (command == "alive") { for (int i = 1; i < args.Count; i++) { // get the message content long s_id = (int)args[i]; newObjectList.Add(s_id); // reduce the object list to the lost objects if (aliveObjectList.Contains(s_id)) { aliveObjectList.Remove(s_id); } } // remove the remaining objects for (int i = 0; i < aliveObjectList.Count; i++) { long s_id = aliveObjectList[i]; TuioObject removeObject = objectList[s_id]; removeObject.remove(currentTime); objectList.Remove(s_id); for (int j = 0; j < listenerList.Count; j++) { TuioListener listener = (TuioListener)listenerList[j]; if (listener != null) { listener.removeTuioObject(removeObject); } } } List <long> buffer = aliveObjectList; aliveObjectList = newObjectList; // recycling of the List newObjectList = buffer; newObjectList.Clear(); } else if (command == "fseq") { int fseq = (int)args[1]; bool lateFrame = false; if (fseq > 0) { if ((fseq >= currentFrame) || ((currentFrame - fseq) > 100)) { currentFrame = fseq; } else { lateFrame = true; } } if (!lateFrame) { IEnumerator <TuioObject> frameEnum = frameObjects.GetEnumerator(); while (frameEnum.MoveNext()) { TuioObject tobj = frameEnum.Current; TuioObject updateObject = getTuioObject(tobj.getSessionID()); updateObject.update(currentTime, tobj.getX(), tobj.getY(), tobj.getAngle(), tobj.getXSpeed(), tobj.getYSpeed(), tobj.getRotationSpeed(), tobj.getMotionAccel(), tobj.getRotationAccel()); for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.updateTuioObject(updateObject); } } } for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.refresh(currentTime); } } if (fseq > 0) { currentTime.reset(); } } frameObjects.Clear(); } } else if (address == "/tuio/2Dcur") { if (command == "set") { if (currentTime.getTotalMilliseconds() == 0) { currentTime = TuioTime.getSessionTime(); } long s_id = (int)args[1]; float x = (float)args[2]; float y = (float)args[3]; float X = (float)args[4]; float Y = (float)args[5]; float m = (float)args[6]; if (!cursorList.ContainsKey(s_id)) { int f_id = cursorList.Count; if (cursorList.Count <= maxFingerID) { TuioCursor closestCursor = freeCursorList[0]; IEnumerator <TuioCursor> testList = freeCursorList.GetEnumerator(); while (testList.MoveNext()) { TuioCursor testCursor = testList.Current; if (testCursor.getDistance(x, y) < closestCursor.getDistance(x, y)) { closestCursor = testCursor; } } f_id = closestCursor.getCursorID(); freeCursorList.Remove(closestCursor); } else { maxFingerID = f_id; } TuioCursor addCursor = new TuioCursor(currentTime, s_id, f_id, x, y); cursorList.Add(s_id, addCursor); for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.addTuioCursor(addCursor); } } } else { TuioCursor updateCursor = (TuioCursor)cursorList[s_id]; if ((updateCursor.getX() != x) || (updateCursor.getY() != y)) { TuioCursor tcur = new TuioCursor(currentTime, s_id, updateCursor.getCursorID(), x, y); tcur.update(currentTime, x, y, X, Y, m); frameCursors.Add(tcur); /*updateCursor.update(currentTime,x,y,X,Y,m); * for (int i=0;i<listenerList.Count;i++) { * TuioListener listener = (TuioListener)listenerList[i]; * if (listener!=null) listener.updateTuioCursor(updateCursor); * }*/ //cursorList[s_id] = tcur; } } } else if (command == "alive") { for (int i = 1; i < args.Count; i++) { // get the message content long s_id = (int)args[i]; newCursorList.Add(s_id); // reduce the cursor list to the lost cursors if (aliveCursorList.Contains(s_id)) { aliveCursorList.Remove(s_id); } } // remove the remaining cursors for (int i = 0; i < aliveCursorList.Count; i++) { long s_id = aliveCursorList[i]; if (!cursorList.ContainsKey(s_id)) { continue; } TuioCursor removeCursor = cursorList[s_id]; int c_id = removeCursor.getCursorID(); cursorList.Remove(s_id); removeCursor.remove(currentTime); if (c_id == maxFingerID) { maxFingerID = -1; if (cursorList.Count > 0) { IEnumerator <KeyValuePair <long, TuioCursor> > clist = cursorList.GetEnumerator(); while (clist.MoveNext()) { int f_id = clist.Current.Value.getCursorID(); if (f_id > maxFingerID) { maxFingerID = f_id; } } List <TuioCursor> freeCursorBuffer = new List <TuioCursor>(); IEnumerator <TuioCursor> flist = freeCursorList.GetEnumerator(); while (flist.MoveNext()) { TuioCursor testCursor = flist.Current; if (testCursor.getCursorID() < maxFingerID) { freeCursorBuffer.Add(testCursor); } } freeCursorList = freeCursorBuffer; } } else if (c_id < maxFingerID) { freeCursorList.Add(removeCursor); } for (int j = 0; j < listenerList.Count; j++) { TuioListener listener = (TuioListener)listenerList[j]; if (listener != null) { listener.removeTuioCursor(removeCursor); } } } List <long> buffer = aliveCursorList; aliveCursorList = newCursorList; // recycling of the List newCursorList = buffer; newCursorList.Clear(); } else if (command == "fseq") { int fseq = (int)args[1]; bool lateFrame = false; if (fseq > 0) { if ((fseq >= currentFrame) || ((currentFrame - fseq) > 100)) { currentFrame = fseq; } else { lateFrame = true; } } if (!lateFrame) { IEnumerator <TuioCursor> frameEnum = frameCursors.GetEnumerator(); while (frameEnum.MoveNext()) { TuioCursor tcur = frameEnum.Current; TuioCursor updateCursor = getTuioCursor(tcur.getSessionID()); updateCursor.update(currentTime, tcur.getX(), tcur.getY(), tcur.getXSpeed(), tcur.getYSpeed(), tcur.getMotionAccel()); for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.updateTuioCursor(updateCursor); } } } for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.refresh(currentTime); } } if (fseq > 0) { currentTime.reset(); } } frameCursors.Clear(); } } }
/*