* The TuioTime class is a simple structure that is used to reprent the time that has elapsed since the session start. * The time is internally represented as seconds and fractions of microseconds which should be more than sufficient for gesture related timing requirements. * Therefore at the beginning of a typical TUIO session the static method initSession() will set the reference time for the session. * Another important static method getSessionTime will return a TuioTime object representing the time elapsed since the session start. * The class also provides various addtional convience method, which allow some simple time arithmetics. *
Exemplo n.º 1
0
 /**
  * <summary>
  * The default constructor takes no arguments and sets
  * its coordinate attributes to zero and its time stamp to the current session time.</summary>
  */
 public TuioPoint()
 {
     xpos = 0.0f;
     ypos = 0.0f;
     currentTime = TuioTime.SessionTime;
     startTime = new TuioTime(currentTime);
 }
Exemplo n.º 2
0
        /**
         * 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();
        }
Exemplo n.º 3
0
        public TuioServer(string host = "127.0.0.1", int port = 3333, int size = 65536)
        {
            if (size > MAX_UDP_SIZE) size = MAX_UDP_SIZE;
            if (size < MIN_UDP_SIZE) size = MIN_UDP_SIZE;

            try
            {
                this.socket = new OSCTransmitter(host, port);
                this.socket.Connect();

                this.connected = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            this.cursorList = new List<TuioCursor>();
            this.freeCursorList = new List<TuioCursor>();
            this.freeCursorBuffer = new List<TuioCursor>();

            this.currentFrameTime = TuioTime.SessionTime;
            this.currentFrame = -1;
            this.sessionID = -1;
            this.maxCursorID = -1;
            this.updateCursor = false;
            this.lastCursorUpdate = this.currentFrameTime.Seconds;

            Clear();
        }
Exemplo n.º 4
0
        /**
         * <summary>
         * 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.</summary>
         *
         * <param name="ttime">the TuioTime to assign</param>
         * <param name="xp">the X coordinate to assign</param>
         * <param name="yp">the Y coordinate to assign</param>
         * <param name="a">the angle coordinate to assign</param>
         */
        public void update(TuioTime ttime, float xp, float yp, float a)
        {
            TuioPoint lastPoint = path.Last.Value;

            base.update(ttime, xp, yp);

            TuioTime diffTime            = currentTime - lastPoint.TuioTime;
            float    dt                  = diffTime.TotalMilliseconds / 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;
            }
        }
Exemplo n.º 5
0
 /**
  * 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);
 }
Exemplo n.º 6
0
 /**
  * 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;
 }
Exemplo n.º 7
0
 /**
  * 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);
 }
Exemplo n.º 8
0
        /**
         * <summary>
         * 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.</summary>
         * <param name="ttime">the TuioTime to assign</param>
         * <param name="xp">the X coordinate to assign</param>
         * <param name="yp">the Y coordinate to assign</param>
         */
        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.TuioTime;
            float    dt                = diffTime.TotalMilliseconds / 1000.0f;
            float    dx                = this.xpos - lastPoint.X;
            float    dy                = this.ypos - lastPoint.Y;
            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;
            }
        }
Exemplo n.º 9
0
 /**
  * <summary>
  * 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.</summary>
  *
  * <param name="tpoint">the TuioPoint to assign</param>
  */
 public TuioPoint(TuioPoint tpoint)
 {
     xpos        = tpoint.X;
     ypos        = tpoint.Y;
     currentTime = TuioTime.SessionTime;
     startTime   = new TuioTime(currentTime);
 }
Exemplo n.º 10
0
        /**
         * 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 > (float)Math.PI * 1.5f)
            {
                da -= (2.0f * (float)Math.PI);
            }
            else if (da < (float)Math.PI * 1.5f)
            {
                da += (2.0f * (float)Math.PI);
            }

            rotation_speed = da / dt;
            rotation_accel = (rotation_speed - last_rotation_speed) / dt;
            if ((rotation_accel != 0) && (state != TUIO_STOPPED))
            {
                state = TUIO_ROTATING;
            }
        }
Exemplo n.º 11
0
        /**
         * <summary>
         * 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.</summary>
         *
         * <param name="ttime">the TuioTime to assign</param>
         * <param name="xp">the X coordinate to assign</param>
         * <param name="yp">the Y coordinate to assign</param>
         * <param name="xs">the X velocity to assign</param>
         * <param name="ys">the Y velocity to assign</param>
         * <param name="ma">the acceleration to assign</param>
         */
        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;

            if (motion_accel > 0)
            {
                state = TUIO_ACCELERATING;
            }
            else if (motion_accel < 0)
            {
                state = TUIO_DECELERATING;
            }
            else
            {
                state = TUIO_STOPPED;
            }

            lock (path) {
                path.AddLast(new TuioPoint(currentTime, xpos, ypos));
                if (path.Count > 128)
                {
                    path.RemoveFirst();
                }
            }
        }
