コード例 #1
0
 public virtual void cursorUp(TuioCursor cursor)
 {
     // find the matching event object, set the state to 'ended'
     // and remove it from our actives
     if (!activeEvents.ContainsKey(cursor.getSessionID())) return;
     BBTouchEvent anEvent = activeEvents[cursor.getSessionID()];
     anEvent.eventState = BBTouchEventState.Ended;
     lock (eventQueueLock) eventQueue.Add(anEvent);
     activeEvents.Remove( cursor.getSessionID() );
 }
コード例 #2
0
 public virtual void cursorMove(TuioCursor cursor)
 {
     // find the matching event object, set th state to 'moved'
     // and update it with the new position info
     if (!activeEvents.ContainsKey(cursor.getSessionID())) return;
     BBTouchEvent anEvent = activeEvents[cursor.getSessionID()];
     updateEvent(anEvent,cursor);
     anEvent.eventState = BBTouchEventState.Moved;
     lock (eventQueueLock) eventQueue.Add(anEvent);
 }
コード例 #3
0
ファイル: mtManager.cs プロジェクト: nuigroup/ccv-physics
 public void removeCursor(TuioCursor cursor)
 {
     if (!activeEvents.ContainsKey(cursor.getSessionID())) return;
     mtEvent anEvent = activeEvents[cursor.getSessionID()];
     anEvent.eventState = mtEventState.Ended;
     lock (eventQueueLock) {
         eventQueue.Add(anEvent);
     }
     activeEvents.Remove( cursor.getSessionID() );
     didChange = true;
 }
コード例 #4
0
ファイル: mtManager.cs プロジェクト: nuigroup/ccv-physics
    public void updateCursor(TuioCursor cursor)
    {
        if (!activeEvents.ContainsKey(cursor.getSessionID())) return;
        mtEvent anEvent = activeEvents[cursor.getSessionID()];
        anEvent.lastScreenPosition = anEvent.screenPosition;

        anEvent.screenPosition = new Vector3(cursor.getX() * cameraPixelWidth, 0,(1.0f - cursor.getY()) * cameraPixelHeight);
        anEvent.tuioPosition = new Vector2(cursor.getX(),(1.0f - cursor.getY()));
        anEvent.eventState = mtEventState.Moved;

        lock (eventQueueLock) eventQueue.Add(anEvent);
        didChange = true;
    }
コード例 #5
0
ファイル: mtManager.cs プロジェクト: nuigroup/ccv-physics
    public void newCursor(TuioCursor cursor)
    {
        mtEvent newEvent = new mtEvent(cursor.getSessionID());
        newEvent.tuioPosition = new Vector2(cursor.getX(),(1.0f - cursor.getY()));
        //switching y and z (y is up axis by default in unity)
        newEvent.screenPosition = new Vector3(cursor.getX() * cameraPixelWidth, 0,(1.0f - cursor.getY()) * cameraPixelHeight);
        newEvent.lastScreenPosition = newEvent.screenPosition;
        newEvent.eventState = mtEventState.Began;

        if (activeEvents.ContainsKey(cursor.getSessionID())) {
            //Already on list, remove old - add new
            activeEvents.Remove(cursor.getSessionID());
        }
        activeEvents.Add( cursor.getSessionID(), newEvent );
        // queue it up for processing
        lock (eventQueueLock) eventQueue.Add(newEvent);
        didChange = true;
    }
コード例 #6
0
ファイル: BBInputDelegate.cs プロジェクト: Scopty/Spixii
    // Cursor down is for new touch events. we take the TUIO cursor object and convert it
    // into a touch event, and add it to our active list of events
    public virtual void cursorDown(TuioCursor cursor)
    {
        // first, make a new BBTouchEvent, tag it with the unique touch id
        BBTouchEvent newEvent = new BBTouchEvent(cursor.getSessionID());
        // set the initial information
        newEvent.screenPosition = new Vector3(cursor.getX() * cameraPixelWidth,(1.0f - cursor.getY()) * cameraPixelHeight,0.3f);
        newEvent.eventState = BBTouchEventState.Began;
        // set all the rest of the info
        updateEvent(newEvent,cursor);

        // add it to our active event dictionary so we can retireve it based on it's unique ID
        // some times badness happens and we get an error adding one here for some reason
        // it should not ever be the case that the ID is already there.
        // if it is, then we need to behave
        if (activeEvents.ContainsKey(cursor.getSessionID())) {
            // then something is not right.. remove the old one and add a new one
            activeEvents.Remove(cursor.getSessionID());
        }
        activeEvents.Add( cursor.getSessionID(), newEvent );
        // queue it up for processing
        lock (eventQueueLock) eventQueue.Add(newEvent);
    }
