/** * This constructor takes a TuioTime object and two floating point coordinate arguments and sets * its coordinate attributes to these values and its time stamp to the provided TUIO time object. * * @param ttime the TuioTime to assign * @param xp the X coordinate to assign * @param yp the Y coordinate to assign */ public TuioPoint(TuioTime ttime, float xp, float yp) { xpos = xp; ypos = yp; currentTime = new TuioTime(ttime); startTime = new TuioTime(currentTime); }
/** * This constructor takes a TuioTime argument and assigns it along with the provided * Session ID, Symbol ID, X and Y coordinate and angle to the newly created TuioObject. * * @param ttime the TuioTime to assign * @param si the Session ID to assign * @param sym the Symbol ID to assign * @param xp the X coordinate to assign * @param yp the Y coordinate to assign * @param a the angle to assign */ public TuioObject(TuioTime ttime, long si, int sym, float xp, float yp, float a) : base(ttime, si, xp, yp) { symbol_id = sym; angle = a; rotation_speed = 0.0f; rotation_accel = 0.0f; }
/** * The default constructor takes no arguments and sets * its coordinate attributes to zero and its time stamp to the current session time. */ public TuioPoint() { xpos = 0.0f; ypos = 0.0f; currentTime = TuioTime.getSessionTime(); startTime = new TuioTime(currentTime); }
/** * Takes a TuioTime argument and assigns it along with the provided * X and Y coordinate and angle to the private TuioObject attributes. * The speed and accleration values are calculated accordingly. * * @param ttime the TuioTime to assign * @param xp the X coordinate to assign * @param yp the Y coordinate to assign * @param a the angle coordinate to assign */ public void update(TuioTime ttime, float xp, float yp, float a) { TuioPoint lastPoint = path[path.Count - 1]; base.update(ttime, xp, yp); TuioTime diffTime = currentTime - lastPoint.getTuioTime(); float dt = diffTime.getTotalMilliseconds() / 1000.0f; float last_angle = angle; float last_rotation_speed = rotation_speed; angle = a; float da = (angle - last_angle) / (2.0f * (float)Math.PI); if (da > 0.75f) { da -= 1.0f; } else if (da < -0.75f) { da += 1.0f; } rotation_speed = da / dt; rotation_accel = (rotation_speed - last_rotation_speed) / dt; if ((rotation_accel != 0) && (state != TUIO_STOPPED)) { state = TUIO_ROTATING; } }
/** * This constructor takes two floating point coordinate arguments and sets * its coordinate attributes to these values and its time stamp to the current session time. * * @param xp the X coordinate to assign * @param yp the Y coordinate to assign */ public TuioPoint(float xp, float yp) { xpos = xp; ypos = yp; currentTime = TuioTime.getSessionTime(); startTime = new TuioTime(currentTime); }
/** * This constructor takes a TuioPoint argument and sets its coordinate attributes * to the coordinates of the provided TuioPoint and its time stamp to the current session time. * * @param tpoint the TuioPoint to assign */ public TuioPoint(TuioPoint tpoint) { xpos = tpoint.getX(); ypos = tpoint.getY(); currentTime = TuioTime.getSessionTime(); startTime = new TuioTime(currentTime); }
/** * This static method globally resets the TUIO session time. */ public static void initSession() { TuioTime startTime = getSystemTime(); start_seconds = startTime.getSeconds(); start_micro_seconds = startTime.getMicroseconds(); }
/** * Takes a TuioTime argument and assigns it along with the provided * X and Y coordinate to the private TuioContainer attributes. * The speed and accleration values are calculated accordingly. * * @param ttime the TuioTime to assign * @param xp the X coordinate to assign * @param yp the Y coordinate to assign */ public new void update(TuioTime ttime, float xp, float yp) { TuioPoint lastPoint = path[path.Count - 1]; base.update(ttime, xp, yp); TuioTime diffTime = currentTime - lastPoint.getTuioTime(); float dt = diffTime.getTotalMilliseconds() / 1000.0f; float dx = this.xpos - lastPoint.getX(); float dy = this.ypos - lastPoint.getY(); float dist = (float)Math.Sqrt(dx * dx + dy * dy); float last_motion_speed = this.motion_speed; this.x_speed = dx / dt; this.y_speed = dy / dt; this.motion_speed = dist / dt; this.motion_accel = (motion_speed - last_motion_speed) / dt; path.Add(new TuioPoint(currentTime, xpos, ypos)); if (motion_accel > 0) { state = TUIO_ACCELERATING; } else if (motion_accel < 0) { state = TUIO_DECELERATING; } else { state = TUIO_STOPPED; } }
/** * Takes a TuioTime argument and assigns it along with the provided * X and Y coordinate, angle, X and Y velocity, motion acceleration, * rotation speed and rotation acceleration to the private TuioObject attributes. * * @param ttime the TuioTime to assign * @param xp the X coordinate to assign * @param yp the Y coordinate to assign * @param a the angle coordinate to assign * @param xs the X velocity to assign * @param ys the Y velocity to assign * @param rs the rotation velocity to assign * @param ma the motion acceleration to assign * @param ra the rotation acceleration to assign */ public void update(TuioTime ttime, float xp, float yp, float a, float xs, float ys, float rs, float ma, float ra) { base.update(ttime, xp, yp, xs, ys, ma); angle = a; rotation_speed = rs; rotation_accel = ra; if ((rotation_accel != 0) && (state != TUIO_STOPPED)) { state = TUIO_ROTATING; } }
/** * Takes a TuioTime argument and compares the provided TuioTime to the private Seconds and Microseconds attributes. * * @param ttime the TuioTime to compare * @return true if the two TuioTime have equal Seconds and Microseconds attributes */ public bool Equals(TuioTime ttime) { if ((seconds == ttime.getSeconds()) && (micro_seconds == ttime.getMicroseconds())) { return(true); } else { return(false); } }
/** * This constructor takes a TuioTime argument and assigns it along with the provided * Session ID, X and Y coordinate to the newly created TuioContainer. * * @param ttime the TuioTime to assign * @param si the Session ID to assign * @param xp the X coordinate to assign * @param yp the Y coordinate to assign */ public TuioContainer(TuioTime ttime, long si, float xp, float yp) : base(ttime, xp, yp) { session_id = si; x_speed = 0.0f; y_speed = 0.0f; motion_speed = 0.0f; motion_accel = 0.0f; path = new List <TuioPoint>(); path.Add(new TuioPoint(currentTime, xpos, ypos)); state = TUIO_ADDED; }
/** * 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); } }
/** * Takes a TuioTime argument and assigns it along with the provided * X and Y coordinate, X and Y velocity and acceleration * to the private TuioContainer attributes. * * @param ttime the TuioTime to assign * @param xp the X coordinate to assign * @param yp the Y coordinate to assign * @param xs the X velocity to assign * @param ys the Y velocity to assign * @param ma the acceleration to assign */ public void update(TuioTime ttime, float xp, float yp, float xs, float ys, float ma) { base.update(ttime, xp, yp); x_speed = xs; y_speed = ys; motion_speed = (float)Math.Sqrt(x_speed * x_speed + y_speed * y_speed); motion_accel = ma; path.Add(new TuioPoint(currentTime, xpos, ypos)); if (motion_accel > 0) { state = TUIO_ACCELERATING; } else if (motion_accel < 0) { state = TUIO_DECELERATING; } else { state = TUIO_STOPPED; } }
public static void OnTuioRefreshEvent(TuioTime t) { try { OnTuioRefresh(t); } catch { } }
private void TuioChannelHelper_OnTuioRefresh(TuioTime t) { OnTuioRefreshEvent(t); }
/** * This constructor takes the provided TuioTime * and assigs its Seconds and Microseconds values to the newly created TuioTime. * * @param ttime the TuioTime used to copy */ public TuioTime(TuioTime ttime) { this.seconds = ttime.getSeconds(); this.micro_seconds = ttime.getMicroseconds(); }
/** * 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") { long s_id = (int)args[1]; int f_id = (int)args[2]; float xpos = (float)args[3]; float ypos = (float)args[4]; float angle = (float)args[5]; float xspeed = (float)args[6]; float yspeed = (float)args[7]; float rspeed = (float)args[8]; float maccel = (float)args[9]; float raccel = (float)args[10]; lock (objectSync) { if (!objectList.ContainsKey(s_id)) { TuioObject addObject = new TuioObject(s_id, f_id, xpos, ypos, angle); frameObjects.Add(addObject); } else { TuioObject tobj = objectList[s_id]; if (tobj == null) { return; } if ((tobj.getX() != xpos) || (tobj.getY() != ypos) || (tobj.getAngle() != angle) || (tobj.getXSpeed() != xspeed) || (tobj.getYSpeed() != yspeed) || (tobj.getRotationSpeed() != rspeed) || (tobj.getMotionAccel() != maccel) || (tobj.getRotationAccel() != raccel)) { TuioObject updateObject = new TuioObject(s_id, f_id, xpos, ypos, angle); updateObject.update(xpos, ypos, angle, xspeed, yspeed, rspeed, maccel, raccel); frameObjects.Add(updateObject); } } } } else if (command == "alive") { newObjectList.Clear(); 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 lock (objectSync) { for (int i = 0; i < aliveObjectList.Count; i++) { long s_id = aliveObjectList[i]; TuioObject removeObject = objectList[s_id]; removeObject.remove(currentTime); frameObjects.Add(removeObject); } } } else if (command == "fseq") { int fseq = (int)args[1]; bool lateFrame = false; if (fseq > 0) { if (fseq > currentFrame) { currentTime = TuioTime.getSessionTime(); } if ((fseq >= currentFrame) || ((currentFrame - fseq) > 100)) { currentFrame = fseq; } else { lateFrame = true; } } else if ((TuioTime.getSessionTime().getTotalMilliseconds() - currentTime.getTotalMilliseconds()) > 100) { currentTime = TuioTime.getSessionTime(); } if (!lateFrame) { IEnumerator <TuioObject> frameEnum = frameObjects.GetEnumerator(); while (frameEnum.MoveNext()) { TuioObject tobj = frameEnum.Current; switch (tobj.getTuioState()) { case TuioObject.TUIO_REMOVED: TuioObject removeObject = tobj; removeObject.remove(currentTime); for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.removeTuioObject(removeObject); } } lock (objectSync) { objectList.Remove(removeObject.getSessionID()); } break; case TuioObject.TUIO_ADDED: TuioObject addObject = new TuioObject(currentTime, tobj.getSessionID(), tobj.getSymbolID(), tobj.getX(), tobj.getY(), tobj.getAngle()); lock (objectSync) { objectList.Add(addObject.getSessionID(), addObject); } for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.addTuioObject(addObject); } } break; default: TuioObject updateObject = getTuioObject(tobj.getSessionID()); if ((tobj.getX() != updateObject.getX() && tobj.getXSpeed() == 0) || (tobj.getY() != updateObject.getY() && tobj.getYSpeed() == 0)) { updateObject.update(currentTime, tobj.getX(), tobj.getY(), tobj.getAngle()); } else { 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); } } break; } } for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.refresh(new TuioTime(currentTime)); } } List <long> buffer = aliveObjectList; aliveObjectList = newObjectList; // recycling the List newObjectList = buffer; } frameObjects.Clear(); } } else if (address == "/tuio/2Dcur") { if (command == "set") { long s_id = (int)args[1]; float xpos = (float)args[2]; float ypos = (float)args[3]; float xspeed = (float)args[4]; float yspeed = (float)args[5]; float maccel = (float)args[6]; lock (cursorList) { if (!cursorList.ContainsKey(s_id)) { TuioCursor addCursor = new TuioCursor(s_id, -1, xpos, ypos); frameCursors.Add(addCursor); } else { TuioCursor tcur = (TuioCursor)cursorList[s_id]; if (tcur == null) { return; } if ((tcur.getX() != xpos) || (tcur.getY() != ypos) || (tcur.getXSpeed() != xspeed) || (tcur.getYSpeed() != yspeed) || (tcur.getMotionAccel() != maccel)) { TuioCursor updateCursor = new TuioCursor(s_id, tcur.getCursorID(), xpos, ypos); updateCursor.update(xpos, ypos, xspeed, yspeed, maccel); frameCursors.Add(updateCursor); } } } } else if (command == "alive") { newCursorList.Clear(); 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 lock (cursorSync) { for (int i = 0; i < aliveCursorList.Count; i++) { long s_id = aliveCursorList[i]; if (!cursorList.ContainsKey(s_id)) { continue; } TuioCursor removeCursor = cursorList[s_id]; removeCursor.remove(currentTime); frameCursors.Add(removeCursor); } } } else if (command == "fseq") { int fseq = (int)args[1]; bool lateFrame = false; if (fseq > 0) { if (fseq > currentFrame) { currentTime = TuioTime.getSessionTime(); } if ((fseq >= currentFrame) || ((currentFrame - fseq) > 100)) { currentFrame = fseq; } else { lateFrame = true; } } else if ((TuioTime.getSessionTime().getTotalMilliseconds() - currentTime.getTotalMilliseconds()) > 100) { currentTime = TuioTime.getSessionTime(); } if (!lateFrame) { IEnumerator <TuioCursor> frameEnum = frameCursors.GetEnumerator(); while (frameEnum.MoveNext()) { TuioCursor tcur = frameEnum.Current; switch (tcur.getTuioState()) { case TuioCursor.TUIO_REMOVED: TuioCursor removeCursor = tcur; removeCursor.remove(currentTime); for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.removeTuioCursor(removeCursor); } } lock (cursorSync) { cursorList.Remove(removeCursor.getSessionID()); if (removeCursor.getCursorID() == maxCursorID) { maxCursorID = -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 > maxCursorID) { maxCursorID = f_id; } } List <TuioCursor> freeCursorBuffer = new List <TuioCursor>(); IEnumerator <TuioCursor> flist = freeCursorList.GetEnumerator(); while (flist.MoveNext()) { TuioCursor testCursor = flist.Current; if (testCursor.getCursorID() < maxCursorID) { freeCursorBuffer.Add(testCursor); } } freeCursorList = freeCursorBuffer; } else { freeCursorList.Clear(); } } else if (removeCursor.getCursorID() < maxCursorID) { freeCursorList.Add(removeCursor); } } break; case TuioCursor.TUIO_ADDED: TuioCursor addCursor; lock (cursorSync) { int c_id = cursorList.Count; if ((cursorList.Count <= maxCursorID) && (freeCursorList.Count > 0)) { TuioCursor closestCursor = freeCursorList[0]; IEnumerator <TuioCursor> testList = freeCursorList.GetEnumerator(); while (testList.MoveNext()) { TuioCursor testCursor = testList.Current; if (testCursor.getDistance(tcur) < closestCursor.getDistance(tcur)) { closestCursor = testCursor; } } c_id = closestCursor.getCursorID(); freeCursorList.Remove(closestCursor); } else { maxCursorID = c_id; } addCursor = new TuioCursor(currentTime, tcur.getSessionID(), c_id, tcur.getX(), tcur.getY()); cursorList.Add(addCursor.getSessionID(), addCursor); } for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.addTuioCursor(addCursor); } } break; default: TuioCursor updateCursor = getTuioCursor(tcur.getSessionID()); if ((tcur.getX() != updateCursor.getX() && tcur.getXSpeed() == 0) || (tcur.getY() != updateCursor.getY() && tcur.getYSpeed() == 0)) { updateCursor.update(currentTime, tcur.getX(), tcur.getY()); } else { 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); } } break; } } for (int i = 0; i < listenerList.Count; i++) { TuioListener listener = (TuioListener)listenerList[i]; if (listener != null) { listener.refresh(new TuioTime(currentTime)); } } List <long> buffer = aliveCursorList; aliveCursorList = newCursorList; // recycling the List newCursorList = buffer; } frameCursors.Clear(); } } }
/** * Takes a TuioTime object and two floating point coordinate arguments and updates its coordinate attributes * to the coordinates of the provided TuioPoint and its time stamp to the provided TUIO time object. * * @param ttime the TuioTime to assign * @param xp the X coordinate to assign * @param yp the Y coordinate to assign */ public void update(TuioTime ttime, float xp, float yp) { xpos = xp; ypos = yp; currentTime = new TuioTime(ttime); }
/** * This method is used to calculate the speed and acceleration values of a * TuioObject with unchanged position and angle. */ public new void stop(TuioTime ttime) { update(ttime, this.xpos, this.ypos, this.angle); }
/** * Assigns the REMOVE state to this TuioContainer and sets * its TuioTime time stamp to the provided TuioTime argument. * * @param ttime the TuioTime to assign */ public void remove(TuioTime ttime) { currentTime = ttime; state = TUIO_REMOVED; }
/** * This method is used to calculate the speed and acceleration values of * TuioContainers with unchanged positions. */ public void stop(TuioTime ttime) { update(ttime, this.xpos, this.ypos); }
/** * This constructor takes a TuioTime argument and assigns it along with the provided * Session ID, Cursor ID, X and Y coordinate to the newly created TuioCursor. * * @param ttime the TuioTime to assign * @param si the Session ID to assign * @param ci the Cursor ID to assign * @param xp the X coordinate to assign * @param yp the Y coordinate to assign */ public TuioCursor(TuioTime ttime, long si, int ci, float xp, float yp) : base(ttime, si, xp, yp) { cursor_id = ci; }