OSCMessage
Inheritance: OSCPacket
コード例 #1
0
ファイル: OcGyro.cs プロジェクト: saerus/opencontrollers
    //
    public void OSCMessageReceived(OSC.NET.OSCMessage message)
    {
        string    address = message.Address;
        ArrayList args    = message.Values;

        //Debug.Log ("receive something: ");
        //Debug.Log("s");
        //
        if (address.Equals("gyro"))
        {
            gyro.x = (float)args[0];
            gyro.y = (float)args[1];
            gyro.z = (float)args[2];
            gyro.w = (float)args[3];
            tempAngleCalibration = (float)args[4];
            //
            if (firstReceive)
            {
                gyroCorrected = correction * gyro;
                oldGyro       = gyro;
                firstReceive  = false;
            }
        }
        if (address.Equals("accel"))
        {
            accel.x   = (float)args[0];
            accel.y   = (float)args[1];
            accel.z   = (float)args[2];
            gravity.x = (float)args[3];
            gravity.y = (float)args[4];
            gravity.z = (float)args[5];
            //
            relativeAccel = accel - gravity;
        }
    }
コード例 #2
0
    public void OSCMessageReceived(OSC.NET.OSCMessage message)
    {
        // do I need to "subscribe" to any messages? or make this instance know about the connection receiver	?
        Debug.Log("this is the new puppet specific controller! OSCMessageReceived. I hope this gets instantiated with the prefab.");
        string    address = message.Address;
        ArrayList args    = message.Values;

        foreach (var item in args)
        {
// ADDRESS SLIDER1

            if (address == "/1/Pad2PuppetController1/1" || address == "/2/Pad2PuppetController1/1")
            {
                Debug.Log("this is the new puppet specific controller!. I hope this gets instantiated with the prefab.");
                bool Pad2PuppetController1TouchFlag = true;
                // This is a problem: how do we manipulate the rigid body character with these values?
                // Where do we rescale the coordinates to the view / screen or world?

                //construct a mouse touch / touch point
                // Input.Touch point is a vec2
                // Input.Mouse is a vec3
                // Then send to animationHandler

                // TOUCHOSC INVERTS THIS
                // TEST FOR THE LEMUR
                float x1 = (float)args[1] * multiplier;
                float y1 = (float)args[0] * multiplier;
                float z1 = 0.05f;                 // z of head in prefab

                // send first touch x y z to second and third touch scripts
                firstTouch = new Vector3(x1, y1, z1);
            }
        }
    }
コード例 #3
0
 public static OSCMessage TUIOFseq(int fseq)
 {
     OSCMessage oscm = new OSCMessage("/tuio/2Dcur");
     oscm.Append("fseq");
     oscm.Append(fseq);
     return oscm;
 }
コード例 #4
0
    public void OSCMessageReceived(OSC.NET.OSCMessage msg)
    {
        ArrayList args = msg.Values;

        ShotManager.instance.NetworkShoot((float)args[0], (1f - (float)args[1]));
        print(args[0] + "    " + args[1]);
    }
コード例 #5
0
ファイル: OpenGyro.cs プロジェクト: saerus/opencontrollers
 IEnumerator sendInfos()
 {
     while (true)
     {
         // GYRO
         OSC.NET.OSCMessage messageGyro = new OSC.NET.OSCMessage("gyro");
         messageGyro.Append(q.x);
         messageGyro.Append(q.y);
         messageGyro.Append(q.z);
         messageGyro.Append(q.w);
         messageGyro.Append(savedAngle);
         BroadcastMessage("TransmitMessage", messageGyro);
         //
         OSC.NET.OSCMessage messageAccel = new OSC.NET.OSCMessage("accel");
         messageAccel.Append(Input.acceleration.x);
         messageAccel.Append(Input.acceleration.y);
         messageAccel.Append(Input.acceleration.z);
         messageAccel.Append(Input.gyro.gravity.x);
         messageAccel.Append(Input.gyro.gravity.y);
         messageAccel.Append(Input.gyro.gravity.z);
         BroadcastMessage("TransmitMessage", messageAccel);
         //
         yield return(new WaitForSeconds(0.1f));
     }
 }
コード例 #6
0
 public static OSCMessage frameMessage(int frame)
 {
     OSCMessage message = new OSCMessage("/tuio/2Dblb");
     message.Append("fseq");
     message.Append(frame);
     return message;
 }
コード例 #7
0
 //
 void TransmitMessage(OSC.NET.OSCMessage _msg)
 {
     if (transmitter != null)
     {
         transmitter.Connect();
         transmitter.Send(_msg);
         transmitter.Close();
     }
 }
コード例 #8
0
 public static OSCMessage aliveMessage(List<Contact> contacts)
 {
     OSCMessage message = new OSCMessage("/tuio/2Dblb");
     message.Append("alive");
     for (int i = 0; i < contacts.Count; i++)
     {
         message.Append(contacts[i].Id);
     }
     return message;
 }
コード例 #9
0
 public static OSCMessage aliveMessage(ReadOnlyTouchPointCollection contacts)
 {
     OSCMessage message = new OSCMessage("/tuio/2Dcur");
     message.Append("alive");
     for (int i = 0; i < contacts.Count; i++)
     {
         message.Append(contacts[i].Id);
     }
     return message;
 }
コード例 #10
0
        public static OSCMessage TUIOParams(params object[] args)
        {
            OSCMessage oscm = new OSCMessage("/tuio/2Dcur");

            for (int I = 0; I < args.Length; I++)
            {
                oscm.Append(args[I]);
            }
            return oscm;
        }
コード例 #11
0
    public void OSCMessageReceived(OSC.NET.OSCMessage message)
    {
        string    address = message.Address;
        ArrayList args    = message.Values;

        Debug.Log(address);

        /*foreach( var item in args){
         *      Debug.Log(item);
         * }*/
    }
コード例 #12
0
 public static OSCMessage setMessage(int s, float x, float y, float xVec, float yVec, float m)
 {
     OSCMessage message = new OSCMessage("/tuio/2Dcur");
     message.Append("set");
     message.Append(s);
     message.Append(x);
     message.Append(y);
     message.Append(xVec);
     message.Append(yVec);
     message.Append(m);
     return message;
 }
コード例 #13
0
        public void processEventFrame()
        {
            // Create an new TUIO Bundle
                OSCBundle pBundle = new OSCBundle();

                // Create a fseq message and save it.  This is to associate a unique frame id with a bundle of SET and ALIVE.
                OSCMessage pMessageFseq = new OSCMessage("/tuio/2Dcur");
                pMessageFseq.Append("fseq");
                pMessageFseq.Append(++iFrame);//(int)e.Timestamp);
                pBundle.Append(pMessageFseq);

                // Create a alive message.
                OSCMessage pMessageAlive = new OSCMessage("/tuio/2Dcur");
                pMessageAlive.Append("alive");

                // Now we want to take the raw frame data and draw points based on its data.
                WiiContact contact;
                while (contactQueue.Count > 0)
                {
                    contact = contactQueue.Dequeue();
                    if ((contact.Type == ContactType.Hover || contact.Type == ContactType.EndFromHover))
                    {
                        //No hover yet
                    }
                    else
                    {
                        // Compile the set message.
                        OSCMessage pMessage = new OSCMessage("/tuio/2Dcur");
                        pMessage.Append("set");                 // set
                        pMessage.Append((int)contact.ID);           // session
                        pMessage.Append((float)contact.NormalPosition.X);   // x
                        pMessage.Append((float)contact.NormalPosition.Y);   // y
                        pMessage.Append(0f);                 // dx
                        pMessage.Append(0f);                 // dy
                        pMessage.Append(0f);                 // motion
                        pMessage.Append((float)contact.Size.X);   // height
                        pMessage.Append((float)contact.Size.Y);   // width

                        // Append it to the bundle.
                        pBundle.Append(pMessage);

                        // Append the alive message for this contact to tbe bundle.
                        pMessageAlive.Append((int)contact.ID);
                    }
                }

                // Save the alive message.
                pBundle.Append(pMessageAlive);

                // Send the message off.
                this.pUDPWriter.Send(pBundle);
        }
