Inheritance: TuioContainer
    void Update()
    {
        this.UpdateCounter();

        if (this.m_TuioManager.IsMarkerAlive(this.MarkerID))
        {
        }


        if (this.m_TuioManager.IsConnected &&
            this.m_TuioManager.IsMarkerAlive(this.MarkerID))
        {
            TUIO.TuioObject marker = this.m_TuioManager.GetMarker(this.MarkerID);

            //update parameters
            this.m_ScreenPosition.x = marker.getX();
            this.m_ScreenPosition.y = this.yAxe;
            //update transform component
            UpdateTransform();
        }

        if (AppleCounter >= 4)
        {
            if (!Play)
            {
                WinSound.Play();
                Play = true;
            }
            Countdown -= Time.deltaTime;
            if (Countdown <= 0.0f)
            {
                this.ms_Instance.FinishGame();
            }
        }
    }
Exemple #2
0
 public void removeTuioObject(TuioObject o)
 {
     lock(objectSync) {
         objectList.Remove(o.SessionID);
     }
     if (verbose) Console.WriteLine("del obj "+o.SymbolID+" ("+o.SessionID+")");
 }
    void Update()
    {
        if (ShouldWait)
        {
            WaitingToMove -= Time.deltaTime;
            if (WaitingToMove <= 0.0f)
            {
                ShouldWait = false;
            }
        }



        if (this.m_TuioManager.IsConnected &&
            this.m_TuioManager.IsMarkerAlive(this.MarkerID) && !ShouldWait)
        {
            GetComponent <Rigidbody2D>().velocity = new Vector2(0.5f, 0);//Setze Geschwindigkeit, sobald Fiducial sichtbar

            TUIO.TuioObject marker = this.m_TuioManager.GetMarker(this.MarkerID);

            //update parameters
            this.m_Angle        = marker.getAngle() * RotationMultiplier;
            this.m_AngleDegrees = marker.getAngleDegrees() * RotationMultiplier;


            //update transform component
            UpdateTransform();
            this.actRotation = GetComponent <Rigidbody2D>().transform.rotation;
        }
        else
        {
            GetComponent <Rigidbody2D>().velocity           = new Vector2(0, 0);//Setze Geschwindigkeit auf 0, sobald Fiducial unsichtbar
            GetComponent <Rigidbody2D>().transform.rotation = this.actRotation;
        }
    }
Exemple #4
0
    void Update()
    {
        if (this.m_TuioManager.IsMarkerAlive(this.MarkerID))
        {
            //Debug.Log("FidcialController Zeile 110:this.m_TuioManager.IsMarkerAlive(this.MarkerID)");
        }


        if (this.m_TuioManager.IsConnected &&
            this.m_TuioManager.IsMarkerAlive(this.MarkerID))
        {
            TUIO.TuioObject marker = this.m_TuioManager.GetMarker(this.MarkerID);

            //update parameters
            this.m_IsVisible = true;

            //set game object to visible, if it was hidden before
            ShowGameObject();
        }
        else
        {
            //automatically hide game object when marker is not visible
            if (this.AutoHideGO)
            {
                HideGameObject();
            }

            this.m_IsVisible = false;
        }
    }
Exemple #5
0
    void Update()
    {
        if (this.m_TuioManager.IsMarkerAlive(this.MarkerID))
        {
        }


        if (this.m_TuioManager.IsConnected &&
            this.m_TuioManager.IsMarkerAlive(this.MarkerID))
        {
            TUIO.TuioObject marker = this.m_TuioManager.GetMarker(this.MarkerID);

            //update parameters
            this.m_IsVisible = true;

            //set game object to visible, if it was hidden before
            ShowGameObject();
            if (warWeg)
            {
                ms_Instance.EinApfelFaellt();
                this.warWeg = false;
            }
        }
        else
        {
            //automatically hide game object when marker is not visible
            if (this.AutoHideGO)
            {
                HideGameObject();
            }
            this.m_IsVisible = false;
            this.warWeg      = true; //Stellt sicher, dass Fiducial für jeden Apfel neu gezeigt werden muss
        }
    }
    void Update()
    {
        if (this.m_TuioManager.IsConnected &&
            this.m_TuioManager.IsMarkerAlive(this.MarkerID))
        {
            if (!ShouldWait)
            {
                TUIO.TuioObject marker = this.m_TuioManager.GetMarker(this.MarkerID);

                this.m_IsVisible = true;

                //set game object to visible, if it was hidden before
                ShowGameObject();
            }
        }
        else
        {
            //automatically hide game object when marker is not visible
            if (this.AutoHideGO)
            {
                HideGameObject();
                ShouldWait = false;
            }
            this.m_IsVisible = false;
        }
    }
Exemple #7
0
    /// <summary>
    /// Alle Fiducials müssen sichtbar sein. x-Wert wird aus Durchschnitt aller x-Werte aller Fiducials berechnet
    /// </summary>
    void Update()
    {
        if (this.m_TuioManager.IsConnected && this.m_TuioManager.IsMarkerAlive(this.MarkerID0) && this.m_TuioManager.IsMarkerAlive(this.MarkerID1) && this.m_TuioManager.IsMarkerAlive(this.MarkerID2) && this.m_TuioManager.IsMarkerAlive(this.MarkerID3))
        {
            string s       = "aktiv:";
            int    counter = 0;
            float  posX    = 0;
            float  x       = this.transform.position.x;

            if (this.m_TuioManager.IsMarkerAlive(this.MarkerID0))
            {
                TUIO.TuioObject marker0 = this.m_TuioManager.GetMarker(0);
                posX += marker0.getX();
                s    += this.MarkerID0 + " posX:" + marker0.getX() + "+";

                counter++;
            }
            if (this.m_TuioManager.IsMarkerAlive(this.MarkerID1))
            {
                TUIO.TuioObject marker1 = this.m_TuioManager.GetMarker(1);
                posX += marker1.getX();
                s    += this.MarkerID1 + " posX:" + marker1.getX() + "+";
                counter++;
            }
            if (this.m_TuioManager.IsMarkerAlive(this.MarkerID2))
            {
                TUIO.TuioObject marker2 = this.m_TuioManager.GetMarker(2);
                posX += marker2.getX();
                s    += this.MarkerID2 + " posX:" + marker2.getX() + "+";
                counter++;
            }
            if (this.m_TuioManager.IsMarkerAlive(this.MarkerID3))
            {
                TUIO.TuioObject marker3 = this.m_TuioManager.GetMarker(3);
                posX += marker3.getX();
                s    += this.MarkerID3 + " posX:" + marker3.getX() + "+";
                counter++;
            }
            if (counter > 0)
            {
                x = posX / counter;
            }
            s += "=" + x;

            //Debug.Log(s);

            if (counter > 0)
            {
                Vector3 position = new Vector3(x * Screen.width,
                                               (1 - this.m_ScreenPosition.y) * Screen.height, this.CameraOffset);
                this.m_WorldPosition = this.m_MainCamera.ScreenToWorldPoint(position);
                transform.position   = new Vector3(this.m_WorldPosition.x, PosY, -1);
            }
        }
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            Application.Quit();
        }
    }
Exemple #8
0
 public TuioObject(TuioObject o)
     : base(o)
 {
     this.fiducial_id = o.getFiducialID();
     this.angle = o.getAngle();
     this.rotation_speed = 0.0f;
     this.rotation_accel = 0.0f;
 }
    void Update()
    {
        if (this.m_TuioManager.IsConnected &&
            this.m_TuioManager.IsMarkerAlive(this.MarkerID))
        {
            TUIO.TuioObject marker = this.m_TuioManager.GetMarker(this.MarkerID);

            //update parameters
            this.m_ScreenPosition.x     = marker.getX();
            this.m_ScreenPosition.y     = marker.getY();
            this.m_Angle                = marker.getAngle() * RotationMultiplier;
            this.m_AngleDegrees         = marker.getAngleDegrees() * RotationMultiplier;
            this.m_Speed                = marker.getMotionSpeed();
            this.m_Acceleration         = marker.getMotionAccel();
            this.m_RotationSpeed        = marker.getRotationSpeed() * RotationMultiplier;
            this.m_RotationAcceleration = marker.getRotationAccel();
            this.m_Direction.x          = marker.getXSpeed();
            this.m_Direction.y          = marker.getYSpeed();
            this.m_IsVisible            = true;

            if (this.fitGrid)
            {
                //fit position into the grid
                int colX = (int)(marker.getX() / this.gridSize);
                this.m_ScreenPosition.x = (float)(colX * this.gridSize);
                int colY = (int)(marker.getY() / this.gridSize);
                this.m_ScreenPosition.y = (float)(colY * this.gridSize);

                //fit rotation angle into a grid
                int step = (int)(marker.getAngleDegrees() / this.rotationGridSize);
                this.m_AngleDegrees = (float)(step * this.rotationGridSize);
            }

            //set game object to visible, if it was hidden before
            ShowGameObject();

            //update transform component
            UpdateTransform();
        }
        else
        {
            //automatically hide game object when marker is not visible
            if (this.AutoHideGO)
            {
                HideGameObject();
            }

            this.m_IsVisible = false;
        }
    }