コード例 #7
0
 public void updateTuioCursor(TuioCursor c)
 {
     if (verbose) Console.WriteLine("set cur " + c.getCursorID() + " (" + c.getSessionID() + ") " + c.getX() + " " + c.getY() + " " + c.getMotionSpeed() + " " + c.getMotionAccel());
     mainGrid.checkCursor((c.getX() * TuioDemo.width), (c.getY() * TuioDemo.height), c.getCursorID(), code);
 }
コード例 #8
0
ファイル: TuioClient.cs プロジェクト: Jasmin91/Tui_My_Child
        /**
         * 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();
                }
            }
        }
コード例 #9
0
ファイル: TuioDemo.cs プロジェクト: tasku12/TUIO
 public void removeTuioCursor(TuioCursor c)
 {
     lock(cursorSync) {
             cursorList.Remove(c.getSessionID());
         }
         if (verbose) Console.WriteLine("del cur "+c.getCursorID() + " ("+c.getSessionID()+")");
 }
コード例 #10
0
        private void processTouchOnlyAddEvent(TuioCursor tcur)
        {
            lock (touchOnlyLock)
            {
                // Make sure touch point isn't already dragging something else
                if (!draggedObjects.Keys.Contains(tcur.getSessionID()))
                {
                    // Find the closest touched freeObject to this touch point
                    Vector2 tcurStartPos = new Vector2(tcur.getPath()[0].getScreenX(Settings.RESOLUTION_X), tcur.getPath()[0].getScreenY(Settings.RESOLUTION_Y));
                    float closestDistance = float.PositiveInfinity;
                    TuioObject closestTobj = null;

                    foreach (TuioObject tobj in freeObjects.Values)
                    //foreach (TuioObject tobj in tuioObjects.Values)
                    {
                        if (!draggedObjects.ContainsKey(tobj.getSessionID()))
                        {
                            Vector2 tobjPosition = new Vector2(tobj.getScreenX(Settings.RESOLUTION_X), tobj.getScreenY(Settings.RESOLUTION_Y));
                            float distance = Vector2.Distance(tcurStartPos, tobjPosition);
                            if (distance < closestDistance && distance < Settings.CIRCLE_RADIUS)
                            {
                                // Found a closer freeObject
                                closestDistance = distance;
                                closestTobj = tobj;
                            }
                        }
                    }
                    if (closestTobj != null)
                    {
                        Vector2 closestTobjPosition = new Vector2(closestTobj.getScreenX(Settings.RESOLUTION_X), closestTobj.getScreenY(Settings.RESOLUTION_Y));
                        draggedObjects.TryAdd(tcur.getSessionID(), closestTobj);
                        dragDiffVectors.TryAdd(tcur.getSessionID(), tcurStartPos - closestTobjPosition);
                        TuioObject outTobj;
                        freeObjects.TryRemove(closestTobj.getSymbolID(), out outTobj);
                        Debug.WriteLine("Grabbing  " + closestTobj.getSymbolID() + " with " + +tcur.getSessionID());
                    }
                }
            }
        }
コード例 #11
0
ファイル: mtPartManager.cs プロジェクト: nuigroup/ccv-physics
    public void updateCursor(TuioCursor cursor)
    {
        if (!activeEvents.ContainsKey(cursor.getSessionID())) return;
        mtCntrEvent anEvent = activeEvents[cursor.getSessionID()];
        anEvent.eventState = mtEventState.Moved;

        if(cursor.getContour() != null)
        {
            List<TuioPoint> contr = cursor.getContour();
            List<Vector3> cntrPoints = new List<Vector3>();
            foreach(TuioPoint pnt in contr)
            {
                float xC = pnt.getX();
                float yC = pnt.getY();
                cntrPoints.Add(new Vector3(xC * cameraPixelWidth, 0, (1.0f - yC ) * cameraPixelHeight));
            }
            anEvent.contour = cntrPoints.ToArray();

            //calibrate and CoM (center of mass)
            float xCoM = 0.0F;
            float yCoM = 0.0F;
            Matrix mat = Matrix.Translate(xTCalib, yTCalib, 0.0F);
            for(int i=0; i<anEvent.contour.Length; i++)
            {
                anEvent.contour[i] = mat.TransformVector( anEvent.contour[i] );
                xCoM += anEvent.contour[i].x;
                yCoM += anEvent.contour[i].y;
            }
            xCoM /= anEvent.contour.Length;
            yCoM /= anEvent.contour.Length;

            //translate to 0
            for(int i=0; i<anEvent.contour.Length; i++)
            {
                anEvent.contour[i].x -= xCoM;
                anEvent.contour[i].y -= yCoM;
            }

            anEvent.lastScreenPosition = anEvent.screenPosition;
            anEvent.screenPosition = new Vector3(xCoM, 0, yCoM);

        }

        lock (eventQueueLock) eventQueue.Add(anEvent);
        didChange = true;
    }
コード例 #12
0
ファイル: Surface.cs プロジェクト: Geistyp/grafiti
 public void updateTuioCursor(TuioCursor c)
 {
     m_updatingCursors.Add(
         new CursorPoint((int)(c.getSessionID()),
         (c.getX() + OFFSET_X) * CAMERA_RESOLUTION_RATIO,
         c.getY(),
         CursorPoint.States.UPDATED));
 }
コード例 #13
0
ファイル: Surface.cs プロジェクト: Geistyp/grafiti
 public void removeTuioCursor(TuioCursor c)
 {
     m_removingCursors.Add(
         new CursorPoint((int)(c.getSessionID()),
         (c.getX() + OFFSET_X) * CAMERA_RESOLUTION_RATIO,
         c.getY(),
         CursorPoint.States.REMOVED));
 }
コード例 #14
0
ファイル: frmKeyboard.cs プロジェクト: pichiliani/CoMusic
        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");
            }
        }
コード例 #15
0
ファイル: frmKeyboard.cs プロジェクト: pichiliani/CoMusic
        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");
            }
        }
コード例 #16
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();
                }
            }
        }
コード例 #17
0
ファイル: TuioClient.cs プロジェクト: nuigroup/ccv-physics
        /**
         * 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();
                }

            }
        }
コード例 #18
0
ファイル: TuioDump.cs プロジェクト: tasku12/TUIO
 public void addTuioCursor(TuioCursor tcur)
 {
     Console.WriteLine("add cur "+tcur.getCursorID() + " ("+tcur.getSessionID()+") "+tcur.getX()+" "+tcur.getY());
 }
コード例 #19
0
 private bool IsUpsideDown(TuioCursor tcur)
 {
     bool upsideDown = false;
     //int cursorID2 = tcur.getPointsorID();
     int cursorID = (int)tcur.getSessionID();
     //Debug.WriteLine("Cursor session ID: " + cursorID);
     //Debug.WriteLine("Cursor ID: " + cursorID2);
     // Search all currently known hands for the cursor ID
     foreach (TuioHand thand in tuioHands.Values)
     {
         if (thand.getFingerID1() == cursorID || thand.getFingerID2() == cursorID || thand.getFingerID3() == cursorID || thand.getFingerID4() == cursorID || thand.getFingerID5() == cursorID)
         {
             if (thand.getY() < tcur.getY())
                 upsideDown = true;
         }
     }
     return upsideDown;
 }
コード例 #20
0
ファイル: TuioDump.cs プロジェクト: tasku12/TUIO
 public void removeTuioCursor(TuioCursor tcur)
 {
     Console.WriteLine("del cur "+tcur.getCursorID() + " ("+tcur.getSessionID()+")");
 }
コード例 #21
0
        private void processTouchOnlyUpdateEvent(TuioCursor tcur)
        {
            lock (touchOnlyLock)
            {
                if (draggedObjects.ContainsKey(tcur.getSessionID()))
                {
                    // Move the currently dragged TuioObject according to its dragging cursor
                    Vector2 tcurPosition = new Vector2(tcur.getScreenX(Settings.RESOLUTION_X), tcur.getScreenY(Settings.RESOLUTION_Y));
                    TuioObject tobj = draggedObjects[tcur.getSessionID()];
                    Vector2 dragDiffVector = dragDiffVectors[tcur.getSessionID()];
                    Vector2 newObjPos = new Vector2((tcurPosition.X - dragDiffVector.X) / (float)Settings.RESOLUTION_X, (tcurPosition.Y - dragDiffVector.Y) / (float)Settings.RESOLUTION_Y);
                    // Don't let objects move off screen
                    if (newObjPos.X >= 0 && newObjPos.X <= 1 && newObjPos.Y >= 0 && newObjPos.Y <= 1)
                    {

                        //tobj.update(TuioTime.getSessionTime(), (tcurPosition.X - dragDiffVector.X) / (float)Settings.RESOLUTION_X, (tcurPosition.Y - dragDiffVector.Y) / (float)Settings.RESOLUTION_Y, tcur.getXSpeed(), tcur.getYSpeed(), tcur.getMotionAccel());
                        //tobj.update(TuioTime.getSessionTime(), newObjPos.X, newObjPos.Y);
                        tobj.update(TuioTime.getSessionTime(), newObjPos.X, newObjPos.Y, tcur.getXSpeed(), tcur.getYSpeed(), tcur.getMotionAccel());
                        draggedObjects.AddOrUpdate(tobj.getSymbolID(), tobj, updateTObj);
                        //tuioObjects.AddOrUpdate(tobj.getSymbolID(), tobj, updateTObj);
                        this.updateTuioObject(tobj);
                        Debug.WriteLine("Moving " + tobj.getSymbolID() + " with " + tcur.getSessionID() + " at speed " + tcur.getXSpeed() + ", " + tcur.getYSpeed());
                    }

                    /*
                    // Update corresponding ZoomCircle
                    // Calculate speed from x and y speeds
                    float totalSpeed = (float)Math.Sqrt(Math.Pow(tobj.getXSpeed() * Settings.RESOLUTION_X, 2) + Math.Pow(tobj.getYSpeed() * Settings.RESOLUTION_Y, 2));

                    // Ignore implausibly high values because Multitaction is giving us speeds of "Infinity" every couple updates
                    if (totalSpeed > 1000f)
                        totalSpeed = 0f;

                    //Debug.WriteLine(totalSpeed);
                    zoomedCircles[tobj.getSymbolID()].MoveTo(tobj.getScreenX(Settings.RESOLUTION_X), tobj.getScreenY(Settings.RESOLUTION_Y), tobj.getAngleDegrees(), this.GetMovieTimestamp(), this.GetMovieTimestampRaw(), totalSpeed);
                    */
                }
            }
        }