コード例 #14
0
    public void OSCMessageReceived(OSC.NET.OSCMessage message)
    {
        if (message.IsBundle())
        {
            string    address = message.Address;
            ArrayList args    = message.Values;

            Debug.Log(address);
            foreach (var item in args)
            {
                Debug.Log(item);
            }
        }
    }
コード例 #15
0
    public void OSCMessageReceived(OSC.NET.OSCMessage message)
    {
        string    address = message.Address;
        ArrayList args    = message.Values;

        if (debugMode)
        {
            Debug.Log("adress : " + address);
        }


        //get the type of button
        string type = address.Replace("/", string.Empty);

        type = Regex.Replace(type, @"\d", string.Empty);


        foreach (GameObject tmpObj in GameObject.FindGameObjectsWithTag("OSCTarget"))
        {
            //send data for simple target game objects
            if (tmpObj.GetComponent <OSCSimpleTarget>() != null)
            {
                if (tmpObj.GetComponent <OSCSimpleTarget>().targetName == address)
                {
                    target = tmpObj;
                    target.SendMessage("OnOscMessage", args);
                }
            }

            //send data for multiple target game objects
            if (tmpObj.GetComponent <OSCMultiTarget>() != null)
            {
                for (var i = 0; i < tmpObj.GetComponent <OSCMultiTarget>().targetName.Count; i++)
                {
                    if (tmpObj.GetComponent <OSCMultiTarget>().targetName[i] == address)
                    {
                        target = tmpObj;

                        tmpObj.GetComponent <OSCMultiTarget>().type = type;
                        target.SendMessage("OnOscMessage", args);
                    }
                }
            }


            //send data accelerometer
        }         // end foreach
    }
コード例 #16
0
    public void OSCMessageReceived(OSC.NET.OSCMessage message)
    {
        string    address = message.Address;
        ArrayList args    = message.Values;

        if (address.StartsWith("/joint"))
        {
            var joint = args[0].ToString();
            if (!Users.ContainsKey((int)args[1]))
            {
                this.Users.Add((int)args[1], new UserSkeleton());
            }
            var user = this.Users[(int)args[1]];
            if (joint == "torso")
            {
                user.torso = (float)args[3];
            }
            else if (joint == "l_hip")
            {
                user.l_hip = (float)args[2];
            }
            else if (joint == "r_hip")
            {
                user.r_hip = (float)args[2];
            }
            else if (joint == "l_knee")
            {
                user.l_knee = (float)args[3];
            }
            else if (joint == "r_knee")
            {
                user.r_knee = (float)args[3];
            }
            else if (joint == "neck")
            {
                user.neck = (float)args[3];
            }
        }
        else if (address.StartsWith("/new_skel"))
        {
            this.Users.Add((int)args[0], new UserSkeleton());
        }
        else if (address.StartsWith("/lost_user"))
        {
            this.Users.Remove((int)args[0]);
            BroadcastMessage("RemoveUser", (int)args[0], SendMessageOptions.DontRequireReceiver);
        }
    }
コード例 #17
0
 public static OSCMessage setMessage(int s, int i, float x, float y, float a, float xVec, float yVec, float A, float m, float r)
 {
     OSCMessage message = new OSCMessage("/tuio/2Dobj");
     message.Append("set");
     message.Append(s);
     message.Append(i);
     message.Append(x);
     message.Append(y);
     message.Append(a);
     message.Append(xVec);
     message.Append(yVec);
     message.Append(A);
     message.Append(m);
     message.Append(r);
     return message;
 }
コード例 #18
0
        /// <summary>
        /// Forward the given touch message.
        /// </summary>
        /// <param name="?"></param>
        public void Forward(TouchMessage Message)
        {
            // Skip bad messages
            if (Message == null)
                return;

            // If we have a bad startup condition.
            if (pUDPWriter == null)
                return;

            // Create an new TUIO Bundle
            OSCBundle pBundle = new OSCBundle();

            // Create a fseq message and save it.  This is to associate a unique frame id with a bundle of SET and ALIVE.
            OSCMessage pMessageFseq = new OSCMessage("/tuio/2Dcur");
            pMessageFseq.Append("fseq");
            pMessageFseq.Append(++iFrame);
            pBundle.Append(pMessageFseq);

            // Create a alive message.
            OSCMessage pMessageAlive = new OSCMessage("/tuio/2Dcur");
            pMessageAlive.Append("alive");

            // Compile the set message.
            OSCMessage pMessage = new OSCMessage("/tuio/2Dcur");
            pMessage.Append("set");                             // set
            pMessage.Append((int)Message.ID);                   // session
            pMessage.Append((float)Message.X);                  // x
            pMessage.Append((float)Message.Y);                  // y
            pMessage.Append(0f);                                // dx
            pMessage.Append(0f);                                // dy
            pMessage.Append(0f);                                // motion
            pMessage.Append(1f);                                // height
            pMessage.Append(1f);                                // width

            // Append it to the bundle.
            pBundle.Append(pMessage);

            // Append the alive message for this contact to tbe bundle.
            pMessageAlive.Append((int)Message.ID);

            // Save the alive message.
            pBundle.Append(pMessageAlive);

            // Send the message off.
            this.pUDPWriter.Send(pBundle);
        }
コード例 #19
0
    public void OSCMessageReceived(OSC.NET.OSCMessage message)
    {
        float x = (float)message.Values[0];
        float y = (float)message.Values[1];

        Fire(new Vector2(x, y));
        //      if(message.Address == "/endGame"){
        //              AdjustGameSetting("Quit Game", true);
        //              timer = 0;
        //      } else if(message.Address == "/timeChange"){
        //              ArrayList args = message.Values;
        //	        print(args[0]);
        //	        string recieved = args[0].ToString();
        //	        float time;
        //	        float.TryParse(recieved, out time);
        //	        AdjustGameSetting("Game Time", time);
        //      }
    }
コード例 #20
0
 public static OSCMessage setMessage(int s, float x, float y, float a, float w, float h, float f, float xVec, float yVec, float A, float m, float r)
 {
     OSCMessage message = new OSCMessage("/tuio/2Dblb");
     message.Append("set");
     message.Append(s);
     message.Append(x);
     message.Append(y);
     message.Append(a);
     message.Append(w);
     message.Append(h);
     message.Append(f);
     message.Append(xVec);
     message.Append(yVec);
     message.Append(A);
     message.Append(m);
     message.Append(r);
     return message;
 }