Exemple #10
0
    void Update()
    {
        if (this.m_TuioManager.IsMarkerAlive(this.MarkerID))
        {
        }


        if (this.m_TuioManager.IsConnected &&
            this.m_TuioManager.IsMarkerAlive(this.MarkerID))
        {
            TUIO.TuioObject marker = this.m_TuioManager.GetMarker(this.MarkerID);

            //update parameters
            this.m_ScreenPosition.x     = marker.getX();
            this.m_ScreenPosition.y     = marker.getY();
            this.m_Angle                = marker.getAngle() * RotationMultiplier;
            this.m_AngleDegrees         = marker.getAngleDegrees() * RotationMultiplier;
            this.m_Speed                = marker.getMotionSpeed();
            this.m_Acceleration         = marker.getMotionAccel();
            this.m_RotationSpeed        = marker.getRotationSpeed() * RotationMultiplier;
            this.m_RotationAcceleration = marker.getRotationAccel();
            this.m_Direction.x          = marker.getXSpeed();
            this.m_Direction.y          = marker.getYSpeed();
            this.m_IsVisible            = true;

            //set game object to visible, if it was hidden before
            ShowGameObject();

            //update transform component
            UpdateTransform();
        }
        else
        {
            //automatically hide game object when marker is not visible
            if (this.AutoHideGO)
            {
                HideGameObject();
            }

            this.m_IsVisible = false;
        }
    }
Exemple #11
0
    void Update()
    {
        if (this.m_TuioManager.IsMarkerAlive(this.MarkerID))
        {
        }


        if (this.m_TuioManager.IsConnected &&
            this.m_TuioManager.IsMarkerAlive(this.MarkerID))
        {
            TUIO.TuioObject marker = this.m_TuioManager.GetMarker(this.MarkerID);

            //update parameters
            this.m_Angle                = marker.getAngle() * RotationMultiplier;
            this.m_AngleDegrees         = marker.getAngleDegrees() * RotationMultiplier;
            this.m_Acceleration         = marker.getMotionAccel();
            this.m_RotationSpeed        = marker.getRotationSpeed() * RotationMultiplier;
            this.m_RotationAcceleration = marker.getRotationAccel();
            this.m_Direction.x          = marker.getXSpeed();
            this.m_Direction.y          = marker.getYSpeed();


            //update transform component
            if (rotate)
            {
                UpdateTransform();
            }
        }
        else
        {
            this.m_IsVisible = false;
        }

        if (this.Manager.GetRightWayFound())
        {
            this.rotate = false; //Lässt Gelenk nur drehen, solang der richtige Weg noch nicht gefunden wurde
        }
    }
        private void processMessage(OSCMessage message)
        {
            string    address = message.Address;
            ArrayList args    = message.Values;
            string    command = (string)args[0];

            if (address == "/tuio/2Dobj")
            {
                if ((command == "set") && (currentFrame >= lastFrame))
                {
                    long  s_id = (int)args[1];
                    int   f_id = (int)args[2];
                    float x    = (float)args[3];
                    float y    = (float)args[4];
                    float a    = (float)args[5];
                    float X    = (float)args[6];
                    float Y    = (float)args[7];
                    float A    = (float)args[8];
                    float m    = (float)args[9];
                    float r    = (float)args[10];


                    if (!objectList.ContainsKey(s_id))
                    {
                        TuioObject addObject = new TuioObject(s_id, f_id, x, y, a);
                        objectList.Add(s_id, addObject);

                        for (int i = 0; i < listenerList.Count; i++)
                        {
                            TuioListener listener = (TuioListener)listenerList[i];
                            if (listener != null)
                            {
                                listener.addTuioObject(addObject);
                            }
                        }
                    }
                    else
                    {
                        TuioObject updateObject = objectList[s_id];

                        if ((updateObject.getX() != x) || (updateObject.getY() != y) || (updateObject.getAngle() != a))
                        {
                            updateObject.update(x, y, a, X, Y, A, m, r);
                            for (int i = 0; i < listenerList.Count; i++)
                            {
                                TuioListener listener = (TuioListener)listenerList[i];
                                if (listener != null)
                                {
                                    listener.updateTuioObject(updateObject);
                                }
                            }
                            //objectList[s_id] = tobj;
                        }
                    }
                }
                else if ((command == "alive") && (currentFrame >= lastFrame))
                {
                    for (int i = 1; i < args.Count; i++)
                    {
                        // get the message content
                        long s_id = (int)args[i];
                        newObjectList.Add(s_id);
                        // reduce the object list to the lost objects
                        if (aliveObjectList.Contains(s_id))
                        {
                            aliveObjectList.Remove(s_id);
                        }
                    }

                    // remove the remaining objects
                    for (int i = 0; i < aliveObjectList.Count; i++)
                    {
                        long       s_id         = aliveObjectList[i];
                        TuioObject removeObject = objectList[s_id];
                        removeObject.remove();
                        objectList.Remove(s_id);


                        for (int j = 0; j < listenerList.Count; j++)
                        {
                            TuioListener listener = (TuioListener)listenerList[j];
                            if (listener != null)
                            {
                                listener.removeTuioObject(removeObject);
                            }
                        }
                    }

                    List <long> buffer = aliveObjectList;
                    aliveObjectList = newObjectList;

                    // recycling of the List
                    newObjectList = buffer;
                    newObjectList.Clear();
                }
                else if (command == "fseq")
                {
                    lastFrame    = currentFrame;
                    currentFrame = (int)args[1];
                    if (currentFrame == -1)
                    {
                        currentFrame = lastFrame;
                    }

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



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

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


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

                    float y = (float)args[3];
                    if (this.FlipHorizontal)
                    {
                        y = 1.0f - y;
                    }
                    float X = (float)args[4];
                    float Y = (float)args[5];
                    float m = (float)args[6];

                    if (!cursorList.ContainsKey(s_id))
                    {
                        int f_id = cursorList.Count;
                        if (cursorList.Count <= maxFingerID)
                        {
                            TuioCursor closestCursor          = freeCursorList[0];
                            IEnumerator <TuioCursor> testList = freeCursorList.GetEnumerator();
                            while (testList.MoveNext())
                            {
                                TuioCursor testCursor = testList.Current;
                                if (testCursor.getDistance(x, y) < closestCursor.getDistance(x, y))
                                {
                                    closestCursor = testCursor;
                                }
                            }
                            f_id = closestCursor.getFingerID();
                            freeCursorList.Remove(closestCursor);
                        }
                        else
                        {
                            maxFingerID = f_id;
                        }

                        TuioCursor addCursor = new TuioCursor(s_id, f_id, x, y);
                        cursorList.Add(s_id, addCursor);

                        for (int i = 0; i < listenerList.Count; i++)
                        {
                            TuioListener listener = (TuioListener)listenerList[i];
                            if (listener != null)
                            {
                                listener.addTuioCursor(addCursor);
                            }
                        }
                    }
                    else
                    {
                        TuioCursor updateCursor = (TuioCursor)cursorList[s_id];
                        if ((updateCursor.getX() != x) || (updateCursor.getY() != y))
                        {
                            updateCursor.update(x, y, X, Y, m);
                            for (int i = 0; i < listenerList.Count; i++)
                            {
                                TuioListener listener = (TuioListener)listenerList[i];
                                if (listener != null)
                                {
                                    listener.updateTuioCursor(updateCursor);
                                }
                            }


                            //cursorList[s_id] = tcur;
                        }
                    }
                }
                else if ((command == "alive") && (currentFrame >= lastFrame))
                {
                    for (int i = 1; i < args.Count; i++)
                    {
                        // get the message content
                        long s_id = (int)args[i];
                        newCursorList.Add(s_id);
                        // reduce the cursor list to the lost cursors
                        if (aliveCursorList.Contains(s_id))
                        {
                            aliveCursorList.Remove(s_id);
                        }
                    }

                    // remove the remaining cursors
                    for (int i = 0; i < aliveCursorList.Count; i++)
                    {
                        long s_id = aliveCursorList[i];
                        if (!cursorList.ContainsKey(s_id))
                        {
                            continue;
                        }
                        TuioCursor removeCursor = cursorList[s_id];
                        int        c_id         = removeCursor.getFingerID();
                        cursorList.Remove(s_id);
                        removeCursor.remove();

                        if (c_id == maxFingerID)
                        {
                            maxFingerID = -1;


                            if (cursorList.Count > 0)
                            {
                                IEnumerator <KeyValuePair <long, TuioCursor> > clist = cursorList.GetEnumerator();
                                while (clist.MoveNext())
                                {
                                    int f_id = clist.Current.Value.getFingerID();
                                    if (f_id > maxFingerID)
                                    {
                                        maxFingerID = f_id;
                                    }
                                }

                                List <TuioCursor>        freeCursorBuffer = new List <TuioCursor>();
                                IEnumerator <TuioCursor> flist            = freeCursorList.GetEnumerator();
                                while (flist.MoveNext())
                                {
                                    TuioCursor testCursor = flist.Current;

                                    if (testCursor.getFingerID() < maxFingerID)
                                    {
                                        freeCursorBuffer.Add(testCursor);
                                    }
                                }
                                freeCursorList = freeCursorBuffer;
                            }
                        }
                        else if (c_id < maxFingerID)
                        {
                            freeCursorList.Add(removeCursor);
                        }


                        for (int j = 0; j < listenerList.Count; j++)
                        {
                            TuioListener listener = (TuioListener)listenerList[j];

                            if (listener != null)
                            {
                                listener.removeTuioCursor(removeCursor);
                            }
                        }
                    }

                    List <long> buffer = aliveCursorList;
                    aliveCursorList = newCursorList;

                    // recycling of the List
                    newCursorList = buffer;
                    newCursorList.Clear();
                }
                else if (command == "fseq")
                {
                    lastFrame    = currentFrame;
                    currentFrame = (int)args[1];
                    if (currentFrame == -1)
                    {
                        currentFrame = lastFrame;
                    }

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

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

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

                        for (int i = 0; i < listenerList.Count; i++)
                        {
                            TuioListener listener = (TuioListener)listenerList[i];
                            if (listener != null)
                            {
                                listener.refresh(currentTime);
                            }
                        }
                    }
                }
            }
        }