Exemplo n.º 12
0
        /**
         * <summary>
         * This static method globally resets the TUIO session time.</summary>
         */
        public static void initSession()
        {
            TuioTime startTime = SystemTime;

            start_seconds       = startTime.Seconds;
            start_micro_seconds = startTime.Microseconds;
        }
Exemplo n.º 13
0
 /**
  * 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);
 }
Exemplo n.º 14
0
 /**
  * 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);
 }
Exemplo n.º 15
0
 /**
  * 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;
 }
Exemplo n.º 16
0
 /**
  * This constructor takes a TuioTime argument and assigns it along with the provided
  * Hand ID, X and Y coordinates, and Finger ID's to the newly created TuioHand.
  *
  * @param	ttime	the TuioTime to assign
  * @param	h_id	the Hand ID to assign
  * @param	xp	the X coordinate to assign
  * @param	yp	the Y coordinate to assign
  * @param	f_id1	the Finger ID #1 to assign
  * @param	f_id2	the Finger ID #2 to assign
  * @param	f_id3	the Finger ID #3 to assign
  * @param	f_id4	the Finger ID #4 to assign
  * @param	f_id5	the Finger ID #5 to assign
  */
 public TuioHand(TuioTime ttime, int h_id, float xp, float yp, int f_id1, int f_id2, int f_id3, int f_id4, int f_id5)
     : base(ttime, h_id, xp, yp)
 {
     hand_id = h_id;
     finger_id1 = f_id1;
     finger_id2 = f_id2;
     finger_id3 = f_id3;
     finger_id4 = f_id4;
     finger_id5 = f_id5;
 }
Exemplo n.º 17
0
 /**
  * <summary>
  * 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 TuioBlob.</summary>
  *
  * <param name="ttime">the TuioTime to assign</param>
  * <param name="si">the Session ID to assign</param>
  * <param name="bi">the Blob ID to assign</param>
  * <param name="xp">the X coordinate to assign</param>
  * <param name="yp">the Y coordinate to assign</param>
  * <param name="a">the angle to assign</param>
  * <param name="w">the width to assign</param>
  * <param name="h">the height to assign</param>
  * <param name="f">the area to assign</param>
  */
 public TuioBlob(TuioTime ttime, long si, int bi, float xp, float yp, float a, float w, float h, float f)
     : base(ttime, si, xp, yp)
 {
     blob_id        = bi;
     angle          = a;
     width          = w;
     height         = h;
     area           = f;
     rotation_speed = 0.0f;
     rotation_accel = 0.0f;
 }