コード例 #21
0
ファイル: OSCMessage.cs プロジェクト: slgrobotics/TrackRoamer
        public static OSCMessage Unpack(byte[] bytes, ref int start)
        {
            string address = unpackString(bytes, ref start);
            OSCMessage msg = new OSCMessage(address);

            char[] tags = unpackString(bytes, ref start).ToCharArray();
            foreach(char tag in tags)
            {
                if(tag == ',') continue;
                else if(tag == INTEGER) msg.Append(unpackInt(bytes, ref start));
                else if(tag == LONG) msg.Append(unpackLong(bytes, ref start));
                else if(tag == DOUBLE) msg.Append(unpackFloat(bytes, ref start));
                else if (tag == FLOAT) msg.Append(unpackFloat(bytes, ref start));
                else if (tag == STRING || tag == SYMBOL) msg.Append(unpackString(bytes, ref start));
                //else ; // TODO
            }

            return msg;
        }
コード例 #22
0
        public void processEventFrame(FrameEventArgs e)
        {
            // Create an new TUIO Bundle
                OSCBundle pBundle = new OSCBundle();

                // Create a fseq message and save it.  This is to associate a unique frame id with a bundle of SET and ALIVE.
                OSCMessage pMessageFseq = new OSCMessage("/tuio/2Dcur");
                pMessageFseq.Append("fseq");
                pMessageFseq.Append(++iFrame);//(int)e.Timestamp);
                pBundle.Append(pMessageFseq);

                // Create a alive message.
                OSCMessage pMessageAlive = new OSCMessage("/tuio/2Dcur");
                pMessageAlive.Append("alive");

                // Now we want to take the raw frame data and draw points based on its data.
                foreach (WiiContact pContact in e.Contacts)
                {
                    // Compile the set message.
                    OSCMessage pMessage = new OSCMessage("/tuio/2Dcur");
                    pMessage.Append("set");                 // set
                    pMessage.Append((int)pContact.ID);           // session
                    pMessage.Append((float)pContact.NormalPosition.X);   // x
                    pMessage.Append((float)pContact.NormalPosition.Y);   // y
                    pMessage.Append(0f);                 // dx
                    pMessage.Append(0f);                 // dy
                    pMessage.Append(0f);                 // motion
                    pMessage.Append((float)pContact.Size.X);   // height
                    pMessage.Append((float)pContact.Size.Y);   // width

                    // Append it to the bundle.
                    pBundle.Append(pMessage);

                    // Append the alive message for this contact to tbe bundle.
                    pMessageAlive.Append((int)pContact.ID);
                }

                // Save the alive message.
                pBundle.Append(pMessageAlive);

                // Send the message off.
                this.pUDPWriter.Send(pBundle);
        }
コード例 #23
0
    public void OSCMessageReceived(OSC.NET.OSCMessage message)
    {
        string    address = message.Address;
        ArrayList args    = message.Values;


        if (address == "/TSPS/personEntered/")
        {
            addPerson(args);
        }
        else if (address == "/TSPS/personUpdated/")
        {
            int    person_id = (int)args[0];
            Person person    = null;
            if (!people.ContainsKey(person_id))
            {
                person = addPerson(args);
            }
            else
            {
                person = people[person_id];
                updatePerson(person, args);
                //personUpdated(person);
                BroadcastMessage("PersonUpdated", person, SendMessageOptions.DontRequireReceiver);
            }
        }
        else if (address == "/TSPS/personWillLeave/")
        {
            int person_id = (int)args[0];
            if (people.ContainsKey(person_id))
            {
                Person personToRemove = people[person_id];
                BroadcastMessage("PersonWillLeave", personToRemove, SendMessageOptions.DontRequireReceiver);
                people.Remove(person_id);
                //personWillLeave(personToRemove);
            }
        }
        else
        {
            print(address + " ");
        }
    }
コード例 #24
0
        public static OSCMessage Unpack(byte[] bytes, ref int start)
        {
            string address = unpackString(bytes, ref start);
            //Console.WriteLine("address: " + address);
            OSCMessage msg = new OSCMessage(address);

            char[] tags = unpackString(bytes, ref start).ToCharArray();
            //Console.WriteLine("tags: " + new string(tags));
            foreach(char tag in tags)
            {
                //Console.WriteLine("tag: " + tag + " @ "+start);
                if(tag == ',') continue;
                else if(tag == INTEGER) msg.Append(unpackInt(bytes, ref start));
                else if(tag == LONG) msg.Append(unpackLong(bytes, ref start));
                else if(tag == DOUBLE) msg.Append(unpackDouble(bytes, ref start));
                else if(tag == FLOAT) msg.Append(unpackFloat(bytes, ref start));
                else if(tag == STRING || tag == SYMBOL) msg.Append(unpackString(bytes, ref start));
                else Console.WriteLine("unknown tag: "+tag);
            }

            return msg;
        }
コード例 #25
0
        private void interpretAccelerationData(double accX, double accY, double accZ)
        {
            accX *= GfCnv;
            accY *= GfCnv;
            accZ *= GfCnv;

            this.accelXLabel.Text = String.Format("{0}", accX);
            this.accelYLabel.Text = String.Format("{0}", accY);
            this.accelZLabel.Text = String.Format("{0}", accZ);

            robotViewControl1.setAccelerometerData(accX, accY, accZ);

            if (oscTransmitter != null)
            {
                OSCMessage oscAccelData = new OSCMessage("/accel-g");
                oscAccelData.Append((float)(accX * 5.0d));
                oscAccelData.Append((float)(accY * 5.0d));
                oscAccelData.Append((float)(accZ * 5.0d));

                oscTransmitter.Send(oscAccelData);
            }
        }
コード例 #26
0
ファイル: TUIOClient.cs プロジェクト: rwxr-xr-x/HomeGenie
 private void processMessage(OSCMessage message)
 {
     for (int i = 0; i < listenerList.Count; i++)
     {
         TUIOListener listener = (TUIOListener)listenerList[i];
         if (listener != null)
         {
             if (listener.processMessage(message)) break;
         }
     }
 }
コード例 #27
0
 private void processMessage(OSCMessage message)
 {
     string address = message.Address;
     ArrayList args = message.Values;
     Debug.Log ("OSC MESSAGE--->ADDRESS: " + address + " --> VALUES:");
     for (int i = 0; i < args.Count; i++)
     {
         Debug.Log("VALUE: " + args[i].ToString() + " . TYPE: " + args[i].GetType());
     }
 }