Exemple #13
0
 public void addTuioObject(TuioObject o)
 {
     lock(objectSync) {
         objectList.Add(o.SessionID,new TuioObject(o));
     } if (verbose) Console.WriteLine("add obj "+o.SymbolID+" ("+o.SessionID+") "+o.X+" "+o.Y+" "+o.Angle);
 }
 /**
  * This constructor takes the atttibutes of the provided TuioObject
  	 * and assigs these values to the newly created TuioObject.
  *
  * @param	tobj	the TuioObject to assign
  */
 public TuioObject(TuioObject tobj)
     : base(tobj)
 {
     symbol_id = tobj.getSymbolID();
     angle = tobj.getAngle();
     rotation_speed = 0.0f;
     rotation_accel = 0.0f;
 }
Exemple #15
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;
            List <object> args    = message.Values;
            string        command = (string)args[0];

            // HACK : TUIO message tracing added by frog (@rktut)
            Trace.WriteLine(string.Format("{0} {1}", address, string.Join(" ", args.ToArray())), "OSC");

            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, ic = args.Count; i < ic; 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, ic = aliveObjectList.Count; i < ic; 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, ic = listenerList.Count; i < ic; i++)
                                {
                                    ITuioListener listener = (ITuioListener)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, ic = listenerList.Count; i < ic; i++)
                                {
                                    ITuioListener listener = (ITuioListener)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, ic = listenerList.Count; i < ic; i++)
                                {
                                    ITuioListener listener = (ITuioListener)listenerList[i];
                                    if (listener != null)
                                    {
                                        listener.UpdateTuioObject(updateObject);
                                    }
                                }
                                break;
                            }
                        }

                        for (int i = 0, ic = listenerList.Count; i < ic; i++)
                        {
                            ITuioListener listener = (ITuioListener)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, ic = args.Count; i < ic; 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, ic = aliveCursorList.Count; i < ic; 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, ic = listenerList.Count; i < ic; i++)
                                {
                                    ITuioListener listener = (ITuioListener)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, ic = listenerList.Count; i < ic; i++)
                                {
                                    ITuioListener listener = (ITuioListener)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, ic = listenerList.Count; i < ic; i++)
                                {
                                    ITuioListener listener = (ITuioListener)listenerList[i];
                                    if (listener != null)
                                    {
                                        listener.UpdateTuioCursor(updateCursor);
                                    }
                                }
                                break;
                            }
                        }

                        for (int i = 0, ic = listenerList.Count; i < ic; i++)
                        {
                            ITuioListener listener = (ITuioListener)listenerList[i];
                            if (listener != null)
                            {
                                listener.Refresh(new TuioTime(currentTime));
                            }
                        }

                        List <long> buffer = aliveCursorList;
                        aliveCursorList = newCursorList;
                        // recycling the List
                        newCursorList = buffer;
                    }
                    frameCursors.Clear();
                }
            }
        }
Exemple #16
0
 public void addTuioObject(TuioObject tobj)
 {
     Console.WriteLine("add obj "+tobj.SymbolID+" "+tobj.SessionID+" "+tobj.X+" "+tobj.Y+" "+tobj.Angle);
 }
 public void removeTuioObject(TuioObject o)
 {
 }
 public void updateTuioObject(TuioObject o)
 {
 }