Exemplo n.º 18
0
 /**
  * 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;
     }
 }
Exemplo n.º 19
0
 /**
  * <summary>
  * Takes a TuioTime argument and compares the provided TuioTime to the private Seconds and Microseconds attributes.</summary>
  *
  * <param name="ttime">the TuioTime to compare</param>
  * <returns>true if the two TuioTime have equal Seconds and Microseconds attributes</returns>
  */
 public bool Equals(TuioTime ttime)
 {
     if ((seconds == ttime.Seconds) && (micro_seconds == ttime.Microseconds))
     {
         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;
        }
Exemplo n.º 21
0
        /**
         * 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);
            }
        }
Exemplo n.º 22
0
        /**
         * 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)
        }
Exemplo n.º 23
0
        /**
         * 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);
            }
        }
Exemplo n.º 24
0
        public TuioServer(string host = "127.0.0.1", int port = 3333, int size = 65536)
        {
            if (size > MAX_UDP_SIZE)
            {
                size = MAX_UDP_SIZE;
            }
            if (size < MIN_UDP_SIZE)
            {
                size = MIN_UDP_SIZE;
            }

            try
            {
                this.socket = new OSCTransmitter(host, port);
                this.socket.Connect();

                this.connected = true;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }

            this.cursorList       = new List <TuioCursor>();
            this.freeCursorList   = new List <TuioCursor>();
            this.freeCursorBuffer = new List <TuioCursor>();

            this.currentFrameTime = TuioTime.SessionTime;
            this.currentFrame     = -1;
            this.sessionID        = -1;
            this.maxCursorID      = -1;
            this.updateCursor     = false;
            this.lastCursorUpdate = this.currentFrameTime.Seconds;

            Clear();
        }
Exemplo n.º 25
0
 /**
  * This constructor takes the provided TUIO Time, Hand ID, X and Y coordinates,
  * and assigns these values to the newly created TuioHand.
  *
  * @param	ttime	the TuioTime to assign
  * @param	h_id	the Hand ID to assign
  * @param	xp	the X coordinate to assign
  * @param	yp	the Y coordinate to assign
  * @param	a	the angle to assign
  */
 public TuioHand(TuioTime ttime, int h_id, float xp, float yp)
     : base(ttime, h_id, xp, yp)
 {
     hand_id = h_id;
 }
Exemplo n.º 26
0
 // this is the end of a single frame
 // we only really need to call the frame end if something actually happened this frame
 public void refresh(TuioTime ftime)
 {
 }
Exemplo n.º 27
0
 /**
  * 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);
 }
Exemplo n.º 28
0
 /**
 * <summary>
 * Assigns the REMOVE state to this TuioContainer and sets
 * its TuioTime time stamp to the provided TuioTime argument.</summary>
 *
 * <param name="ttime">the TuioTime to assign</param>
 */
 public void remove(TuioTime ttime)
 {
     currentTime = ttime;
     state = TUIO_REMOVED;
 }
Exemplo n.º 29
0
        /**
         * <summary>
         * The OSC callback method where all TUIO messages are received and decoded
         * and where the TUIO event callbacks are dispatched</summary>
         * <param name="message">the received OSC message</param>
         */
        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.X != xpos) || (tobj.Y != ypos) || (tobj.Angle != angle) || (tobj.XSpeed != xspeed) || (tobj.YSpeed != yspeed) || (tobj.RotationSpeed != rspeed) || (tobj.MotionAccel != maccel) || (tobj.RotationAccel != 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.SessionTime;
                        }
                        if ((fseq >= currentFrame) || ((currentFrame - fseq) > 100))
                        {
                            currentFrame = fseq;
                        }
                        else
                        {
                            lateFrame = true;
                        }
                    }
                    else if ((TuioTime.SessionTime.TotalMilliseconds - currentTime.TotalMilliseconds) > 100)
                    {
                        currentTime = TuioTime.SessionTime;
                    }

                    if (!lateFrame)
                    {
                        IEnumerator <TuioObject> frameEnum = frameObjects.GetEnumerator();
                        while (frameEnum.MoveNext())
                        {
                            TuioObject tobj = frameEnum.Current;

                            switch (tobj.TuioState)
                            {
                            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.SessionID);
                                }
                                break;

                            case TuioObject.TUIO_ADDED:
                                TuioObject addObject = new TuioObject(currentTime, tobj.SessionID, tobj.SymbolID, tobj.X, tobj.Y, tobj.Angle);
                                lock (objectSync)
                                {
                                    objectList.Add(addObject.SessionID, 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.SessionID);
                                if ((tobj.X != updateObject.X && tobj.XSpeed == 0) || (tobj.Y != updateObject.Y && tobj.YSpeed == 0))
                                {
                                    updateObject.update(currentTime, tobj.X, tobj.Y, tobj.Angle);
                                }
                                else
                                {
                                    updateObject.update(currentTime, tobj.X, tobj.Y, tobj.Angle, tobj.XSpeed, tobj.YSpeed, tobj.RotationSpeed, tobj.MotionAccel, tobj.RotationAccel);
                                }

                                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.X != xpos) || (tcur.Y != ypos) || (tcur.XSpeed != xspeed) || (tcur.YSpeed != yspeed) || (tcur.MotionAccel != maccel))
                            {
                                TuioCursor updateCursor = new TuioCursor(s_id, tcur.CursorID, 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.SessionTime;
                        }
                        if ((fseq >= currentFrame) || ((currentFrame - fseq) > 100))
                        {
                            currentFrame = fseq;
                        }
                        else
                        {
                            lateFrame = true;
                        }
                    }
                    else if ((TuioTime.SessionTime.TotalMilliseconds - currentTime.TotalMilliseconds) > 100)
                    {
                        currentTime = TuioTime.SessionTime;
                    }

                    if (!lateFrame)
                    {
                        IEnumerator <TuioCursor> frameEnum = frameCursors.GetEnumerator();
                        while (frameEnum.MoveNext())
                        {
                            TuioCursor tcur = frameEnum.Current;
                            switch (tcur.TuioState)
                            {
                            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.SessionID);

                                    if (removeCursor.CursorID == maxCursorID)
                                    {
                                        maxCursorID = -1;

                                        if (cursorList.Count > 0)
                                        {
                                            IEnumerator <KeyValuePair <long, TuioCursor> > clist = cursorList.GetEnumerator();
                                            while (clist.MoveNext())
                                            {
                                                int f_id = clist.Current.Value.CursorID;
                                                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.CursorID < maxCursorID)
                                                {
                                                    freeCursorBuffer.Add(testCursor);
                                                }
                                            }
                                            freeCursorList = freeCursorBuffer;
                                        }
                                        else
                                        {
                                            freeCursorList.Clear();
                                        }
                                    }
                                    else if (removeCursor.CursorID < 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.CursorID;
                                        freeCursorList.Remove(closestCursor);
                                    }
                                    else
                                    {
                                        maxCursorID = c_id;
                                    }

                                    addCursor = new TuioCursor(currentTime, tcur.SessionID, c_id, tcur.X, tcur.Y);
                                    cursorList.Add(addCursor.SessionID, 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.SessionID);
                                if ((tcur.X != updateCursor.X && tcur.XSpeed == 0) || (tcur.Y != updateCursor.Y && tcur.YSpeed == 0))
                                {
                                    updateCursor.update(currentTime, tcur.X, tcur.Y);
                                }
                                else
                                {
                                    updateCursor.update(currentTime, tcur.X, tcur.Y, tcur.XSpeed, tcur.YSpeed, tcur.MotionAccel);
                                }

                                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();
                }
            }
            else if (address == "/tuio/2Dblb")
            {
                if (command == "set")
                {
                    long  s_id   = (int)args[1];
                    float xpos   = (float)args[2];
                    float ypos   = (float)args[3];
                    float angle  = (float)args[4];
                    float width  = (float)args[5];
                    float height = (float)args[6];
                    float area   = (float)args[7];
                    float xspeed = (float)args[8];
                    float yspeed = (float)args[9];
                    float rspeed = (float)args[10];
                    float maccel = (float)args[11];
                    float raccel = (float)args[12];

                    lock (blobList)
                    {
                        if (!blobList.ContainsKey(s_id))
                        {
                            TuioBlob addBlob = new TuioBlob(s_id, -1, xpos, ypos, angle, width, height, area);
                            frameBlobs.Add(addBlob);
                        }
                        else
                        {
                            TuioBlob tblb = (TuioBlob)blobList[s_id];
                            if (tblb == null)
                            {
                                return;
                            }
                            if ((tblb.X != xpos) || (tblb.Y != ypos) || (tblb.Angle != angle) || (tblb.Width != width) || (tblb.Height != height) || (tblb.Area != area) || (tblb.XSpeed != xspeed) || (tblb.YSpeed != yspeed) || (tblb.RotationSpeed != rspeed) || (tblb.MotionAccel != maccel) || (tblb.RotationAccel != raccel))
                            {
                                TuioBlob updateBlob = new TuioBlob(s_id, tblb.BlobID, xpos, ypos, angle, width, height, area);
                                updateBlob.update(xpos, ypos, angle, width, height, area, xspeed, yspeed, rspeed, maccel, raccel);
                                frameBlobs.Add(updateBlob);
                            }
                        }
                    }
                }
                else if (command == "alive")
                {
                    newBlobList.Clear();
                    for (int i = 1; i < args.Count; i++)
                    {
                        // get the message content
                        long s_id = (int)args[i];
                        newBlobList.Add(s_id);
                        // reduce the blob list to the lost blobs
                        if (aliveBlobList.Contains(s_id))
                        {
                            aliveBlobList.Remove(s_id);
                        }
                    }

                    // remove the remaining blobs
                    lock (blobSync)
                    {
                        for (int i = 0; i < aliveBlobList.Count; i++)
                        {
                            long s_id = aliveBlobList[i];
                            if (!blobList.ContainsKey(s_id))
                            {
                                continue;
                            }
                            TuioBlob removeBlob = blobList[s_id];
                            removeBlob.remove(currentTime);
                            frameBlobs.Add(removeBlob);
                        }
                    }
                }
                else if (command == "fseq")
                {
                    int  fseq      = (int)args[1];
                    bool lateFrame = false;

                    if (fseq > 0)
                    {
                        if (fseq > currentFrame)
                        {
                            currentTime = TuioTime.SessionTime;
                        }
                        if ((fseq >= currentFrame) || ((currentFrame - fseq) > 100))
                        {
                            currentFrame = fseq;
                        }
                        else
                        {
                            lateFrame = true;
                        }
                    }
                    else if ((TuioTime.SessionTime.TotalMilliseconds - currentTime.TotalMilliseconds) > 100)
                    {
                        currentTime = TuioTime.SessionTime;
                    }

                    if (!lateFrame)
                    {
                        IEnumerator <TuioBlob> frameEnum = frameBlobs.GetEnumerator();
                        while (frameEnum.MoveNext())
                        {
                            TuioBlob tblb = frameEnum.Current;
                            switch (tblb.TuioState)
                            {
                            case TuioBlob.TUIO_REMOVED:
                                TuioBlob removeBlob = tblb;
                                removeBlob.remove(currentTime);

                                for (int i = 0; i < listenerList.Count; i++)
                                {
                                    TuioListener listener = (TuioListener)listenerList[i];
                                    if (listener != null)
                                    {
                                        listener.removeTuioBlob(removeBlob);
                                    }
                                }
                                lock (blobSync)
                                {
                                    blobList.Remove(removeBlob.SessionID);

                                    if (removeBlob.BlobID == maxBlobID)
                                    {
                                        maxBlobID = -1;

                                        if (blobList.Count > 0)
                                        {
                                            IEnumerator <KeyValuePair <long, TuioBlob> > blist = blobList.GetEnumerator();
                                            while (blist.MoveNext())
                                            {
                                                int b_id = blist.Current.Value.BlobID;
                                                if (b_id > maxBlobID)
                                                {
                                                    maxBlobID = b_id;
                                                }
                                            }

                                            List <TuioBlob>        freeBlobBuffer = new List <TuioBlob>();
                                            IEnumerator <TuioBlob> flist          = freeBlobList.GetEnumerator();
                                            while (flist.MoveNext())
                                            {
                                                TuioBlob testBlob = flist.Current;
                                                if (testBlob.BlobID < maxBlobID)
                                                {
                                                    freeBlobBuffer.Add(testBlob);
                                                }
                                            }
                                            freeBlobList = freeBlobBuffer;
                                        }
                                        else
                                        {
                                            freeBlobList.Clear();
                                        }
                                    }
                                    else if (removeBlob.BlobID < maxBlobID)
                                    {
                                        freeBlobList.Add(removeBlob);
                                    }
                                }
                                break;

                            case TuioBlob.TUIO_ADDED:
                                TuioBlob addBlob;
                                lock (blobSync)
                                {
                                    int b_id = blobList.Count;
                                    if ((blobList.Count <= maxBlobID) && (freeBlobList.Count > 0))
                                    {
                                        TuioBlob closestBlob            = freeBlobList[0];
                                        IEnumerator <TuioBlob> testList = freeBlobList.GetEnumerator();
                                        while (testList.MoveNext())
                                        {
                                            TuioBlob testBlob = testList.Current;
                                            if (testBlob.getDistance(tblb) < closestBlob.getDistance(tblb))
                                            {
                                                closestBlob = testBlob;
                                            }
                                        }
                                        b_id = closestBlob.BlobID;
                                        freeBlobList.Remove(closestBlob);
                                    }
                                    else
                                    {
                                        maxBlobID = b_id;
                                    }

                                    addBlob = new TuioBlob(currentTime, tblb.SessionID, b_id, tblb.X, tblb.Y, tblb.Angle, tblb.Width, tblb.Height, tblb.Area);
                                    blobList.Add(addBlob.SessionID, addBlob);
                                }

                                for (int i = 0; i < listenerList.Count; i++)
                                {
                                    TuioListener listener = (TuioListener)listenerList[i];
                                    if (listener != null)
                                    {
                                        listener.addTuioBlob(addBlob);
                                    }
                                }
                                break;

                            default:
                                TuioBlob updateBlob = getTuioBlob(tblb.SessionID);
                                if ((tblb.X != updateBlob.X && tblb.XSpeed == 0) || (tblb.Y != updateBlob.Y && tblb.YSpeed == 0) || (tblb.Angle != updateBlob.Angle && tblb.RotationSpeed == 0))
                                {
                                    updateBlob.update(currentTime, tblb.X, tblb.Y, tblb.Angle, tblb.Width, tblb.Height, tblb.Area);
                                }
                                else
                                {
                                    updateBlob.update(currentTime, tblb.X, tblb.Y, tblb.Angle, tblb.Width, tblb.Height, tblb.Area, tblb.XSpeed, tblb.YSpeed, tblb.RotationSpeed, tblb.MotionAccel, tblb.RotationAccel);
                                }

                                for (int i = 0; i < listenerList.Count; i++)
                                {
                                    TuioListener listener = (TuioListener)listenerList[i];
                                    if (listener != null)
                                    {
                                        listener.updateTuioBlob(updateBlob);
                                    }
                                }
                                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 = aliveBlobList;
                        aliveBlobList = newBlobList;
                        // recycling the List
                        newBlobList = buffer;
                    }
                    frameBlobs.Clear();
                }
            }
        }
Exemplo n.º 30
0
 /**
  * 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();
 }
Exemplo n.º 31
0
 /**
  * <summary>
  * This method is used to calculate the speed and acceleration values of a
  * TuioBlob with unchanged position and angle.</summary>
  */
 public new void stop(TuioTime ttime)
 {
     update(ttime, this.xpos, this.ypos, this.angle, this.width, this.height, this.area);
 }
 /**
  * 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;
 }
Exemplo n.º 33
0
 /**
  * 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;
 }
Exemplo n.º 34
0
 /**
  * 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 TuioHand 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	f_id1	the Finger ID #1 to assign
  * @param	f_id2	the Finger ID #2 to assign
  * @param	f_id3	the Finger ID #3 to assign
  * @param	f_id4	the Finger ID #4 to assign
  * @param	f_id5	the Finger ID #5 to assign
  */
 public void update(TuioTime ttime, float xp, float yp, float xs, float ys, int f_id1, int f_id2, int f_id3, int f_id4, int f_id5)
 {
     base.update(ttime, xp, yp, xs, ys, 0f);
     finger_id1 = f_id1;
     finger_id2 = f_id2;
     finger_id3 = f_id3;
     finger_id4 = f_id4;
     finger_id5 = f_id5;
 }
Exemplo n.º 35
0
 /**
  * <summary>
  * 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.</summary>
  *
  * <param name="ttime">the TuioTime to assign</param>
  * <param name="xp">the X coordinate to assign</param>
  * <param name="yp">the Y coordinate to assign</param>
  * <param name="xs">the X velocity to assign</param>
  * <param name="ys">the Y velocity to assign</param>
  * <param name="ma">the acceleration to assign</param>
  */
 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;
 }