コード例 #22
0
ファイル: TuioDump.cs プロジェクト: tasku12/TUIO
 public void updateTuioCursor(TuioCursor tcur)
 {
     Console.WriteLine("set cur "+tcur.getCursorID() + " ("+tcur.getSessionID()+") "+tcur.getX()+" "+tcur.getY()+" "+tcur.getMotionSpeed()+" "+tcur.getMotionAccel());
 }
コード例 #23
0
ファイル: TuioDemo.cs プロジェクト: tasku12/TUIO
 public void addTuioCursor(TuioCursor c)
 {
     lock(cursorSync) {
             cursorList.Add(c.getSessionID(),c);
         }
         if (verbose) Console.WriteLine("add cur "+c.getCursorID() + " ("+c.getSessionID()+") "+c.getX()+" "+c.getY());
 }
コード例 #24
0
 public void removeTuioCursor(TuioCursor tuioCursor)
 {
     this.Dispatcher.Invoke(
         DispatcherPriority.Normal,
         (Action)(() =>
         {
             BSQSim.RemoveTouchDevice((int)tuioCursor.getSessionID());
         }));
 }
コード例 #25
0
ファイル: TuioDemo.cs プロジェクト: tasku12/TUIO
 public void updateTuioCursor(TuioCursor c)
 {
     if (verbose) Console.WriteLine("set cur "+c.getCursorID() + " ("+c.getSessionID()+") "+c.getX()+" "+c.getY()+" "+c.getMotionSpeed()+" "+c.getMotionAccel());
 }