コード例 #28
0
    private void processMessage(OSCMessage message)
    {
        string address = message.Address;
        ArrayList args = message.Values;

        float x,y,z;

        // TEST WITH SKELETON 1 ONLY
        if (address == "/skeleton/1/center")
        {
            x = (float) args[0];
            y = (float) args[1];
            z = (float) args[2];

            center = getJointPosition(new Vector3(x,y,z));

            Debug.Log("Tracking Skeleton Center: " + center);
        }
        else if (address == "/skeleton/1/neck/realWorld")
        {
            x = (float) args[0];
            y = (float) args[1];
            z = (float) args[2];
            neckStart = getJointPosition(new Vector3(x,y,z));
            x = (float) args[3];
            y = (float) args[4];
            z = (float) args[5];
            neckEnd = getJointPosition(new Vector3(x,y,z));
        }
        else if (address == "/skeleton/1/hip/realWorld")
        {
            x = (float) args[0];
            y = (float) args[1];
            z = (float) args[2];
            hipStart = getJointPosition(new Vector3(x,y,z));
            x = (float) args[3];
            y = (float) args[4];
            z = (float) args[5];
            hipEnd = getJointPosition(new Vector3(x,y,z));
        }
        else if (address == "/skeleton/1/left_upper_torso/realWorld")
        {
            x = (float) args[0];
            y = (float) args[1];
            z = (float) args[2];
            leftUpperTorsoStart = getJointPosition(new Vector3(x,y,z));
            x = (float) args[3];
            y = (float) args[4];
            z = (float) args[5];
            leftUpperTorsoEnd = getJointPosition(new Vector3(x,y,z));
        }
        else if (address == "/skeleton/1/right_upper_torso/realWorld")
        {
            x = (float) args[0];
            y = (float) args[1];
            z = (float) args[2];
            rightUpperTorsoStart = getJointPosition(new Vector3(x,y,z));
            x = (float) args[3];
            y = (float) args[4];
            z = (float) args[5];
            rightUpperTorsoEnd = getJointPosition(new Vector3(x,y,z));
        }
        else if (address == "/skeleton/1/left_lower_torso/realWorld")
        {
            x = (float) args[0];
            y = (float) args[1];
            z = (float) args[2];
            leftLowerTorsoStart = getJointPosition(new Vector3(x,y,z));
            x = (float) args[3];
            y = (float) args[4];
            z = (float) args[5];
            leftLowerTorsoEnd = getJointPosition(new Vector3(x,y,z));
        }
        else if (address == "/skeleton/1/right_lower_torso/realWorld")
        {
            x = (float) args[0];
            y = (float) args[1];
            z = (float) args[2];
            rightLowerTorsoStart = getJointPosition(new Vector3(x,y,z));
            x = (float) args[3];
            y = (float) args[4];
            z = (float) args[5];
            rightLowerTorsoEnd = getJointPosition(new Vector3(x,y,z));
        }
        else if (address == "/skeleton/1/left_upper_leg/realWorld")
        {
            x = (float) args[0];
            y = (float) args[1];
            z = (float) args[2];
            leftUpperLegStart = getJointPosition(new Vector3(x,y,z));
            x = (float) args[3];
            y = (float) args[4];
            z = (float) args[5];
            leftUpperLegEnd = getJointPosition(new Vector3(x,y,z));
        }
        else if (address == "/skeleton/1/left_lower_leg/realWorld")
        {
            x = (float) args[0];
            y = (float) args[1];
            z = (float) args[2];
            leftLowerLegStart = getJointPosition(new Vector3(x,y,z));
            x = (float) args[3];
            y = (float) args[4];
            z = (float) args[5];
            leftLowerLegEnd = getJointPosition(new Vector3(x,y,z));
        }
        else if (address == "/skeleton/1/right_upper_leg/realWorld")
        {
            x = (float) args[0];
            y = (float) args[1];
            z = (float) args[2];
            rightUpperLegStart = getJointPosition(new Vector3(x,y,z));
            x = (float) args[3];
            y = (float) args[4];
            z = (float) args[5];
            rightUpperLegEnd = getJointPosition(new Vector3(x,y,z));
        }
        else if (address == "/skeleton/1/right_lower_leg/realWorld")
        {
            x = (float) args[0];
            y = (float) args[1];
            z = (float) args[2];
            rightLowerLegStart = getJointPosition(new Vector3(x,y,z));
            x = (float) args[3];
            y = (float) args[4];
            z = (float) args[5];
            rightLowerLegEnd = getJointPosition(new Vector3(x,y,z));
        }
        else if (address == "/skeleton/1/left_shoulder/realWorld")
        {
            x = (float) args[0];
            y = (float) args[1];
            z = (float) args[2];
            leftShoulderStart = getJointPosition(new Vector3(x,y,z));
            x = (float) args[3];
            y = (float) args[4];
            z = (float) args[5];
            leftShoulderEnd = getJointPosition(new Vector3(x,y,z));
        }
        else if (address == "/skeleton/1/right_shoulder/realWorld")
        {
            x = (float) args[0];
            y = (float) args[1];
            z = (float) args[2];
            rightShoulderStart = getJointPosition(new Vector3(x,y,z));
            x = (float) args[3];
            y = (float) args[4];
            z = (float) args[5];
            rightShoulderEnd = getJointPosition(new Vector3(x,y,z));
        }
        else if (address == "/skeleton/1/left_upper_arm/realWorld")
        {
            x = (float) args[0];
            y = (float) args[1];
            z = (float) args[2];
            leftUpperArmStart = getJointPosition(new Vector3(x,y,z));
            x = (float) args[3];
            y = (float) args[4];
            z = (float) args[5];
            leftUpperArmEnd = getJointPosition(new Vector3(x,y,z));
        }
        else if (address == "/skeleton/1/left_lower_arm/realWorld")
        {
            x = (float) args[0];
            y = (float) args[1];
            z = (float) args[2];
            leftLowerArmStart = getJointPosition(new Vector3(x,y,z));
            x = (float) args[3];
            y = (float) args[4];
            z = (float) args[5];
            leftLowerArmEnd = getJointPosition(new Vector3(x,y,z));
        }
        else if (address == "/skeleton/1/right_upper_arm/realWorld")
        {
            x = (float) args[0];
            y = (float) args[1];
            z = (float) args[2];
            rightUpperArmStart = getJointPosition(new Vector3(x,y,z));
            x = (float) args[3];
            y = (float) args[4];
            z = (float) args[5];
            rightUpperArmEnd = getJointPosition(new Vector3(x,y,z));
        }
        else if (address == "/skeleton/1/right_lower_arm/realWorld")
        {
            x = (float) args[0];
            y = (float) args[1];
            z = (float) args[2];
            rightLowerArmStart = getJointPosition(new Vector3(x,y,z));
            x = (float) args[3];
            y = (float) args[4];
            z = (float) args[5];
            rightLowerArmEnd = getJointPosition(new Vector3(x,y,z));
        }
    }
コード例 #29
0
ファイル: TuioDemo.cs プロジェクト: oomojola/Tuio-Skeleton
 public void doneCapturePhoto()
 {
     OSC.NET.OSCMessage m = new OSC.NET.OSCMessage("camera_on");
         OSC.NET.OSCTransmitter t = new OSC.NET.OSCTransmitter("localhost", capturePort + 1);
         t.Connect();
         t.Send(m);
 }
コード例 #30
0
ファイル: TuioClient.cs プロジェクト: pichiliani/CoMusic
        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];
                    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.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);
                        }
                    }
                }

            }
        }
コード例 #31
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();
                }

            }
        }