Exemple #19
0
        /**
         * <summary>
         * The OSC callback method where all TUIO messages are received and decoded
         * and where the TUIO event callbacks are dispatched</summary>
         * <param name="message">the received OSC message</param>
         */
        public void ProcessMessage(OSCMessage message)
        {
            string address = message.Address;
            var    args    = message.Values;
            string command = (string)args[0];

            if (address == "/tuio/2Dobj")
            {
                if (command == "set")
                {
                    long  s_id   = (int)args[1];
                    int   f_id   = (int)args[2];
                    float xpos   = (float)args[3];
                    float ypos   = (float)args[4];
                    float angle  = (float)args[5];
                    float xspeed = (float)args[6];
                    float yspeed = (float)args[7];
                    float rspeed = (float)args[8];
                    float maccel = (float)args[9];
                    float raccel = (float)args[10];

                    lock (objectSync)
                    {
                        if (!objectList.ContainsKey(s_id))
                        {
                            TuioObject addObject = new TuioObject(s_id, f_id, xpos, ypos, angle);
                            frameObjects.Add(addObject);
                        }
                        else
                        {
                            TuioObject tobj = objectList[s_id];
                            if (tobj == null)
                            {
                                return;
                            }
                            if ((tobj.X != xpos) || (tobj.Y != ypos) || (tobj.Angle != angle) || (tobj.XSpeed != xspeed) || (tobj.YSpeed != yspeed) || (tobj.RotationSpeed != rspeed) || (tobj.MotionAccel != maccel) || (tobj.RotationAccel != raccel))
                            {
                                TuioObject updateObject = new TuioObject(s_id, f_id, xpos, ypos, angle);
                                updateObject.update(xpos, ypos, angle, xspeed, yspeed, rspeed, maccel, raccel);
                                frameObjects.Add(updateObject);
                            }
                        }
                    }
                }
                else if (command == "alive")
                {
                    newObjectList.Clear();
                    for (int i = 1; i < args.Count; i++)
                    {
                        // get the message content
                        long s_id = (int)args[i];
                        newObjectList.Add(s_id);
                        // reduce the object list to the lost objects
                        if (aliveObjectList.Contains(s_id))
                        {
                            aliveObjectList.Remove(s_id);
                        }
                    }

                    // remove the remaining objects
                    lock (objectSync)
                    {
                        for (int i = 0; i < aliveObjectList.Count; i++)
                        {
                            long       s_id         = aliveObjectList[i];
                            TuioObject removeObject = objectList[s_id];
                            removeObject.remove(currentTime);
                            frameObjects.Add(removeObject);
                        }
                    }
                }
                else if (command == "fseq")
                {
                    int  fseq      = (int)args[1];
                    bool lateFrame = false;

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

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

                            switch (tobj.TuioState)
                            {
                            case TuioObject.TUIO_REMOVED:
                                TuioObject removeObject = tobj;
                                removeObject.remove(currentTime);

                                lock (objectSync)
                                {
                                    objectList.Remove(removeObject.SessionID);
                                }
                                break;

                            case TuioObject.TUIO_ADDED:
                                TuioObject addObject = new TuioObject(currentTime, tobj.SessionID, tobj.SymbolID, tobj.X, tobj.Y, tobj.Angle);
                                lock (objectSync)
                                {
                                    objectList.Add(addObject.SessionID, addObject);
                                }

                                break;

                            default:
                                TuioObject updateObject = getTuioObject(tobj.SessionID);
                                if ((tobj.X != updateObject.X && tobj.XSpeed == 0) || (tobj.Y != updateObject.Y && tobj.YSpeed == 0))
                                {
                                    updateObject.update(currentTime, tobj.X, tobj.Y, tobj.Angle);
                                }
                                else
                                {
                                    updateObject.update(currentTime, tobj.X, tobj.Y, tobj.Angle, tobj.XSpeed, tobj.YSpeed, tobj.RotationSpeed, tobj.MotionAccel, tobj.RotationAccel);
                                }

                                break;
                            }
                        }


                        List <long> buffer = aliveObjectList;
                        aliveObjectList = newObjectList;
                        // recycling the List
                        newObjectList = buffer;
                    }
                    frameObjects.Clear();
                }
            }
        }
    void Update()
    {
        if (this.m_TuioManager.IsConnected &&
            this.m_TuioManager.IsMarkerAlive(this.MarkerID))
        {
            if (fighting == false)
            {
                TUIO.TuioObject marker = this.m_TuioManager.GetMarker(this.MarkerID);

                //update parameters
                this.m_ScreenPosition.x     = marker.getX();
                this.m_ScreenPosition.y     = marker.getY();
                this.m_Angle                = marker.getAngle() * RotationMultiplier;
                this.m_AngleDegrees         = marker.getAngleDegrees() * RotationMultiplier;
                this.m_Speed                = marker.getMotionSpeed();
                this.m_Acceleration         = marker.getMotionAccel();
                this.m_RotationSpeed        = marker.getRotationSpeed() * RotationMultiplier;
                this.m_RotationAcceleration = marker.getRotationAccel();
                this.m_Direction.x          = marker.getXSpeed();
                this.m_Direction.y          = marker.getYSpeed();
                this.m_IsVisible            = true;

                //set game object to visible, if it was hidden before
                ShowGameObject();

                //update transform component
                UpdateTransform();
            }
        }
        else
        {
            //automatically hide game object when marker is not visible
            if (this.AutoHideGO)
            {
                HideGameObject();
            }
            else
            {
                if (fighting == false)
                {
                    //activate markers
                    transform.GetChild(0).gameObject.SetActive(true);
                    //keyboard commands to test
                    if (MarkerID == 0)
                    {
                        Vector3 t = transform.position;

                        if (Input.GetKey(KeyCode.UpArrow))
                        {
                            Vector3 forward = Vector3.forward * 0.5f;
                            t += forward;
                        }
                        if (Input.GetKey(KeyCode.DownArrow))
                        {
                            Vector3 backward = Vector3.forward * -0.5f;
                            t += backward;
                        }
                        if (Input.GetKey(KeyCode.RightArrow))
                        {
                            Vector3 right = Vector3.right * 0.5f;
                            t += right;
                        }
                        if (Input.GetKey(KeyCode.LeftArrow))
                        {
                            Vector3 left = Vector3.right * -0.5f;
                            t += left;
                        }

                        if (t.x >= 96.0f || t.x <= 4.0f)
                        {
                            t.x = transform.position.x;
                        }

                        if (t.z >= 96.0f || t.z <= 4.0f)
                        {
                            t.z = transform.position.z;
                        }

                        if (t != transform.position)
                        {
                            transform.position = t;
                        }
                    }
                    if (MarkerID == 1)
                    {
                        if (Input.GetKey(KeyCode.Keypad8))
                        {
                            transform.position += Vector3.forward * 0.5f;
                        }
                        if (Input.GetKey(KeyCode.Keypad2))
                        {
                            transform.position += Vector3.forward * -0.5f;
                        }
                        if (Input.GetKey(KeyCode.Keypad6))
                        {
                            transform.position += Vector3.right * 0.5f;
                        }
                        if (Input.GetKey(KeyCode.Keypad4))
                        {
                            transform.position += Vector3.right * -0.5f;
                        }
                    }
                    if (MarkerID == 2)
                    {
                        Vector3 t = transform.position;

                        if (Input.GetKey(KeyCode.W))
                        {
                            Vector3 forward = Vector3.forward * 0.5f;
                            t += forward;
                        }
                        if (Input.GetKey(KeyCode.S))
                        {
                            Vector3 backward = Vector3.forward * -0.5f;
                            t += backward;
                        }
                        if (Input.GetKey(KeyCode.D))
                        {
                            Vector3 right = Vector3.right * 0.5f;
                            t += right;
                        }
                        if (Input.GetKey(KeyCode.A))
                        {
                            Vector3 left = Vector3.right * -0.5f;
                            t += left;
                        }

                        if (t.x >= 96.0f || t.x <= 4.0f)
                        {
                            t.x = transform.position.x;
                        }

                        if (t.z >= 96.0f || t.z <= 4.0f)
                        {
                            t.z = transform.position.z;
                        }

                        if (t != transform.position)
                        {
                            transform.position = t;
                        }
                    }
                    if (MarkerID == 3)
                    {
                        if (Input.GetKey(KeyCode.I))
                        {
                            transform.position += Vector3.forward * 0.5f;
                        }
                        if (Input.GetKey(KeyCode.K))
                        {
                            transform.position += Vector3.forward * -0.5f;
                        }
                        if (Input.GetKey(KeyCode.L))
                        {
                            transform.position += Vector3.right * 0.5f;
                        }
                        if (Input.GetKey(KeyCode.J))
                        {
                            transform.position += Vector3.right * -0.5f;
                        }
                    }
                }
            }

            this.m_IsVisible = false;
        }
    }
Exemple #21
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();
                }
            }
        }
Exemple #22
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();
                }
            }
        }