Exemplo n.º 36
0
        /**
         * <summary>
         * 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.</summary>
         * <param name="ttime">the TuioTime to assign</param>
         * <param name="xp">the X coordinate to assign</param>
         * <param name="yp">the Y coordinate to assign</param>
         */
        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.TuioTime;
            float dt = diffTime.TotalMilliseconds / 1000.0f;
            float dx = this.xpos - lastPoint.X;
            float dy = this.ypos - lastPoint.Y;
            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;
        }
Exemplo n.º 37
0
 /**
  * <summary>
  * This method is used to calculate the speed and acceleration values of
  * TuioContainers with unchanged positions.</summary>
  */
 public void stop(TuioTime ttime)
 {
     update(ttime, this.xpos, this.ypos);
 }
Exemplo n.º 38
0
 /**
  * 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();
 }
Exemplo n.º 39
0
 /**
  * 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;
 }
Exemplo n.º 40
0
        /**
         * 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();
                }
            }
        }
Exemplo n.º 41
0
 /**
  * <summary>
  * 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 TuioBlob.</summary>
  *
  * <param name="ttime">the TuioTime to assign</param>
  * <param name="si">the Session ID to assign</param>
  * <param name="bi">the Blob ID to assign</param>
  * <param name="xp">the X coordinate to assign</param>
  * <param name="yp">the Y coordinate to assign</param>
  * <param name="a">the angle to assign</param>
  * <param name="w">the width to assign</param>
  * <param name="h">the height to assign</param>
  * <param name="f">the area to assign</param>
  */
 public TuioBlob(TuioTime ttime, long si, int bi, float xp, float yp, float a, float w, float h, float f)
     : base(ttime, si, xp, yp)
 {
     blob_id = bi;
     angle = a;
     width = w;
     height = h;
     area = f;
     rotation_speed = 0.0f;
     rotation_accel = 0.0f;
 }