コード例 #32
0
        public static OSCMessage sourceMessage()
        {
            StringCollection localIP = Helper.getLocalIP();

            OSCMessage message = new OSCMessage("/tuio/2Dblb");
            message.Append("source");
            message.Append("surface@" + localIP[3]);
            return message;
        }
コード例 #33
0
ファイル: WiimoteReceiver.cs プロジェクト: adrianblp/Teamtris
 private void processMessage(OSCMessage message)
 {
     string address = message.Address;
     int wiimoteID = int.Parse(address.Substring(5,1));
     //UnityEngine.Debug.Log (message.Address);
     // Is wii OSC message
     if( String.Compare(address.Substring(1,3), "wii") == 0)
     {
         // Does Wiimote object id already exist ?
         if( !wiimotes.ContainsKey(wiimoteID) )
         {
             wiimotes.Add(wiimoteID, new Wiimote(wiimoteID) );
         }
         // Update Wiimote Object
         try
         {
             Wiimote mote = wiimotes[wiimoteID];
             string wiiEvent = address.Substring(7);
             mote.update(wiiEvent, ArrayList.ReadOnly(message.Values), DateTime.Now );
             Console.WriteLine(wiiEvent);
         } catch(Exception e)
         {
             Console.WriteLine( "Failed to get Wiimote Object from Dictionary" + e.Message);
         }
     }
 }
コード例 #34
0
    public void OSCMessageReceived(OSC.NET.OSCMessage message)
    {
        string address = message.Address;
        //ArrayList args = message.Values;
        Bounds bounds = new Bounds(Vector3.zero, new Vector3(1, 2, 1));

        if (address.Contains("rot") && init)
        {
            //Debug.Log (address);
            string[] rotVals = address.Substring(4).Split('|');
            if (rotVals[0].IndexOf("null") == -1)
            {
                float  alpha = float.Parse(rotVals [0]);
                float  beta  = float.Parse(rotVals [1]);
                float  gamma = float.Parse(rotVals [2]);
                string rotId = rotVals[3];
                rotation = Quaternion.Euler(beta, gamma, alpha);
                //rotation = new Quaternion (x, y, z, w);
                GameObject shapeToRotate = GameObject.Find(rotId);
                //hand.transform.Translate (x/factor, y/factor, z/factor, null);
                if (shapeToRotate)
                {
                    shapeToRotate.transform.rotation = rotation;
                }
            }
        }
        if (address.Contains("acc") && init)
        {
            string[] accVals = address.Substring(4).Split('|');
            //Debug.Log(accVals[0].IndexOf("null"));
            if (accVals[0].IndexOf("null") == -1)
            {
                float   valX = float.Parse(accVals [0]);
                float   valY = float.Parse(accVals [1]);
                float   valZ = float.Parse(accVals [2]);
                float   x    = NormalizeAccel(valX);
                float   y    = NormalizeAccel(valY);
                float   z    = NormalizeAccel(valZ);
                Vector3 v    = new Vector3(valX * scaleFactor, valY * scaleFactor, valZ * scaleFactor);
                //Vector3 normV = new Vector3(x, y, z);
                string     accId        = accVals[3];
                GameObject shapeToScale = GameObject.Find(accId);
                if (shapeToScale)
                {
                    //move mv = shapeToScale.GetComponent<move>();
                    shapeToScale.GetComponent <move>().scaleShape(v.sqrMagnitude);
                    if ((x + y + z) > minAccelForLaunch)
                    {
                        shapeToScale.GetComponent <move>().Fling(v);
                    }
                    shapeToScale.GetComponent <move>().timeSinceDisconnected = 0f;
                    shapeToScale.GetComponent <MidiControl>().sendCC(v.sqrMagnitude);
                    // not sure about the halo look
                    //cubeToScale.transform.GetComponentInChildren<Light>().light.range = 3 * (x + y + z);
                }
            }
        }
        if (address.Contains("message") && !init)
        {
            string[] messageVals = address.Substring(8).Split('|');
            Debug.Log(messageVals);
        }

        if (address.Contains("create"))
        {
            if (shapeCounter == 12)
            {
                return;
            }
            string[] createVals = address.Substring(8).Split('|');
            //Debug.Log (createVals[0] + " -- " + createVals[1] + " -- " + createVals[2]);
            string[] hsl      = createVals[1].Split(',');
            HSLColor hslColor = new HSLColor(float.Parse(hsl[0]), float.Parse(hsl[1]), float.Parse(hsl[2]));
            //Color shapeColor = hslColor.ToRGBA();
            string[] rgb        = createVals[1].Split(',');
            Color    shapeColor = new Color(float.Parse(rgb[0]) / 255f, float.Parse(rgb[1]) / 255f, float.Parse(rgb[2]) / 255f);
            Debug.Log(shapeColor);
            string     id          = createVals[2];
            int        shapesIndex = int.Parse(createVals[0]);
            GameObject newShape;
            Vector3    initPos    = helpers.locationOnXYCircle(shapeCounter, radius, angle);
            int        shapeCount = shapeCounter % numShapes;
            newShape = (GameObject)Instantiate(shapes[shapesIndex], initPos, Quaternion.identity);
            //			if (shapeCounter % 3 == 0) {
            //				newShape = (GameObject)Instantiate(shape1, initPos, Quaternion.identity);
            //			} else if (shapeCounter % 2 == 0) {
            //				newShape = (GameObject)Instantiate(shape2, initPos, Quaternion.identity);
            //			} else  {
            //				newShape = (GameObject)Instantiate(shape3, initPos, Quaternion.identity);
            //			}
            newShape.name = id;
            newShape.GetComponent <MidiControl>().controlNumber = shapeCounter + 1;
            newShape.GetComponent <move>().initPos = initPos;
            Renderer[] shapeRenderers = newShape.GetComponentsInChildren <Renderer>();
            foreach (Renderer renderer in shapeRenderers)
            {
                renderer.material.SetColor("_Color", shapeColor);
                renderer.material.SetColor("_SpecColor", shapeColor);
            }
            ;
            Transform trail = newShape.transform.Find("Trail");
            trail.renderer.material.SetColor("_TintColor", shapeColor);
            //bounds.Encapsulate(newShape.transform.position);
            init = true;
            shapeCounter++;

//			message = new OSCMessage("/shape", "1");
//			transmitter = new OSCTransmitter("10.0.0.2", sendport);
//			transmitter.Send(message);
        }
    }
コード例 #35
0
    /// <summary>
    /// Processes the OSC message.
    /// </summary>
    /// <param name='message'>
    /// The Message.
    /// </param>
    private void processMessage(OSCMessage message)
    {
        string address = message.Address;
        ArrayList args = message.Values;
        //Debug.Log("ADDRESS: " + address);
        // THIS IS HACK FIXME
        string actor_str = Regex.Replace(address,@"[/a-zA-Z_]*",String.Empty);
        int actor_id = Convert.ToInt32(actor_str);
        //Debug.Log("SKELETON ACTOR: " + actor_id);

        switch (actor_id)
        {
        case 1:
            oniActorOneScript.updateJointCoordinates(args, address);
            break;
        case 2:
            oniActorTwoScript.updateJointCoordinates(args, address);
            break;
        default:
        break;
        }
    }