Exemple #23
0
    void Update()
    {
        if (this.m_TuioManager.IsMarkerAlive(this.MarkerID))
        {
            //Debug.Log("FidcialController Zeile 110:this.m_TuioManager.IsMarkerAlive(this.MarkerID)");
        }


        if (this.m_TuioManager.IsConnected &&
            this.m_TuioManager.IsMarkerAlive(this.MarkerID))
        {
            TUIO.TuioObject marker = this.m_TuioManager.GetMarker(this.MarkerID);

            //update parameters
            this.m_ScreenPosition.x     = marker.getX();
            this.m_ScreenPosition.y     = marker.getY();
            this.m_Angle                = marker.getAngle() * RotationMultiplier;
            this.m_AngleDegrees         = marker.getAngleDegrees() * RotationMultiplier;
            this.m_Speed                = marker.getMotionSpeed();
            this.m_Acceleration         = marker.getMotionAccel();
            this.m_RotationSpeed        = marker.getRotationSpeed() * RotationMultiplier;
            this.m_RotationAcceleration = marker.getRotationAccel();
            this.m_Direction.x          = marker.getXSpeed();
            this.m_Direction.y          = marker.getYSpeed();
            this.m_IsVisible            = true;

            //set game object to visible, if it was hidden before
            ShowGameObject();

            //update transform component
            UpdateTransform();

            //Hier werden die Rüben gesucht, die auf der Seite der jeweiligen Person sind und ihre Kreise eingefärbt
            if (Time.time - Fiducial_Counter.time > 2)
            {
                //Hier wird der Index gesetzt, damit man weiß, welche "kleinen" Rüben und Kreise zu welcher Rübe gehören
                if (this.name.IndexOf("Ruebe" + Fiducial_Counter.count) > -1)
                {
                    /*Die Rüben in der Mitte werden von 1 - 4 gezählt und
                     *      die unteren Rüben werden ebenfalls von 1-4 nummeriert,
                     *      jedoch nach dem "_" werden sie pro Seite mit gleich nummeriert.
                     *      Auf der Seite der Marker ID 0 ist bspw. die Ruebe1_1
                     *      Hier soll die jeweilige Rübe in Kleinformat gefunden werden */
                    if (this.name.Equals("Ruebe" + Fiducial_Counter.count + "_" + (this.MarkerID + 1)))
                    {
                        //Dadurch findet man den Jeweiligen kreis der Unterrübe und färbt diesen Grün
                        GameObject     circle   = GameObject.Find(this.name.Replace("Ruebe", "Kreis"));
                        SpriteRenderer renderer = circle.GetComponents <SpriteRenderer> () [0];
                        renderer.color = new Color(0.133f, 0.545f, 0.133f);

                        /*Hier kommt die Methode handleMarkerMovement in Aktion, die unten im Code zu finden ist.
                         *      Über diese Methode wird der Füllstand und die Bewegungsrichtung der Fiducials festgelegt*/
                        float diff = this.handleMarkerMovement();

                        /*Die Bewegungsachse wird in der Methode handleMarkerMovement festgelegt und
                         *      hier wird nochmal festgelegt ob sie in die + oder - Richtung
                         *      auf der jeweiligen Achse bewegt werden müssen.
                         *      Spricht MarkerID 0 muss in Richtung +y, MarkerID 1 -x,
                         *      MarkerID 2 -y und MarkerID 3 +x*/
                        diff *= MarkerID == 0 && MarkerID == 3 ? -1 : 1;

                        if (diff > 0)
                        {
                            //Der maximale Füllstand wird dann in den jeweiligen Loadscreen-Skripten kontrolliert
                            ScreenArray [MarkerID] += diff;
                        }
                    }
                }
                else
                {
                    //Ist die Rübe nicht dran, so bleibt der Kreis braun
                    GameObject     circle   = GameObject.Find(this.name.Replace("Ruebe", "Kreis"));
                    SpriteRenderer renderer = circle.GetComponents <SpriteRenderer> () [0];
                    renderer.color = new Color(0.35f, 0.19f, 0.1f);
                }
            }
            else
            {
                //automatically hide game object when marker is not visible
                if (this.AutoHideGO)
                {
                    HideGameObject();
                }

                //Wird das Fiducial nicht erkannt, so bleibt die Rübe auch braun
                recognized = false;

                GameObject     circle   = GameObject.Find(this.name.Replace("Ruebe", "Kreis"));
                SpriteRenderer renderer = circle.GetComponents <SpriteRenderer> () [0];
                renderer.color = new Color(0.35f, 0.19f, 0.1f);

                this.m_IsVisible = false;
            }
        }
        else
        {
            //automatically hide game object when marker is not visible
            if (this.AutoHideGO)
            {
                HideGameObject();
            }

            recognized = false;

            GameObject     circle   = GameObject.Find(this.name.Replace("Ruebe", "Kreis"));
            SpriteRenderer renderer = circle.GetComponents <SpriteRenderer> () [0];
            renderer.color = new Color(0.35f, 0.19f, 0.1f);

            this.m_IsVisible = false;
        }
    }
 // Update function for Tuio methods
 public TuioObject updateTObj(long key, TuioObject value)
 {
     return value;
 }
        public void updateTuioObject(TuioObject tobj)
        {
            if (readyForInput)
            {
                // If using calibration values, modify TuioObject using calibration values before passing it on
                if (Settings.INPUT_USE_FIDUCIALS && Settings.USE_INDIVIDUAL_CALIBRATION)
                    ApplyIndividualCalibrations(tobj);
                tuioObjects.AddOrUpdate(tobj.getSymbolID(), tobj, updateTObj);
                /*
                // Only accept updates if coordinates are within movieDestination
                if (movieDestination.Contains(tobj.getScreenX(Settings.RESOLUTION_X), tobj.getScreenY(Settings.RESOLUTION_Y) - 1))
                {
                    //Debug.WriteLine("Object update!, x=" + tobj.getScreenX(RESOLUTION_X) + ", y=" + tobj.getScreenY(RESOLUTION_Y) + ", speed=" + tobj.getMotionSpeed() + ", accel=" + tobj.getMotionAccel() + ", angle=" + tobj.getAngleDegrees() + ", symbolID=" + tobj.getSymbolID() + ", sessionID=" + tobj.getSessionID() + ", gameTime=" + gameTime.TotalGameTime.TotalMilliseconds);
                    //Debug.WriteLine("Oject velocity: " + tobj.getVelocityFromPath(RESOLUTION_X,RESOLUTION_Y));
                    //if (USE_FIDUCIALS) // Use symbol ID's from fiducials instead of session ID's
                    //{
                    //    //if (!USE_CALIBRATION || (USE_CALIBRATION && tobj.getSymbolID() < 10))
                    //        tuioObjects.AddOrUpdate(tobj.getSymbolID(), tobj, updateTObj);
                    //}
                    //else
                    //{
                    //    tuioObjects.AddOrUpdate(tobj.getSessionID(), tobj, updateTObj);
                    //}
                    if (Settings.INPUT_USE_GLOBAL_CALIBRATION)
                        tobj.update(((tobj.getX() * Settings.RESOLUTION_X + Settings.INPUT_GLOBAL_X_SHIFT) / (float)Settings.RESOLUTION_X), ((tobj.getY() * Settings.RESOLUTION_Y + Settings.INPUT_GLOBAL_Y_SHIFT) / (float)Settings.RESOLUTION_Y));
                    if (zoomedCircles.ContainsKey(tobj.getSymbolID()))
                    {
                        // If this is an update, smooth motion by ignoring small changes
                        ZoomCircle oldZoomCircle = zoomedCircles[tobj.getSymbolID()];
                        Vector2 oldPosition = oldZoomCircle.position;
                        //Debug.WriteLine(oldPosition.X + ", " + oldPosition.Y + "\t" + tobj.getScreenX(RESOLUTION_X) + ", " + tobj.getScreenY(RESOLUTION_Y));

                        //Debug.WriteLineIf((Math.Abs(oldZoomCircle.position.X - tobj.getScreenX(RESOLUTION_X)) > 0), Math.Abs(oldZoomCircle.position.X - tobj.getScreenX(RESOLUTION_X)));
                        //Debug.WriteLine(oldPosition.X + ", " + oldPosition.Y + "\t" + tobj.getScreenX(RESOLUTION_X) + ", " + tobj.getScreenY(RESOLUTION_Y));
                        List<TuioPoint> path = tobj.getPath();
                        int pathCount = path.Count;
                        if (pathCount >= 10)
                        {
                            List<TuioPoint> lastPoints = path.GetRange(pathCount - 10, 10);
                            float yDiff = 0f;
                            float xDiff = 0f;
                            foreach (TuioPoint tpoint in lastPoints)
                            {
                                xDiff += Math.Abs(tpoint.getX() * Settings.RESOLUTION_X - oldPosition.X);
                                yDiff += Math.Abs(tpoint.getY() * Settings.RESOLUTION_Y - oldPosition.Y);
                            }
                            if (xDiff < 10f * Settings.CIRCLE_POSITION_CHANGE_THRESHOLD || yDiff < 10f * Settings.CIRCLE_POSITION_CHANGE_THRESHOLD)
                            {
                                tobj.update(oldPosition.X / (float)Settings.RESOLUTION_X, oldPosition.Y / (float)Settings.RESOLUTION_Y);
                            }
                            else
                            {
                                tuioObjects.AddOrUpdate(tobj.getSymbolID(), tobj, updateTObj);
                            }

                            //if ((Math.Abs(oldPosition.X - tobj.getScreenX(RESOLUTION_X)) < CIRCLE_POSITION_CHANGE_THRESHOLD) ||
                            //    (Math.Abs(oldPosition.Y - tobj.getScreenY(RESOLUTION_Y)) < CIRCLE_POSITION_CHANGE_THRESHOLD))
                            //{
                            //    tobj.update(oldPosition.X / RESOLUTION_X, oldPosition.Y / RESOLUTION_Y);
                            //}
                            //else
                            //{
                            //    tuioObjects.AddOrUpdate(tobj.getSymbolID(), tobj, updateTObj);
                            //}
                        }
                        else
                        {
                            tuioObjects.AddOrUpdate(tobj.getSymbolID(), tobj, updateTObj);
                        }
                    }
                    else
                    {
                        // Otherwise just add it
                        tuioObjects.AddOrUpdate(tobj.getSymbolID(), tobj, updateTObj);
                    }
                }
                */

                // Measure how many total updates / second we're getting
                //if ((int)gameTime.TotalGameTime.TotalSeconds > secondsRunning)
                //{
                //    Debug.WriteLine("Object updates per second:" + updatesCount);
                //    secondsRunning = (int)gameTime.TotalGameTime.TotalSeconds;
                //    updatesCount = 0;
                //}
                //else
                //{
                //    updatesCount++;
                //}
            }
        }
Exemple #26
0
 public void updateTuioObject(TuioObject o)
 {
     lock(objectSync) {
             objectList[o.getSessionID()].update(o);
         }
         if (verbose) Console.WriteLine("set obj "+o.getSymbolID()+" "+o.getSessionID()+" "+o.getX()+" "+o.getY()+" "+o.getAngle()+" "+o.getMotionSpeed()+" "+o.getRotationSpeed()+" "+o.getMotionAccel()+" "+o.getRotationAccel());
 }
 // required implementations
 public void addTuioObject(TuioObject o)
 {
 }
		public void UpdateTuioObject(TuioObject tuioObject) { }
Exemple #29
0
 public void updateTuioObject(TuioObject tobj)
 {
     Console.WriteLine("set obj "+tobj.SymbolID+" "+tobj.SessionID+" "+tobj.X+" "+tobj.Y+" "+tobj.Angle+" "+tobj.MotionSpeed+" "+tobj.RotationSpeed+" "+tobj.MotionAccel+" "+tobj.RotationAccel);
 }