コード例 #26
0
 public void addTuioCursor(TuioCursor tuioCursor)
 {
     this.Dispatcher.Invoke(
         DispatcherPriority.Normal,
         (Action)(() =>
         {
             BSQSim.AddTouchDevice((int)tuioCursor.getSessionID(),
                 new Point(tuioCursor.getScreenX(Convert.ToInt32(DISPLAY_W)), tuioCursor.getScreenY(Convert.ToInt32(DISPLAY_H))));
         }));
 }
コード例 #27
0
ファイル: mtCntrManager.cs プロジェクト: nuigroup/ccv-physics
    public void updateCursor(TuioCursor cursor)
    {
        if (!activeEvents.ContainsKey(cursor.getSessionID())) return;
        mtCntrEvent anEvent = activeEvents[cursor.getSessionID()];
        anEvent.eventState = mtEventState.Moved;

        if(cursor.getContour() != null)
        {
            List<TuioPoint> contr = cursor.getContour();
            List<Vector3> cntrPoints = new List<Vector3>();
            foreach(TuioPoint pnt in contr)
            {
                float xC = pnt.getX();
                float yC = pnt.getY();
                cntrPoints.Add(new Vector3(xC * cameraPixelWidth, (1.0f - yC ) * cameraPixelHeight, 0));
            }
            anEvent.contour = cntrPoints.ToArray();
            //calibrate and CoM (center of mass)
            float xCoM = 0.0F;
            float yCoM = 0.0F;
            Matrix mat = Matrix.Translate(xTCalib, yTCalib, 0.0F);
            for(int i=0; i<anEvent.contour.Length; i++)
            {
                anEvent.contour[i] = mat.TransformVector( anEvent.contour[i] );
                xCoM += anEvent.contour[i].x;
                yCoM += anEvent.contour[i].y;
            }
            xCoM /= anEvent.contour.Length;
            yCoM /= anEvent.contour.Length;

            //translate to 0
            for(int i=0; i<anEvent.contour.Length; i++)
            {
                anEvent.contour[i].x -= xCoM;
                anEvent.contour[i].y -= yCoM;
            }

            anEvent.lastScreenPosition = anEvent.screenPosition;
            anEvent.screenPosition = new Vector3(xCoM, 0, yCoM);

            /*
            anEvent.lastTime = anEvent.currentTime;
            anEvent.currentTime = Time.time;
            float dt = anEvent.currentTime - anEvent.lastTime; //delta time
            if(dt > 0)
            {
                float dx = anEvent.lastScreenPosition.x - anEvent.screenPosition.x;
                float dy = anEvent.lastScreenPosition.z - anEvent.screenPosition.z;
                float distance = (float)Mathf.Sqrt(dx*dx+dy*dy);
                float lastMspeed = anEvent.mAccel;
                anEvent.x_speed = dx / dt; // delta x / delta time = velocity x
                anEvent.y_speed = dy / dt; // -||-
                anEvent.mSpeed = distance / dt;
                anEvent.mAccel = (anEvent.mSpeed - lastMspeed) / dt;
            }
            */
        }

        lock (eventQueueLock) eventQueue.Add(anEvent);
        didChange = true;
    }