コード例 #36
0
ファイル: TuioClient.cs プロジェクト: yothere/TUIO
        /**
         * The OSC callback method where all TUIO messages are received and decoded
         * and where the TUIO event callbacks are dispatched
         *
         * @param message	the received OSC message
         */
        private void processMessage(OSCMessage message)
        {
            string address = message.Address;
            ArrayList args = message.Values;
            string command = (string)args[0];

            if (address == "/tuio/2Dobj") {
                if (command == "set") {

                    long s_id = (int)args[1];
                    int f_id = (int)args[2];
                    float xpos = (float)args[3];
                    float ypos = (float)args[4];
                    float angle = (float)args[5];
                    float xspeed = (float)args[6];
                    float yspeed = (float)args[7];
                    float rspeed = (float)args[8];
                    float maccel = (float)args[9];
                    float raccel = (float)args[10];

                    lock(objectSync) {
                        if (!objectList.ContainsKey(s_id)) {
                            TuioObject addObject = new TuioObject(s_id,f_id,xpos,ypos,angle);
                            frameObjects.Add(addObject);
                        } else {
                            TuioObject tobj = objectList[s_id];
                            if (tobj==null) return;
                            if((tobj.getX()!=xpos) || (tobj.getY()!=ypos) || (tobj.getAngle()!=angle) || (tobj.getXSpeed()!=xspeed) || (tobj.getYSpeed()!=yspeed) || (tobj.getRotationSpeed()!=rspeed) || (tobj.getMotionAccel()!=maccel) || (tobj.getRotationAccel()!=raccel)) {

                                TuioObject updateObject = new TuioObject(s_id,f_id,xpos,ypos,angle);
                                updateObject.update(xpos,ypos,angle,xspeed,yspeed,rspeed,maccel,raccel);
                                frameObjects.Add(updateObject);
                            }
                        }
                    }

                } else if (command == "alive") {

                    newObjectList.Clear();
                    for (int i=1;i<args.Count;i++) {
                        // get the message content
                        long s_id = (int)args[i];
                        newObjectList.Add(s_id);
                        // reduce the object list to the lost objects
                        if (aliveObjectList.Contains(s_id))
                             aliveObjectList.Remove(s_id);
                    }

                    // remove the remaining objects
                    lock(objectSync) {
                        for (int i=0;i<aliveObjectList.Count;i++) {
                            long s_id = aliveObjectList[i];
                            TuioObject removeObject = objectList[s_id];
                            removeObject.remove(currentTime);
                            frameObjects.Add(removeObject);
                        }
                    }

                } else if (command=="fseq") {
                    int fseq = (int)args[1];
                    bool lateFrame = false;

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

                    if (!lateFrame) {

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

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

                                    for (int i=0;i<listenerList.Count;i++) {
                                        TuioListener listener = (TuioListener)listenerList[i];
                                        if (listener!=null) listener.removeTuioObject(removeObject);
                                    }
                                    lock(objectSync) {
                                        objectList.Remove(removeObject.getSessionID());
                                    }
                                    break;
                                case TuioObject.TUIO_ADDED:
                                    TuioObject addObject = new TuioObject(currentTime,tobj.getSessionID(),tobj.getSymbolID(),tobj.getX(),tobj.getY(),tobj.getAngle());
                                    lock(objectSync) {
                                        objectList.Add(addObject.getSessionID(),addObject);
                                    }
                                    for (int i=0;i<listenerList.Count;i++) {
                                        TuioListener listener = (TuioListener)listenerList[i];
                                        if (listener!=null) listener.addTuioObject(addObject);
                                    }
                                    break;
                                default:
                                    TuioObject updateObject = getTuioObject(tobj.getSessionID());
                                    if ( (tobj.getX()!=updateObject.getX() && tobj.getXSpeed()==0) || (tobj.getY()!=updateObject.getY() && tobj.getYSpeed()==0) )
                                        updateObject.update(currentTime,tobj.getX(),tobj.getY(),tobj.getAngle());
                                    else
                                        updateObject.update(currentTime,tobj.getX(),tobj.getY(),tobj.getAngle(),tobj.getXSpeed(),tobj.getYSpeed(),tobj.getRotationSpeed(),tobj.getMotionAccel(),tobj.getRotationAccel());

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

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

                        List<long> buffer = aliveObjectList;
                        aliveObjectList = newObjectList;
                        // recycling the List
                        newObjectList = buffer;
                    }
                    frameObjects.Clear();
                }

            } else if (address == "/tuio/2Dcur") {

                if (command == "set") {

                    long s_id = (int)args[1];
                    float xpos = (float)args[2];
                    float ypos = (float)args[3];
                    float xspeed = (float)args[4];
                    float yspeed = (float)args[5];
                    float maccel = (float)args[6];

                    lock(cursorList) {
                        if (!cursorList.ContainsKey(s_id)) {

                            TuioCursor addCursor = new TuioCursor(s_id,-1,xpos,ypos);
                            frameCursors.Add(addCursor);

                        } else {
                            TuioCursor tcur = (TuioCursor)cursorList[s_id];
                            if (tcur==null) return;
                            if ((tcur.getX()!=xpos) || (tcur.getY()!=ypos) || (tcur.getXSpeed()!=xspeed) || (tcur.getYSpeed()!=yspeed) || (tcur.getMotionAccel()!=maccel)) {
                                TuioCursor updateCursor = new TuioCursor(s_id,tcur.getCursorID(),xpos,ypos);
                                updateCursor.update(xpos,ypos,xspeed,yspeed,maccel);
                                frameCursors.Add(updateCursor);
                            }
                        }
                    }

                } else if (command == "alive") {

                    newCursorList.Clear();
                    for (int i=1;i<args.Count;i++) {
                        // get the message content
                        long s_id = (int)args[i];
                        newCursorList.Add(s_id);
                        // reduce the cursor list to the lost cursors
                        if (aliveCursorList.Contains(s_id))
                            aliveCursorList.Remove(s_id);
                    }

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

                } else if (command=="fseq") {
                    int fseq = (int)args[1];
                    bool lateFrame = false;

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

                    if (!lateFrame) {

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

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

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

                                            if (cursorList.Count > 0) {

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

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

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

                                    addCursor = new TuioCursor(currentTime,tcur.getSessionID(),c_id,tcur.getX(),tcur.getY());
                                    cursorList.Add(addCursor.getSessionID(),addCursor);
                                }

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

                            default:
                                TuioCursor updateCursor = getTuioCursor(tcur.getSessionID());
                                if ( (tcur.getX()!=updateCursor.getX() && tcur.getXSpeed()==0) || (tcur.getY()!=updateCursor.getY() && tcur.getYSpeed()==0) )
                                    updateCursor.update(currentTime,tcur.getX(),tcur.getY());
                                else
                                    updateCursor.update(currentTime,tcur.getX(),tcur.getY(),tcur.getXSpeed(),tcur.getYSpeed(),tcur.getMotionAccel());

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

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

                        List<long> buffer = aliveCursorList;
                        aliveCursorList = newCursorList;
                        // recycling the List
                        newCursorList = buffer;
                    }
                    frameCursors.Clear();
                }

            }
        }
