Ejemplo n.º 1
0
        public TuioContact(TuioCursor cursor, ContactState state, System.Drawing.Size monitorSize)
            : base(cursor.getFingerID(), state, new Point(0, 0), 20, 20)
        {
            float x = cursor.getScreenX(monitorSize.Width);
            float y = cursor.getScreenY(monitorSize.Height);

            Position = new Point(x, y);
            Orientation = 0;
        }
Ejemplo n.º 2
0
		public TuioContact(TuioCursor cursor, ContactState state, System.Drawing.Size monitorSize)
			: base(cursor.getFingerID(), state, new Point(0, 0), 20, 20)
		{

            float x, y;

            //Edit by Wander
            if (secondaryScreen == null)
            {
                x = cursor.getScreenX(monitorSize.Width);
                y = cursor.getScreenY(monitorSize.Height);
            }
            else
            {
                x = cursor.getX() * secondaryScreen.WorkingArea.Width + secondaryScreen.WorkingArea.Left;
                y = cursor.getY() * secondaryScreen.WorkingArea.Height + secondaryScreen.WorkingArea.Top;
            }

			Position = new Point(x, y);
			Orientation = 0;
		}
Ejemplo n.º 3
0
        public void updateTuioCursor(TuioCursor c)
        {
            // Enviando a posição do cursor do mouse!
            // ContaTelefingerMove++;

            if (clienteEnvia.connected)
            {
                // if (ContaTelefingerMove.Equals(4))
                // {
                // TODO: Resolver problema de posicionamento do TeleFinger
                // Enviando os dados para a movimentação do TeleFinger
                // int x = (int)c.getScreenX(width);
                // int y = (int)c.getScreenY(height);
                int x = Convert.ToInt32(c.getScreenX(width) * (0.5 * 5));
                int y = Convert.ToInt32(c.getScreenY(height) * (0.5 * 5));

                this.EnviaMsgBlob(new Point(x, y), clienteEnvia.getCorTelepointer(), c.getFingerID(), clienteEnvia.getLogin(), "fingerMovePointer");
                // ContaTelefingerMove = 0;
                //}
            }
        }
Ejemplo n.º 4
0
        public void removeTuioCursor(TuioCursor c)
        {
            cursorList.Remove(c.getSessionID());

            // this.label1.Text = "Eemoções enviadas:" + ContaTelefingerMove.ToString();
            // ContaTelefingerMove++;

            // this.label1.Text = "Enviado:" + DateTime.Now.ToLongTimeString() + " " + DateTime.Now.Millisecond.ToString() ;

            if (clienteEnvia.connected)
            {

                int x = Convert.ToInt32(c.getScreenX(width) * (0.5 * 5));
                int y = Convert.ToInt32(c.getScreenY(height) * (0.5 * 5));

                this.EnviaMsgBlob(new Point(x, y), clienteEnvia.getCorTelepointer(), c.getFingerID(), clienteEnvia.getLogin(), "fingerRemovePointer");
            }
        }
Ejemplo n.º 5
0
        public void addTuioCursor(TuioCursor c)
        {
            // Adicionando na lista de objetos a serem varidos no método OnPaintBackground
            cursorList.Add(c.getSessionID(), c);

            if (clienteEnvia.connected)
            {
                // TODO: Resolver problema de posicionamento do TeleFinger
                // Enviando os dados para a crição do TeleFinger
                // int x = (int) c.getScreenX(width);
                // int y = (int) c.getScreenY(height);
                int x = Convert.ToInt32(c.getScreenX(width) * (0.5 * 5));
                int y = Convert.ToInt32(c.getScreenY(height) * (0.5 * 5));

                this.EnviaMsgBlob(new Point(x, y), clienteEnvia.getCorTelepointer(), c.getFingerID(), clienteEnvia.getLogin(), "fingerCreatePointer");
            }
        }
Ejemplo n.º 6
0
 public TuioCursor(TuioCursor c)
     : base(c)
 {
     this.finger_id = c.getFingerID();
 }
Ejemplo n.º 7
0
        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") && (currentFrame >= lastFrame))
                {
                    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(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))
                        {
                            updateObject.update(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") && (currentFrame >= lastFrame))
                {
                    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();
                        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")
                {
                    lastFrame    = currentFrame;
                    currentFrame = (int)args[1];
                    if (currentFrame == -1)
                    {
                        currentFrame = lastFrame;
                    }

                    if (currentFrame >= lastFrame)
                    {
                        long currentTime = lastTime;
                        if (currentFrame > lastFrame)
                        {
                            TimeSpan span = DateTime.Now - startTime;
                            currentTime = (long)span.TotalMilliseconds;
                            lastTime    = currentTime;
                        }



                        IEnumerator <TuioObject> refreshList = objectList.Values.GetEnumerator();

                        while (refreshList.MoveNext())
                        {
                            TuioObject refreshObject = refreshList.Current;
                            if (refreshObject.getUpdateTime() == TUIO_UNDEFINED)
                            {
                                refreshObject.setUpdateTime(currentTime);
                            }
                        }


                        for (int i = 0; i < listenerList.Count; i++)
                        {
                            TuioListener listener = (TuioListener)listenerList[i];
                            if (listener != null)
                            {
                                listener.refresh(currentTime);
                            }
                        }
                    }
                }
            }
            else if (address == "/tuio/2Dcur")
            {
                if ((command == "set") && (currentFrame >= lastFrame))
                {
                    long  s_id = (int)args[1];
                    float x    = (float)args[2];
                    if (this.FlipHorizontal)
                    {
                        x = 1.0f - x;
                    }

                    float y = (float)args[3];
                    if (this.FlipHorizontal)
                    {
                        y = 1.0f - y;
                    }
                    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.getFingerID();
                            freeCursorList.Remove(closestCursor);
                        }
                        else
                        {
                            maxFingerID = f_id;
                        }

                        TuioCursor addCursor = new TuioCursor(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))
                        {
                            updateCursor.update(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") && (currentFrame >= lastFrame))
                {
                    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.getFingerID();
                        cursorList.Remove(s_id);
                        removeCursor.remove();

                        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.getFingerID();
                                    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.getFingerID() < 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")
                {
                    lastFrame    = currentFrame;
                    currentFrame = (int)args[1];
                    if (currentFrame == -1)
                    {
                        currentFrame = lastFrame;
                    }

                    if (currentFrame >= lastFrame)
                    {
                        long currentTime = lastTime;
                        if (currentFrame > lastFrame)
                        {
                            TimeSpan span = DateTime.Now - startTime;
                            currentTime = (long)span.TotalMilliseconds;
                            lastTime    = currentTime;
                        }

                        IEnumerator <TuioCursor> refreshList = cursorList.Values.GetEnumerator();

                        while (refreshList.MoveNext())
                        {
                            TuioCursor refreshCursor = refreshList.Current;
                            if (refreshCursor.getUpdateTime() == TUIO_UNDEFINED)
                            {
                                refreshCursor.setUpdateTime(currentTime);
                            }
                        }

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