Exemple #30
0
        /**
         * <summary>
         * The OSC callback method where all TUIO messages are received and decoded
         * and where the TUIO event callbacks are dispatched</summary>
         * <param name="message">the received OSC message</param>
         */
        private void processMessage(OSCMessage message)
        {
            string    address = message.Address;
            ArrayList args    = message.Values;
            string    command = (string)args[0];

            if (address == "/tuio/2Dobj")
            {
                if (command == "set")
                {
                    long  s_id   = (int)args[1];
                    int   f_id   = (int)args[2];
                    float xpos   = (float)args[3];
                    float ypos   = (float)args[4];
                    float angle  = (float)args[5];
                    float xspeed = (float)args[6];
                    float yspeed = (float)args[7];
                    float rspeed = (float)args[8];
                    float maccel = (float)args[9];
                    float raccel = (float)args[10];

                    lock (objectSync)
                    {
                        if (!objectList.ContainsKey(s_id))
                        {
                            TuioObject addObject = new TuioObject(s_id, f_id, xpos, ypos, angle);
                            frameObjects.Add(addObject);
                        }
                        else
                        {
                            TuioObject tobj = objectList[s_id];
                            if (tobj == null)
                            {
                                return;
                            }
                            if ((tobj.X != xpos) || (tobj.Y != ypos) || (tobj.Angle != angle) || (tobj.XSpeed != xspeed) || (tobj.YSpeed != yspeed) || (tobj.RotationSpeed != rspeed) || (tobj.MotionAccel != maccel) || (tobj.RotationAccel != raccel))
                            {
                                TuioObject updateObject = new TuioObject(s_id, f_id, xpos, ypos, angle);
                                updateObject.update(xpos, ypos, angle, xspeed, yspeed, rspeed, maccel, raccel);
                                frameObjects.Add(updateObject);
                            }
                        }
                    }
                }
                else if (command == "alive")
                {
                    newObjectList.Clear();
                    for (int i = 1; i < args.Count; i++)
                    {
                        // get the message content
                        long s_id = (int)args[i];
                        newObjectList.Add(s_id);
                        // reduce the object list to the lost objects
                        if (aliveObjectList.Contains(s_id))
                        {
                            aliveObjectList.Remove(s_id);
                        }
                    }

                    // remove the remaining objects
                    lock (objectSync)
                    {
                        for (int i = 0; i < aliveObjectList.Count; i++)
                        {
                            long       s_id         = aliveObjectList[i];
                            TuioObject removeObject = objectList[s_id];
                            removeObject.remove(currentTime);
                            frameObjects.Add(removeObject);
                        }
                    }
                }
                else if (command == "fseq")
                {
                    int  fseq      = (int)args[1];
                    bool lateFrame = false;

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

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

                            switch (tobj.TuioState)
                            {
                            case TuioObject.TUIO_REMOVED:
                                TuioObject removeObject = tobj;
                                removeObject.remove(currentTime);

                                for (int i = 0; i < listenerList.Count; i++)
                                {
                                    TuioListener listener = (TuioListener)listenerList[i];
                                    if (listener != null)
                                    {
                                        listener.removeTuioObject(removeObject);
                                    }
                                }
                                lock (objectSync)
                                {
                                    objectList.Remove(removeObject.SessionID);
                                }
                                break;

                            case TuioObject.TUIO_ADDED:
                                TuioObject addObject = new TuioObject(currentTime, tobj.SessionID, tobj.SymbolID, tobj.X, tobj.Y, tobj.Angle);
                                lock (objectSync)
                                {
                                    objectList.Add(addObject.SessionID, addObject);
                                }
                                for (int i = 0; i < listenerList.Count; i++)
                                {
                                    TuioListener listener = (TuioListener)listenerList[i];
                                    if (listener != null)
                                    {
                                        listener.addTuioObject(addObject);
                                    }
                                }
                                break;

                            default:
                                TuioObject updateObject = getTuioObject(tobj.SessionID);
                                if ((tobj.X != updateObject.X && tobj.XSpeed == 0) || (tobj.Y != updateObject.Y && tobj.YSpeed == 0))
                                {
                                    updateObject.update(currentTime, tobj.X, tobj.Y, tobj.Angle);
                                }
                                else
                                {
                                    updateObject.update(currentTime, tobj.X, tobj.Y, tobj.Angle, tobj.XSpeed, tobj.YSpeed, tobj.RotationSpeed, tobj.MotionAccel, tobj.RotationAccel);
                                }

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

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

                        List <long> buffer = aliveObjectList;
                        aliveObjectList = newObjectList;
                        // recycling the List
                        newObjectList = buffer;
                    }
                    frameObjects.Clear();
                }
            }
            else if (address == "/tuio/2Dcur")
            {
                if (command == "set")
                {
                    long  s_id   = (int)args[1];
                    float xpos   = (float)args[2];
                    float ypos   = (float)args[3];
                    float xspeed = (float)args[4];
                    float yspeed = (float)args[5];
                    float maccel = (float)args[6];

                    lock (cursorList)
                    {
                        if (!cursorList.ContainsKey(s_id))
                        {
                            TuioCursor addCursor = new TuioCursor(s_id, -1, xpos, ypos);
                            frameCursors.Add(addCursor);
                        }
                        else
                        {
                            TuioCursor tcur = (TuioCursor)cursorList[s_id];
                            if (tcur == null)
                            {
                                return;
                            }
                            if ((tcur.X != xpos) || (tcur.Y != ypos) || (tcur.XSpeed != xspeed) || (tcur.YSpeed != yspeed) || (tcur.MotionAccel != maccel))
                            {
                                TuioCursor updateCursor = new TuioCursor(s_id, tcur.CursorID, xpos, ypos);
                                updateCursor.update(xpos, ypos, xspeed, yspeed, maccel);
                                frameCursors.Add(updateCursor);
                            }
                        }
                    }
                }
                else if (command == "alive")
                {
                    newCursorList.Clear();
                    for (int i = 1; i < args.Count; i++)
                    {
                        // get the message content
                        long s_id = (int)args[i];
                        newCursorList.Add(s_id);
                        // reduce the cursor list to the lost cursors
                        if (aliveCursorList.Contains(s_id))
                        {
                            aliveCursorList.Remove(s_id);
                        }
                    }

                    // remove the remaining cursors
                    lock (cursorSync)
                    {
                        for (int i = 0; i < aliveCursorList.Count; i++)
                        {
                            long s_id = aliveCursorList[i];
                            if (!cursorList.ContainsKey(s_id))
                            {
                                continue;
                            }
                            TuioCursor removeCursor = cursorList[s_id];
                            removeCursor.remove(currentTime);
                            frameCursors.Add(removeCursor);
                        }
                    }
                }
                else if (command == "fseq")
                {
                    int  fseq      = (int)args[1];
                    bool lateFrame = false;

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

                    if (!lateFrame)
                    {
                        IEnumerator <TuioCursor> frameEnum = frameCursors.GetEnumerator();
                        while (frameEnum.MoveNext())
                        {
                            TuioCursor tcur = frameEnum.Current;
                            switch (tcur.TuioState)
                            {
                            case TuioCursor.TUIO_REMOVED:
                                TuioCursor removeCursor = tcur;
                                removeCursor.remove(currentTime);

                                for (int i = 0; i < listenerList.Count; i++)
                                {
                                    TuioListener listener = (TuioListener)listenerList[i];
                                    if (listener != null)
                                    {
                                        listener.removeTuioCursor(removeCursor);
                                    }
                                }
                                lock (cursorSync)
                                {
                                    cursorList.Remove(removeCursor.SessionID);

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

                                        if (cursorList.Count > 0)
                                        {
                                            IEnumerator <KeyValuePair <long, TuioCursor> > clist = cursorList.GetEnumerator();
                                            while (clist.MoveNext())
                                            {
                                                int f_id = clist.Current.Value.CursorID;
                                                if (f_id > maxCursorID)
                                                {
                                                    maxCursorID = f_id;
                                                }
                                            }

                                            List <TuioCursor>        freeCursorBuffer = new List <TuioCursor>();
                                            IEnumerator <TuioCursor> flist            = freeCursorList.GetEnumerator();
                                            while (flist.MoveNext())
                                            {
                                                TuioCursor testCursor = flist.Current;
                                                if (testCursor.CursorID < maxCursorID)
                                                {
                                                    freeCursorBuffer.Add(testCursor);
                                                }
                                            }
                                            freeCursorList = freeCursorBuffer;
                                        }
                                        else
                                        {
                                            freeCursorList.Clear();
                                        }
                                    }
                                    else if (removeCursor.CursorID < maxCursorID)
                                    {
                                        freeCursorList.Add(removeCursor);
                                    }
                                }
                                break;

                            case TuioCursor.TUIO_ADDED:
                                TuioCursor addCursor;
                                lock (cursorSync)
                                {
                                    int c_id = cursorList.Count;
                                    if ((cursorList.Count <= maxCursorID) && (freeCursorList.Count > 0))
                                    {
                                        TuioCursor closestCursor          = freeCursorList[0];
                                        IEnumerator <TuioCursor> testList = freeCursorList.GetEnumerator();
                                        while (testList.MoveNext())
                                        {
                                            TuioCursor testCursor = testList.Current;
                                            if (testCursor.getDistance(tcur) < closestCursor.getDistance(tcur))
                                            {
                                                closestCursor = testCursor;
                                            }
                                        }
                                        c_id = closestCursor.CursorID;
                                        freeCursorList.Remove(closestCursor);
                                    }
                                    else
                                    {
                                        maxCursorID = c_id;
                                    }

                                    addCursor = new TuioCursor(currentTime, tcur.SessionID, c_id, tcur.X, tcur.Y);
                                    cursorList.Add(addCursor.SessionID, addCursor);
                                }

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

                            default:
                                TuioCursor updateCursor = getTuioCursor(tcur.SessionID);
                                if ((tcur.X != updateCursor.X && tcur.XSpeed == 0) || (tcur.Y != updateCursor.Y && tcur.YSpeed == 0))
                                {
                                    updateCursor.update(currentTime, tcur.X, tcur.Y);
                                }
                                else
                                {
                                    updateCursor.update(currentTime, tcur.X, tcur.Y, tcur.XSpeed, tcur.YSpeed, tcur.MotionAccel);
                                }

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

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

                        List <long> buffer = aliveCursorList;
                        aliveCursorList = newCursorList;
                        // recycling the List
                        newCursorList = buffer;
                    }
                    frameCursors.Clear();
                }
            }
            else if (address == "/tuio/2Dblb")
            {
                if (command == "set")
                {
                    long  s_id   = (int)args[1];
                    float xpos   = (float)args[2];
                    float ypos   = (float)args[3];
                    float angle  = (float)args[4];
                    float width  = (float)args[5];
                    float height = (float)args[6];
                    float area   = (float)args[7];
                    float xspeed = (float)args[8];
                    float yspeed = (float)args[9];
                    float rspeed = (float)args[10];
                    float maccel = (float)args[11];
                    float raccel = (float)args[12];

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        List <long> buffer = aliveBlobList;
                        aliveBlobList = newBlobList;
                        // recycling the List
                        newBlobList = buffer;
                    }
                    frameBlobs.Clear();
                }
            }
        }