コード例 #37
0
        public int Send(OSCPacket packet)
        {
            int byteNum = 0;

            byte[] data;
            try
            {
                if (!portIsTcp)
                {
                    data    = packet.BinaryData;
                    byteNum = this.udpClient.Send(data, data.Length);
                }
                else
                {
                    OSCBundle bundle = packet as OSCBundle;

                    if (bundle != null)
                    {
                        foreach (var value in bundle.Values)
                        {
                            if (value is OSCMessage)
                            {
                                OSCMessage message    = value as OSCMessage;
                                XmlElement xmlMessage = message.ToXml;

                                //<OSCPACKET ADDRESS="127.0.0.1" PORT="49178" TIME="1">
                                XmlDocument xDoc      = new XmlDocument();
                                XmlElement  xmlPacket = xDoc.CreateElement("OSCPACKET");

                                XmlAttribute address = xDoc.CreateAttribute("ADDRESS");
                                address.Value = "127.0.0.1";

                                XmlAttribute port = xDoc.CreateAttribute("PORT");
                                port.Value = "0";

                                XmlAttribute time = xDoc.CreateAttribute("TIME");
                                time.Value = "0";

                                xmlPacket.Attributes.Append(address);
                                xmlPacket.Attributes.Append(port);
                                xmlPacket.Attributes.Append(time);


                                xDoc.AppendChild(xmlPacket);

                                xmlPacket.AppendChild(xDoc.ImportNode(xmlMessage, true));
                                String xml = xDoc.InnerXml;
                                //Console.Write(xml);
                                this.tcpServer.Broadcast(xDoc);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Console.Error.WriteLine(e.Message);
                Console.Error.WriteLine(e.StackTrace);
            }

            return(byteNum);
        }
コード例 #38
0
ファイル: TUIOReceiver.cs プロジェクト: florpan/HomeGenie
        public bool processMessage(OSCMessage message)
        {
            string address = message.Address;
            ArrayList args = message.Values;


            //Console.WriteLine(address + " > " + " , " + args[0] + " , " + args[1] + " , " + args[2] + " , " + args[3]);


            if (address == "/acceleration/xyz")
            {
                if (!accelerationEnable)
                    return false;

                float x = (float)args[0];
                float y = (float)args[1];
                float z = (float)args[2];

                if (AccelerometerUpdate != null)
                {
                    AccelerometerUpdateEventArgs eventargs = new AccelerometerUpdateEventArgs() { AccelerometerData = new AccelerometerData() { X = x, Y = y, Z = z } };
                    AccelerometerUpdate(this, eventargs);
                }

                return true;
            }
            else if (address == "/tuio/2Dobj")
            {

                // TODO: FIDUCIALS TRACKING NOT TESTED, comment out and test =)
                /*           
                string command = (string)args[0];

                if ((command == "set") && (_currentframe >= _lastframe))
                {
                    int 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 (!_objects.ContainsKey(args[1]))
                    {
                        TUIOData t = new TUIOData(f_id, x, y, a);
                        _objects.Add(s_id, t);
                        addTuioObj(s_id, f_id);
                        updateTuioObj(s_id, f_id, x, y, a, X, Y, A, m, r);
                    }
                    else
                    {
                        TUIOData t = (TUIOData)_objects[s_id];
                        if ((t.X != x) || (t.Y != y) || (t.Angle != a))
                        {
                            updateTuioObj(s_id, f_id, x, y, a, X, Y, A, m, r);
                            t.update(x, y, a);
                            _objects[s_id] = t;
                        }
                    }
                }
                else if ((command == "alive") && (_currentframe >= _lastframe))
                {

                    for (int i = 1; i < args.Count; i++)
                    {
                        // get the message content
                        _newobjects.Add((int)args[i]);
                        // reduce the object list to the lost objects
                        if (_aliveobjects.Contains(args[i]))
                            _aliveobjects.Remove(args[i]);
                    }

                    // remove the remaining objects
                    for (int i = 0; i < _aliveobjects.Count; i++)
                    {
                        int s_id = (int)_aliveobjects[i];
                        int f_id = ((TUIOData)_objects[_aliveobjects[i]]).f_id;
                        _objects.Remove(_aliveobjects[i]);
                        removeTuioObj(s_id, f_id);
                    }


                    ArrayList buffer = _aliveobjects;
                    _aliveobjects = _newobjects;

                    // recycling of the ArrayList
                    _newobjects = buffer;
                    _newobjects.Clear();
                }
                else if (command == "fseq")
                {
                    _lastframe = _currentframe;
                    _currentframe = (int)args[1];
                    if (_currentframe == -1) _currentframe = _lastframe;

                    if (_currentframe >= _lastframe)
                    {
                        refresh();
                    }
                }

//                _plugincontrol.UpdateMonitor(_cursors, _acceleration);

                return true; */
            }
            else if (address == "/tuio/2Dcur")
            {
                string command = (string)args[0];

                if ((command == "set") && (currentFrame >= lastFrame))
                {
                    int 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 (CursorUpdate != null)
                    {
                        CursorUpdateEventArgs eventargs = new CursorUpdateEventArgs() { Command = TuioCursorCommand.Set, CursorData = new TUIOData(s_id, x, y, X, Y, m) };
                        CursorUpdate(this, eventargs);
                    }

                }
                else if ((command == "alive") && (currentFrame >= lastFrame))
                {
                    CursorUpdateEventArgs eventargs = new CursorUpdateEventArgs() { Command = TuioCursorCommand.Alive, CursorData = new TUIOData(args) };
                    CursorUpdate(this, eventargs);
                }

                return true;
            }
            //
            // else... unknown/unsupported command =/
            //
            return false;
        }
コード例 #39
0
ファイル: TuioClient.cs プロジェクト: nuigroup/ccv-physics
        /**
         * The OSC callback method where all TUIO messages are received and decoded
         * and where the TUIO event callbacks are dispatched
         *
         * @param message	the received OSC message
         */
        private void processMessage(OSCMessage message)
        {
            string address = message.Address;
            ArrayList args = message.Values;
            string command = (string)args[0];

            if (address == "/tuio/2Dobj") {
                if (command == "set") {

                    long s_id = (int)args[1];
                    int f_id = (int)args[2];
                    float xpos = (float)args[3];
                    float ypos = (float)args[4];
                    float angle = (float)args[5];
                    float xspeed = (float)args[6];
                    float yspeed = (float)args[7];
                    float rspeed = (float)args[8];
                    float maccel = (float)args[9];
                    float raccel = (float)args[10];

                    lock(objectSync) {
                        if (!objectList.ContainsKey(s_id)) {
                            TuioObject addObject = new TuioObject(s_id,f_id,xpos,ypos,angle);
                            frameObjects.Add(addObject);
                        } else {
                            TuioObject tobj = objectList[s_id];
                            if (tobj==null) return;
                            if((tobj.getX()!=xpos) || (tobj.getY()!=ypos) || (tobj.getAngle()!=angle) || (tobj.getXSpeed()!=xspeed) || (tobj.getYSpeed()!=yspeed) || (tobj.getRotationSpeed()!=rspeed) || (tobj.getMotionAccel()!=maccel) || (tobj.getRotationAccel()!=raccel)) {

                                TuioObject updateObject = new TuioObject(s_id,f_id,xpos,ypos,angle);
                                updateObject.update(xpos,ypos,angle,xspeed,yspeed,rspeed,maccel,raccel);
                                frameObjects.Add(updateObject);
                            }
                        }
                    }

                } else if (command == "alive") {

                    newObjectList.Clear();
                    for (int i=1;i<args.Count;i++) {
                        // get the message content
                        long s_id = (int)args[i];
                        newObjectList.Add(s_id);
                        // reduce the object list to the lost objects
                        if (aliveObjectList.Contains(s_id))
                             aliveObjectList.Remove(s_id);
                    }

                    // remove the remaining objects
                    lock(objectSync) {
                        for (int i=0;i<aliveObjectList.Count;i++) {
                            long s_id = aliveObjectList[i];
                            TuioObject removeObject = objectList[s_id];
                            removeObject.remove(currentTime);
                            frameObjects.Add(removeObject);
                        }
                    }

                } else if (command=="fseq") {
                    int fseq = (int)args[1];
                    bool lateFrame = false;

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

                    if (!lateFrame) {

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

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

                                    for (int i=0;i<listenerList.Count;i++) {
                                        TuioListener listener = (TuioListener)listenerList[i];
                                        if (listener!=null) listener.removeTuioObject(removeObject);
                                    }
                                    lock(objectSync) {
                                        objectList.Remove(removeObject.getSessionID());
                                    }
                                    break;
                                case TuioObject.TUIO_ADDED:
                                    TuioObject addObject = new TuioObject(currentTime,tobj.getSessionID(),tobj.getSymbolID(),tobj.getX(),tobj.getY(),tobj.getAngle());
                                    lock(objectSync) {
                                        objectList.Add(addObject.getSessionID(),addObject);
                                    }
                                    for (int i=0;i<listenerList.Count;i++) {
                                        TuioListener listener = (TuioListener)listenerList[i];
                                        if (listener!=null) listener.addTuioObject(addObject);
                                    }
                                    break;
                                default:
                                    TuioObject updateObject = getTuioObject(tobj.getSessionID());
                                    if ( (tobj.getX()!=updateObject.getX() && tobj.getXSpeed()==0) || (tobj.getY()!=updateObject.getY() && tobj.getYSpeed()==0) )
                                        updateObject.update(currentTime,tobj.getX(),tobj.getY(),tobj.getAngle());
                                    else
                                        updateObject.update(currentTime,tobj.getX(),tobj.getY(),tobj.getAngle(),tobj.getXSpeed(),tobj.getYSpeed(),tobj.getRotationSpeed(),tobj.getMotionAccel(),tobj.getRotationAccel());

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

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

                        List<long> buffer = aliveObjectList;
                        aliveObjectList = newObjectList;
                        // recycling the List
                        newObjectList = buffer;
                    }
                    frameObjects.Clear();
                }

            } else if (address == "/tuio/2Dcur" || address == "/tuio/2Dcur source ccv@localhost") {

                if (command == "set") {

                    long s_id = (int)args[1];
                    float xpos = (float)args[2];
                    float ypos = (float)args[3];
                    float xspeed = (float)args[4];
                    float yspeed = (float)args[5];
                    float maccel = (float)args[6];
                    //~ Debug.Log("Cursor - id: " + s_id);

                    lock(cursorList) {
                        if (!cursorList.ContainsKey(s_id)) {

                            TuioCursor addCursor = new TuioCursor(s_id,-1,xpos,ypos);
                            frameCursors.Add(addCursor);

                        } else {
                            TuioCursor tcur = (TuioCursor)cursorList[s_id];
                            if (tcur==null) return;
                            if ((tcur.getX()!=xpos) || (tcur.getY()!=ypos) || (tcur.getXSpeed()!=xspeed) || (tcur.getYSpeed()!=yspeed) || (tcur.getMotionAccel()!=maccel)) {
                                TuioCursor updateCursor = new TuioCursor(s_id,tcur.getCursorID(),xpos,ypos);
                                updateCursor.update(xpos,ypos,xspeed,yspeed,maccel);
                                frameCursors.Add(updateCursor);
                            }
                        }
                    }
                //experimental contour data (by Rasmus H. - www.schnitzel.dk)
                  }else if (command == "contour") {

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

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

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

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

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

                        if(!cursorList.ContainsKey(s_id)){
                            //no cursor with that id so we return
                            return;
                        }else{
                            TuioCursor tcur = (TuioCursor)cursorList[s_id];
                            if (tcur==null) return;
                            TuioCursor updateCursor = new TuioCursor(tcur);
                            updateCursor.update(tcur, xpos, ypos, xwidth, yheight, heightp);
                            frameCursors.Add(updateCursor);
                        }
                    }

                } else if (command == "alive") {

                    newCursorList.Clear();
                    for (int i=1;i<args.Count;i++) {
                        // get the message content
                        long s_id = (int)args[i];
                        newCursorList.Add(s_id);
                        // reduce the cursor list to the lost cursors
                        if (aliveCursorList.Contains(s_id))
                            aliveCursorList.Remove(s_id);
                    }

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

                } else if (command=="fseq") {
                    int fseq = (int)args[1];
                    bool lateFrame = false;

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

                    if (!lateFrame) {

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

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

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

                                            if (cursorList.Count > 0) {

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

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

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

                                    addCursor = new TuioCursor(currentTime,tcur.getSessionID(),c_id,tcur.getX(),tcur.getY());
                                    cursorList.Add(addCursor.getSessionID(),addCursor);
                                }

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

                            default:

                                TuioCursor updateCursor = getTuioCursor(tcur.getSessionID());
                                if ( (tcur.getX()!=updateCursor.getX() && tcur.getXSpeed()==0) || (tcur.getY()!=updateCursor.getY() && tcur.getYSpeed()==0) ) {
                                    updateCursor.update(currentTime,tcur.getX(),tcur.getY());
                                }else{
                                    updateCursor.update(currentTime,tcur.getX(),tcur.getY(),tcur.getXSpeed(),tcur.getYSpeed(),tcur.getMotionAccel());
                                }
                                //rasmus edit
                                if(tcur.getContour() != null)
                                    updateCursor.update(updateCursor, tcur.getContour());

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

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

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

                        List<long> buffer = aliveCursorList;
                        aliveCursorList = newCursorList;
                        // recycling the List
                        newCursorList = buffer;
                    }
                    frameCursors.Clear();
                }

            }
        }
コード例 #40
0
ファイル: raComClient.cs プロジェクト: nuigroup/ccv-physics
        private void processMessage(OSCMessage message)
        {
            string address = message.Address;
            ArrayList args = message.Values;
            string command = (string)args[0];

            if (address == "/raCom/test") {
                if (command == "set") {

                    dataPoints = args;

                }
            }
        }
コード例 #41
0
ファイル: TuioClient.cs プロジェクト: lemoele/ColorSplat
        /**
         * <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();
                }

            }
        }
コード例 #42
0
 public static OSCMessage sourceMessage()
 {
     string localIP = Helper.getLocalIP();
     OSCMessage message = new OSCMessage("/tuio/2Dcur");
     message.Append("source");
     message.Append("surface@" + localIP);
     return message;
 }
コード例 #43
-1
/*