Exemplo n.º 42
0
        /**
         * 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" || address == "/tuio/2Dcur source ccv@localhost") {

                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];
                    //~ Debug.Log("Cursor - id: " + s_id);

                    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);
                            }
                        }
                    }
                //experimental contour data (by Rasmus H. - www.schnitzel.dk)
                  }else if (command == "contour") {

                    long s_id = (int)args[1];
                    int m_length = (int)args[2];
                    //~ Debug.Log("Contour - id: " + s_id + " Lenght: " + m_length);
                    if(m_length > 0)
                    {
                        lock(cursorList) {

                            List<TuioPoint> contr = new List<TuioPoint>();
                            for(int i=3; i+2 <= m_length+3; i+=2)
                            {
                                float xpos = (float)args[i];
                                float ypos = (float)args[i+1];
                                contr.Add(new TuioPoint(xpos,ypos));
                            }

                            if(!cursorList.ContainsKey(s_id)){
                                //no cursor with that id so we return
                                return;
                            }else{
                                TuioCursor tcur = (TuioCursor)cursorList[s_id];
                                if (tcur==null) return;
                                TuioCursor updateCursor = new TuioCursor(tcur);
                                updateCursor.update(tcur, contr);
                                frameCursors.Add(updateCursor);
                            }
                        }
                    }
             //experimental height data (by Rasmus H. - www.schnitzel.dk)
                  }else if (command == "height") {

                    long s_id = (int)args[1];
                    float xpos = (float)args[2];
                    float ypos = (float)args[3];
                    int xwidth = (int)args[4];
                    int yheight = (int)args[5];
                    int hpoints = (int)args[6];
                    //Debug.Log("Contour - id: " + s_id + " x: " + xpos +  " y: " + ypos + " width: " + xwidth + " height: " + yheight + " hpoints: " + hpoints );
                    lock(cursorList) {

                        List<float> heightp = new List<float>();
                        for(int i=7; i < hpoints+7; i++)
                        {
                            heightp.Add((float)args[i]);
                        }

                        if(!cursorList.ContainsKey(s_id)){
                            //no cursor with that id so we return
                            return;
                        }else{
                            TuioCursor tcur = (TuioCursor)cursorList[s_id];
                            if (tcur==null) return;
                            TuioCursor updateCursor = new TuioCursor(tcur);
                            updateCursor.update(tcur, xpos, ypos, xwidth, yheight, heightp);
                            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());
                                }
                                //rasmus edit
                                if(tcur.getContour() != null)
                                    updateCursor.update(updateCursor, tcur.getContour());

                                if(tcur.getHeightPoints() != null)
                                    updateCursor.update(updateCursor, tcur.getHXpos(), tcur.getHYpos(), tcur.getWidth(), tcur.getHeight(), tcur.getHeightPoints());

                                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();
                }

            }
        }
Exemplo n.º 43
0
        /**
         * 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();
                }

            }
        }
Exemplo n.º 44
0
 /**
  * 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);
 }
Exemplo n.º 45
0
        /**
         * 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;
        }
Exemplo n.º 46
0
		public void Refresh(TuioTime frameTime)
		{
			Trace.WriteLine(string.Format("refresh {0}", frameTime.getTotalMilliseconds()), "TUIO");

			_refreshTimer.Stop();

			if (this.IsContactEnabled && this.IsWindowsKeyPressEnabled)
			{
				if (_pointerTouchInfos.Count.Equals(this.WindowsKeyPressTouchCount))
				{
#pragma warning disable 4014
					InjectWindowsKeyPress();
#pragma warning restore 4014
					return;
				}
			}

			InjectPointerTouchInfos();

			if (_pointerTouchInfos.Count > 0)
			{
				for (int i = _pointerTouchInfos.Count - 1; i >= 0; i--)
				{
					if (_pointerTouchInfos[i].PointerInfo.PointerFlags.HasFlag(PointerFlags.UP))
					{
						_pointerTouchInfos.RemoveAt(i);
					}
				}

				if (_pointerTouchInfos.Count > 0)
				{
					for (int i = 0, ic = _pointerTouchInfos.Count; i < ic; i++)
					{
						if (_pointerTouchInfos[i].PointerInfo.PointerFlags.HasFlag(PointerFlags.DOWN))
						{
							PointerTouchInfo pointerTouchInfo = _pointerTouchInfos[i];
							pointerTouchInfo.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | ((this.IsContactEnabled) ? PointerFlags.INCONTACT : PointerFlags.NONE);
							_pointerTouchInfos[i] = pointerTouchInfo;
						}
					}

					_refreshTimer.Start();
				}
			}	
		}
Exemplo n.º 47
0
 /**
  * <summary>
  * This constructor takes the provided TuioTime
  * and assigs its Seconds and Microseconds values to the newly created TuioTime.</summary>
  *
  * <param name="ttime">the TuioTime used to copy</param>
  */
 public TuioTime(TuioTime ttime)
 {
     this.seconds       = ttime.Seconds;
     this.micro_seconds = ttime.Microseconds;
 }