コード例 #28
0
ファイル: TuioClient.cs プロジェクト: yothere/TUIO
        /**
         * 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();
                }

            }
        }
コード例 #29
0
		public void RemoveTuioCursor(TuioCursor tuioCursor)
		{
			_refreshTimer.Stop();

			int pid = tuioCursor.getCursorID();

			int i = _pointerTouchInfos.FindIndex(pti => pti.PointerInfo.PointerId == pid);
			if (i != -1)
			{
				PointerTouchInfo pointerTouchInfo = _pointerTouchInfos[i];
				pointerTouchInfo.PointerInfo.PointerFlags = PointerFlags.UP;
				_pointerTouchInfos[i] = pointerTouchInfo;

				Trace.WriteLine(string.Format("del cur {0} ({1})", pid, tuioCursor.getSessionID()), "TUIO");
			}
		}
コード例 #30
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();
                }
            }
        }
コード例 #31
0
		public void AddTuioCursor(TuioCursor tuioCursor)
		{
			_refreshTimer.Stop();

			int pid = tuioCursor.getCursorID();

			int i = _pointerTouchInfos.FindIndex(pti => pti.PointerInfo.PointerId == pid);
			if (i != -1)
			{
				_pointerTouchInfos.RemoveAt(i);
			}

			int x = (int)((tuioCursor.getX() * (_screenRect.Width + _calibrationBuffer.Width)) + _calibrationBuffer.Left + _screenRect.Left);
			int y = (int)((tuioCursor.getY() * (_screenRect.Height + _calibrationBuffer.Height)) + _calibrationBuffer.Top + _screenRect.Top);

			_pointerTouchInfos.Add
			(
				new PointerTouchInfo()
				{
					TouchFlags = TouchFlags.NONE,
					Orientation = TOUCH_ORIENTATION,
					Pressure = TOUCH_PRESSURE,
					TouchMasks = TouchMask.CONTACTAREA | TouchMask.ORIENTATION | TouchMask.PRESSURE,
					PointerInfo = new PointerInfo
					{
						PointerInputType = PointerInputType.TOUCH,
						PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | ((this.IsContactEnabled) ? PointerFlags.INCONTACT : PointerFlags.NONE),
						PtPixelLocation = new PointerTouchPoint { X = x, Y = y },
						PointerId = (uint)pid
					},
					ContactArea = new ContactArea
					{
						Left = x - CONTACT_AREA_RADIUS,
						Right = x + CONTACT_AREA_RADIUS,
						Top = y - CONTACT_AREA_RADIUS,
						Bottom = y + CONTACT_AREA_RADIUS
					}
				}
			);

			Trace.WriteLine(string.Format("add cur {0} ({1}) {2} {3}", pid, tuioCursor.getSessionID(), x, y), "TUIO");
		}
コード例 #32
0
		public void UpdateTuioCursor(TuioCursor tuioCursor)
		{
			_refreshTimer.Stop();

			int pid = tuioCursor.getCursorID();

			int i = _pointerTouchInfos.FindIndex(pti => pti.PointerInfo.PointerId == pid);
			if (i != -1)
			{
				int x = (int)((tuioCursor.getX() * (_screenRect.Width + _calibrationBuffer.Width)) + _calibrationBuffer.Left + _screenRect.Left);
				int y = (int)((tuioCursor.getY() * (_screenRect.Height + _calibrationBuffer.Height)) + _calibrationBuffer.Top + _screenRect.Top);

				PointerTouchInfo pointerTouchInfo = _pointerTouchInfos[i];
				pointerTouchInfo.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | ((this.IsContactEnabled) ? PointerFlags.INCONTACT : PointerFlags.NONE);
				pointerTouchInfo.PointerInfo.PtPixelLocation = new PointerTouchPoint { X = x, Y = y };
				pointerTouchInfo.ContactArea = new ContactArea
				{
					Left = x - CONTACT_AREA_RADIUS,
					Right = x + CONTACT_AREA_RADIUS,
					Top = y - CONTACT_AREA_RADIUS,
					Bottom = y + CONTACT_AREA_RADIUS
				};
				_pointerTouchInfos[i] = pointerTouchInfo;

				Trace.WriteLine(string.Format("set cur {0} ({1}) {2} {3} {4} {5}", pid, tuioCursor.getSessionID(), x, y, tuioCursor.getMotionSpeed(), tuioCursor.getMotionAccel()), "TUIO");
			}	
		}
コード例 #33
-1
/*