Exemple #31
0
 public void removeTuioObject(TuioObject tobj)
 {
     Console.WriteLine("del obj "+tobj.SymbolID+" "+tobj.SessionID);
 }
Exemple #32
0
 public void removeTuioObject(TuioObject o)
 {
     m_tuioObjectRemovedList.Add(o);
 }
Exemple #33
0
 public void addTuioObject(TuioObject o)
 {
     lock(objectSync) {
             objectList.Add(o.getSessionID(),new TuioDemoObject(o));
         } if (verbose) Console.WriteLine("add obj "+o.getSymbolID()+" ("+o.getSessionID()+") "+o.getX()+" "+o.getY()+" "+o.getAngle());
 }
Exemple #34
0
 public void update(TuioObject o)
 {
     base.update(o);
     this.angle = o.getAngle();
     this.rotation_speed = o.getRotationSpeed();
     this.rotation_accel = o.getRotationAccel();
 }
		public void AddTuioObject(TuioObject tuioObject) {}
        /**
         * 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();
                }

            }
        }
		public void RemoveTuioObject(TuioObject tuioObject) { }
        private static void ApplyIndividualCalibrations(TuioObject tobj)
        {
            if (Settings.USE_INDIVIDUAL_CALIBRATION) // Modify object using calibration values before passing it on
            {
                int symbolID = tobj.getSymbolID();

                // ERICSOCO ADDED
                if (symbolID > 4095)
                {
                    throw new ArgumentOutOfRangeException();
                }

                // Retrieve calibration values for this object
                float calA1 = MathHelper.ToRadians(Settings.CALIBRATIONS[symbolID, 0]);
                float calD = (float)Settings.CALIBRATIONS[symbolID, 1];
                float calA2 = MathHelper.ToRadians(Settings.CALIBRATIONS[symbolID, 2]);

                // Assume that the tuioObject is the origin, and that its orientation vector points up (along the y-axis).

                // Create a position vector based on the calibration information that is offset from the tuioObject/origin.
                Vector2 offsetVector = new Vector2((float)Math.Cos(calA1), (float)Math.Sin(calA1));
                offsetVector = Vector2.Multiply(offsetVector, calD);

                // Rotate vector around the origin by the TUIO object's orientation.
                Matrix tMatrix = Matrix.CreateRotationZ(tobj.getAngle());

                // Translate vector by the TUIO object's position.
                tMatrix *= Matrix.CreateTranslation(tobj.getScreenX(Settings.RESOLUTION_X), tobj.getScreenY(Settings.RESOLUTION_Y), 0f);

                // Apply matrix transforms.
                offsetVector = Vector2.Transform(offsetVector, tMatrix);

                // Normalize to screen resolution.
                float offsetX = offsetVector.X / Settings.RESOLUTION_X;
                float offsetY = offsetVector.Y / Settings.RESOLUTION_Y;

                // Add other calibration angle to tuioObject angle.
                float offsetA = tobj.getAngle() + calA2;

                // Update the TUIO object.
                tobj.update(tobj.getTuioTime(), offsetX, offsetY, offsetA);

                /*
                // Add offset angle to tuioObject's rotation
                float offsetA = tobj.getAngle() + calA1;
                Vector2 offsetV = new Vector2((float)Math.Cos(offsetA), (float)Math.Sin(offsetA));

                // Move fiducial point to data point
                // offsetV.Normalize();
                Vector2 dataPoint = Vector2.Multiply(offsetV, calD);

                tobj.update(tobj.getTuioTime(), tobj.getX() + dataPoint.X / RESOLUTION_X, tobj.getY() + dataPoint.Y / RESOLUTION_Y, tobj.getAngle() + calA2);
                 */
            }
        }
Exemple #39
0
 public void addTuioObject(TuioObject o)
 {
     m_tuioObjectAddedList.Add(o);
 }
        private void InitializeCircles()
        {
            freeObjects = new ConcurrentDictionary<long, TuioObject>();
            draggedObjects = new ConcurrentDictionary<long, TuioObject>();
            zoomedCircles = new ConcurrentDictionary<long, ZoomCircle>();
            tuioObjects.Clear();

            // If touch_only, add 3 tuio objects that will stay forever
            if (Settings.TOUCHONLY)
            {
                for (int i = 0; i < 3; i++)
                {
                    TuioObject tobj = new TuioObject(new TuioTime(), rand.Next(), i, (float)rand.Next(movieDestination.Left, movieDestination.Right) / Settings.RESOLUTION_X, (float)rand.Next(movieDestination.Top, movieDestination.Bottom) / Settings.RESOLUTION_Y, 0f);
                    this.addTuioObject(tobj);
                    if (!freeObjects.TryAdd(tobj.getSymbolID(), tobj))
                    {
                        Debug.WriteLine("Failed to add to freeObjects in InitializeCircles()");
                    };
                }
            }
        }