Exemplo n.º 48
0
 /**
  * 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;
 }
Exemplo n.º 49
0
        /**
         * <summary>
         * This constructor takes a TuioTime argument and assigns it along with the provided
         * Session ID, X and Y coordinate to the newly created TuioContainer.</summary>
         *
         * <param name="ttime">the TuioTime to assign</param>
         * <param name="si">the Session ID to assign</param>
         * <param name="xp">the X coordinate to assign</param>
         * <param name="yp">the Y coordinate to assign</param>
         */
        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;
        }
Exemplo n.º 50
0
        /**
         * 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();
                }

            }
        }
Exemplo n.º 51
0
        /**
         * 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);
            }
        }
Exemplo n.º 52
0
 /**
  * <summary>
  * This method is used to calculate the speed and acceleration values of
  * TuioContainers with unchanged positions.</summary>
  */
 public void stop(TuioTime ttime)
 {
     update(ttime, this.xpos, this.ypos);
 }
Exemplo n.º 53
0
 /**
  * <summary>
  * Assigns the REMOVE state to this TuioContainer and sets
  * its TuioTime time stamp to the provided TuioTime argument.</summary>
  *
  * <param name="ttime">the TuioTime to assign</param>
  */
 public void remove(TuioTime ttime)
 {
     currentTime = ttime;
     state       = TUIO_REMOVED;
 }
Exemplo n.º 54
0
 /**
  * <summary>
  * This method is used to calculate the speed and acceleration values of a
  * TuioBlob with unchanged position and angle.</summary>
  */
 public new void stop(TuioTime ttime)
 {
     update(ttime, this.xpos, this.ypos, this.angle, this.width, this.height, this.area);
 }
 public void refresh(TuioTime bundleTime)
 {
     // Measure how many total updates / second we're getting
     //if ((int)gameTime.TotalGameTime.TotalSeconds > secondsRunning)
     //{
     //    Debug.WriteLine("Refreshes per second:" + refreshCount);
     //    secondsRunning = (int)gameTime.TotalGameTime.TotalSeconds;
     //    refreshCount = 0;
     //}
     //else
     //{
     //    refreshCount++;
     //}
 }
Exemplo n.º 56
0
 /**
  * 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);
 }
Exemplo n.º 57
0
 public void refresh(TuioTime frameTime)
 {
     //Console.WriteLine("refresh "+frameTime.getTotalMilliseconds());
 }
Exemplo n.º 58
0
 public void refresh(TuioTime frameTime)
 {
     //		Invalidate();
 }
Exemplo n.º 59
0
 /**
  * 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();
 }
/*