Exemple #41
0
 public void updateTuioObject(TuioObject o)
 {
     m_tuioObjectUpdatedList.Add(o);
 }
        private void processMouseInput(GameTime gameTime)
        {
            MouseState mouseState = Mouse.GetState();
            float mouseX = (float)mouseState.X / (float)Settings.RESOLUTION_X;
            float mouseY = (float)mouseState.Y / (float)Settings.RESOLUTION_Y;

            // If left button not clicked, release objects and cursors
            if (mouseState.LeftButton != ButtonState.Pressed)
            {
                draggedCursor = null;
                draggedObject = null;
                dragDiffVector = Vector2.Zero;
                tuioCursors.Clear();

                /*
                // Update objects
                foreach (TuioObject tobj in tuioObjects.Values) {
                    this.updateTuioObject(new TuioObject(new TuioTime(), tobj.getSessionID(), tobj.getSymbolID(),tobj.getX()+0.00001f,tobj.getY(),tobj.getAngle()));
                }
                 */
            }
            else if (mouseState.LeftButton == ButtonState.Pressed)
            {
                // If we're already dragging an object or cursor, just update that object's position
                if (draggedCursor != null)
                {
                    draggedCursor.update(TuioTime.getSessionTime(), mouseX, mouseY);
                    this.updateTuioCursor(draggedCursor);
                    return;
                }
                else if (draggedObject != null)
                {
                    draggedObject.update(TuioTime.getSessionTime(), mouseX - dragDiffVector.X / (float)Settings.RESOLUTION_X, mouseY - dragDiffVector.Y / (float)Settings.RESOLUTION_Y);
                    //draggedObject.update(new TuioTime(), mouseX, mouseY);
                    this.updateTuioObject(draggedObject);
                    return;
                }

                // If click is on a guide tab, make it a cursor
                TuioCursor tcur = new TuioCursor(TuioTime.getSessionTime(), 0, 0, mouseX, mouseY);
                ZoomCircle outZoomCircle;
                string outButtonName;
                this.WouldPushButton(tcur, out outZoomCircle, out outButtonName);
                if (outZoomCircle != null)
                {
                    draggedCursor = tcur;
                    this.addTuioCursor(tcur);
                    return;
                }

                // If click is on an open zoomCircle, start dragging its object

                // Find nearest object
                TuioObject closestTobj = null;
                float closestDistance = 1000f;
                Vector2 mousePosition = new Vector2(mouseState.X, mouseState.Y);
                Vector2 tobjPosition = new Vector2();
                Vector2 closestDiffVector = Vector2.Zero;
                foreach (TuioObject tobj in tuioObjects.Values)
                {
                    tobjPosition.X = tobj.getScreenX(Settings.RESOLUTION_X);
                    tobjPosition.Y = tobj.getScreenY(Settings.RESOLUTION_Y);
                    Vector2 diffVector = Vector2.Subtract(mousePosition, tobjPosition);
                    float distance = diffVector.Length();
                    if (closestTobj == null)
                    {
                        closestDistance = distance;
                        closestTobj = tobj;
                        closestDiffVector = diffVector;
                    }
                    else if (distance < closestDistance)
                    {
                        closestDistance = distance;
                        closestTobj = tobj;
                        closestDiffVector = diffVector;
                    }
                }

                if (closestTobj != null)
                {
                    if (closestDistance <= Settings.CIRCLE_RADIUS)
                    {
                        // On left click, start dragging it
                        if (mouseState.LeftButton == ButtonState.Pressed)
                        {
                            draggedObject = closestTobj;
                            dragDiffVector = closestDiffVector;
                            return;
                        }
                    }
                }
                // If we're not maxed out on objects, place a new object and start dragging it
                if (tuioObjects.Count < Settings.MAX_CIRCLES)
                {
                    // Find a new id that's not taken yet
                    int id = 0;
                    while (tuioObjects.Keys.Contains(id))
                    {
                        id++;
                    }

                    TuioObject tobj = new TuioObject(new TuioTime(), rand.Next(), id, mouseX, mouseY, 0f);
                    draggedObject = tobj;
                    this.addTuioObject(tobj);
                    return;
                }

                // Otherwise, it's a cursor
                draggedCursor = tcur;
                this.addTuioCursor(tcur);
                return;
            }

            // If right clicked on a circle, remove it
            if (mouseState.RightButton == ButtonState.Pressed)
            {
                TuioObject closestTobj = null;
                float closestDistance = 1000f;
                Vector2 mousePosition = new Vector2(mouseState.X, mouseState.Y);
                Vector2 tobjPosition = new Vector2();
                foreach (TuioObject tobj in tuioObjects.Values)
                {
                    tobjPosition.X = tobj.getScreenX(Settings.RESOLUTION_X);
                    tobjPosition.Y = tobj.getScreenY(Settings.RESOLUTION_Y);
                    Vector2 diffVector = Vector2.Subtract(mousePosition, tobjPosition);
                    float distance = diffVector.Length();
                    if (closestTobj == null)
                    {
                        closestDistance = distance;
                        closestTobj = tobj;
                    }
                    else if (distance < closestDistance)
                    {
                        closestDistance = distance;
                        closestTobj = tobj;
                    }
                }

                if (closestTobj != null)
                {
                    if (closestDistance <= Settings.CIRCLE_RADIUS)
                    {
                        this.removeTuioObject(closestTobj);
                        return;
                    }
                }
            }

            // If middle clicked on a circle, flip the orientation
            if (mouseState.MiddleButton == ButtonState.Pressed)
            {
                TuioObject closestTobj = null;
                float closestDistance = 1000f;
                Vector2 mousePosition = new Vector2(mouseState.X, mouseState.Y);
                Vector2 tobjPosition = new Vector2();
                foreach (TuioObject tobj in tuioObjects.Values)
                {
                    tobjPosition.X = tobj.getScreenX(Settings.RESOLUTION_X);
                    tobjPosition.Y = tobj.getScreenY(Settings.RESOLUTION_Y);
                    Vector2 diffVector = Vector2.Subtract(mousePosition, tobjPosition);
                    float distance = diffVector.Length();
                    if (closestTobj == null)
                    {
                        closestDistance = distance;
                        closestTobj = tobj;
                    }
                    else if (distance < closestDistance)
                    {
                        closestDistance = distance;
                        closestTobj = tobj;
                    }
                }

                if (closestTobj != null)
                {
                    if (closestDistance <= Settings.CIRCLE_RADIUS)
                    {
                        if (this.zoomedCircles[closestTobj.getSymbolID()].AttachedGuide.IsUpsideDown)
                            this.zoomedCircles[closestTobj.getSymbolID()].AttachedGuide.IsUpsideDown = false;
                        else
                            this.zoomedCircles[closestTobj.getSymbolID()].AttachedGuide.IsUpsideDown = true;
                        return;
                    }
                }
            }
        }
 /**
  * Takes the atttibutes of the provided TuioObject
  	 * and assigs these values to this TuioObject.
  * The TuioTime time stamp of this TuioContainer remains unchanged.
  *
  * @param	tobj	the TuioContainer to assign
  */
 public void update(TuioObject tobj)
 {
     base.update(tobj);
     angle = tobj.getAngle();
     rotation_speed = tobj.getRotationSpeed();
     rotation_accel = tobj.getRotationAccel();
     if ((rotation_accel!=0) && (state!=TUIO_STOPPED)) state = TUIO_ROTATING;
 }
        // TuioListener interface methods
        // this is called when an object becomes visible
        public void addTuioObject(TuioObject tobj)
        {
            this.updateTuioObject(tobj);
            //if (readyForInput)
            //{
            //    // If using calibration values, modify TuioObject using calibration values before passing it on
            //    if (USE_FIDUCIALS && USE_INDIVIDUAL_CALIBRATION)
            //        //ApplyCalibrations(tobj);
            //        // ERICSOCO ADDED:
            //        try
            //        {
            //            ApplyIndividualCalibrations(tobj);
            //        }
            //        catch (ArgumentOutOfRangeException aoore)
            //        {
            //            return;
            //        }

            //    // Only accept new objects if coordinates are within movieDestination
            //    if (movieDestination.Contains(tobj.getScreenX(RESOLUTION_X), tobj.getScreenY(RESOLUTION_Y) - 1))
            //    {
            //        //Debug.WriteLine("Object added!, x=" + tobj.getScreenX(RESOLUTION_X) + ", y=" + tobj.getScreenY(RESOLUTION_Y) + ", angle=" + tobj.getAngleDegrees() + ", symbolID=" + tobj.getSymbolID() + ", sessionID=" + tobj.getSessionID() + ", gameTime=" + gameTime.TotalGameTime.TotalMilliseconds);
            //        //if (USE_FIDUCIALS) // Use symbol ID's from fiducials instead of session ID's
            //        //{
            //        //   tuioObjects.AddOrUpdate(tobj.getSymbolID(), tobj, updateTObj);
            //        //}
            //        //else
            //        //{
            //        //    tuioObjects.AddOrUpdate(tobj.getSessionID(), tobj, updateTObj);
            //        //}
            //        if (USE_GLOBAL_CALIBRATION)
            //            tobj.update(((tobj.getX() * RESOLUTION_X + GLOBAL_X_SHIFT) / (float)RESOLUTION_X), ((tobj.getY() * RESOLUTION_Y + GLOBAL_Y_SHIFT) / (float)RESOLUTION_Y));
            //        tuioObjects.AddOrUpdate(tobj.getSymbolID(), tobj, updateTObj);
            //    }
            //}
        }
Exemple #45
0
 public void updateTuioObject(TuioObject o)
 {
     lock(objectSync) {
         objectList[o.SessionID].update(o);
     }
     if (verbose) Console.WriteLine("set obj "+o.SymbolID+" "+o.SessionID+" "+o.X+" "+o.Y+" "+o.Angle+" "+o.MotionSpeed+" "+o.RotationSpeed+" "+o.MotionAccel+" "+o.RotationAccel);
 }
 // an object was removed from the table
 public void removeTuioObject(TuioObject tobj)
 {
     if (readyForInput)
     {
         //Debug.WriteLine("Object removed!");
         TuioObject dummy;
         //if (USE_FIDUCIALS) // Use symbol ID's from fiducials instead of session ID's
         //{
         //    tuioObjects.TryRemove(tobj.getSymbolID(), out dummy);
         //}
         //else
         //{
         //    tuioObjects.TryRemove(tobj.getSessionID(), out dummy);
         //}
         tuioObjects.TryRemove(tobj.getSymbolID(), out dummy);
     }
 }