OSCBundle
Inheritance: OSCPacket
Exemple #1
0
 public static OSCPacket Unpack(byte[] bytes, ref int start, int end, bool extendedMode = false)
 {
     if (bytes[start] == '#')
     {
         return(OSCBundle.Unpack(bytes, ref start, end, extendedMode));
     }
     else
     {
         return(OSCMessage.Unpack(bytes, ref start, extendedMode));
     }
 }
Exemple #2
0
 public static OSCPacket Unpack(byte[] bytes, ref int start, int end)
 {
     if (bytes[start] == '#')
     {
         return(OSCBundle.Unpack(bytes, ref start, end));
     }
     else
     {
         return(OSCMessage.Unpack(bytes, ref start));
     }
 }
        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);
        }
        /// <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);
        }
Exemple #5
0
        public static new OSCBundle Unpack(byte[] bytes, ref int start, int end)
        {
            OSCBundle bundle = new OSCBundle();

            string address = unpackString(bytes, ref start);
            if(!address.Equals(BUNDLE)) return null; // TODO

            long time = unpackLong(bytes, ref start);
            while(start < end)
            {
                int subEnd = unpackInt(bytes, ref start);
                bundle.Append(OSCPacket.Unpack(bytes, ref start, subEnd));

            }

            return bundle;
        }
Exemple #6
0
        public static new OSCBundle Unpack(byte[] bytes, ref int start, int end, bool extendedMode = false)
        {
            string address = unpackString(bytes, ref start);
            //Console.WriteLine("bundle: " + address);
            if(!address.Equals(BUNDLE)) return null; // TODO

            DateTime timestamp = unpackTimeTag(bytes, ref start);
            OSCBundle bundle = new OSCBundle(timestamp, extendedMode);

            while(start < end)
            {
                int length = unpackInt(bytes, ref start);
                int sub_end = start + length;
                bundle.Append(OSCPacket.Unpack(bytes, ref start, sub_end, extendedMode));
            }

            return bundle;
        }
        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);
        }
        public static new OSCBundle Unpack(byte[] bytes, ref int start, int end)
        {
            string address = unpackString(bytes, ref start);
            //Console.WriteLine("bundle: " + address);
            if(!address.Equals(BUNDLE)) return null; // TODO

            long timestamp = unpackLong(bytes, ref start);
            OSCBundle bundle = new OSCBundle(timestamp);

            while(start < end)
            {
                int length = unpackInt(bytes, ref start);
                int sub_end = start + length;
                //Console.WriteLine(bytes.Length +" "+ start+" "+length+" "+sub_end);
                bundle.Append(OSCPacket.Unpack(bytes, ref start, sub_end));

            }

            return bundle;
        }
Exemple #9
0
        public static new OSCBundle Unpack(byte[] bytes, ref int start, int end, bool extendedMode = false)
        {
            string address = unpackString(bytes, ref start);

            //Console.WriteLine("bundle: " + address);
            if (!address.Equals(BUNDLE))
            {
                return(null);                                    // TODO
            }
            DateTime  timestamp = unpackTimeTag(bytes, ref start);
            OSCBundle bundle    = new OSCBundle(timestamp, extendedMode);

            while (start < end)
            {
                int length  = unpackInt(bytes, ref start);
                int sub_end = start + length;
                bundle.Append(OSCPacket.Unpack(bytes, ref start, sub_end, extendedMode));
            }

            return(bundle);
        }
Exemple #10
0
        public static new OSCBundle Unpack(byte[] bytes, ref int start, int end)
        {
            OSCBundle bundle = new OSCBundle();

            string address = unpackString(bytes, ref start);

            if (!address.Equals(BUNDLE))
            {
                return(null);                                    // TODO
            }
            long time = unpackLong(bytes, ref start);

            while (start < end)
            {
                int subEnd = unpackInt(bytes, ref start);
                bundle.Append(OSCPacket.Unpack(bytes, ref start, subEnd));
            }


            return(bundle);
        }
Exemple #11
0
        public static new OSCBundle Unpack(byte[] bytes, ref int start, int end)
        {
            string address = unpackString(bytes, ref start);

            //Console.WriteLine("bundle: " + address);
            if (!address.Equals(BUNDLE))
            {
                return(null);                                    // TODO
            }
            long      timestamp = unpackLong(bytes, ref start);
            OSCBundle bundle    = new OSCBundle(timestamp);

            while (start < end)
            {
                int length  = unpackInt(bytes, ref start);
                int sub_end = start + length;
                //Console.WriteLine(bytes.Length +" "+ start+" "+length+" "+sub_end);
                bundle.Append(OSCPacket.Unpack(bytes, ref start, sub_end));
            }

            return(bundle);
        }
        private void sendEmptyCursorBundle()
        {
            OSCBundle bundle = new OSCBundle();

            OSCMessage msg1 = new OSCMessage("/tuio/2Dcur");
            msg1.Append("alive");

            bundle.Append(msg1);

            OSCMessage msg2 = new OSCMessage("/tuio/2Dcur");
            msg2.Append("fseq");
            msg2.Append(-1);

            bundle.Append(msg2);

            this.socket.Send(bundle);
        }
Exemple #13
0
        /// <summary>
        /// Sends a /tuio/2Dobj message
        /// The remote Host is specified in the appConfig
        /// The message is built according to TUIO 1.1 specifications (see http://www.tuio.org/?specification)
        /// </summary>
        /// <param name="contacts">Current acitve Contacts</param>
        /// <param name="previousContacts">Contacts from the previous frame</param>
        public void sendTUIO_2DObj(List<TouchPoint> contacts, ReadOnlyTouchPointCollection previousContacts)
        {
            //if (contacts.Count == 0) return;
            //#warning Properties about the device are now on the InteractiveSurfaceDevice class.
            //InteractiveSurface surface = Microsoft.Surface.Core.InteractiveSurfaceDevice.PrimarySurfaceDevice;
            //double width = InteractiveSurface.PrimarySurfaceDevice.Right - InteractiveSurface.PrimarySurfaceDevice.Left;
            //double height = InteractiveSurface.PrimarySurfaceDevice.Bottom - InteractiveSurface.PrimarySurfaceDevice.Top;
            InteractiveSurfaceDevice surface = InteractiveSurface.PrimarySurfaceDevice;
            double width = surface.Right - surface.Left;
            double height = surface.Bottom - surface.Top;

            OSCBundle objectBundle = new OSCBundle();
            OSCMessage sourceMessage = TUIO_2DObj.sourceMessage();
            objectBundle.Append(sourceMessage);

            OSCMessage aliveMessage = TUIO_2DObj.aliveMessage(contacts);
            objectBundle.Append(aliveMessage);

            for (int i = 0; i < contacts.Count; i++)
            {
                TouchPoint c = contacts[i];
                double x = (c.CenterX - surface.Left) / width;
                double y = (c.CenterY - surface.Top) / height;

                float angularVelocity = 0.0f;
                float angularAcceleration = 0.0f;

                if( previousContacts.Contains( c.Id ))
                {
                    computeAngularVelocity(c, previousContacts.GetTouchPointFromId(c.Id), out angularVelocity, out angularAcceleration);
                }

                float X = 0.0f;
                float Y = 0.0f;
                getVelocity(c.Id, out X, out Y); //, InteractiveSurface.PrimarySurfaceDevice.);
                float motionAcceleration = 0.0f;
                getMotionAcceleration(c.Id, out motionAcceleration, c.FrameTimestamp);

                //if (c.Tag.Value)
                {
                    OSCMessage setMessage = TUIO_2DObj.setMessage(c.Id, (int)c.Tag.Value, (float)x, (float)y, (float)c.Orientation, X, Y, angularVelocity, motionAcceleration, angularAcceleration);
                    objectBundle.Append(setMessage);
                }
                /*else if (c.Tag.Series)
                {
                    OSCMessage setMessage = TUIO_2DObj.setMessage(c.Id, (int)c.Tag.Series, (float)x, (float)y, (float)c.Orientation, X, Y, angularVelocity, motionAcceleration, angularAcceleration);
                    objectBundle.Append(setMessage);
                }*/

            }
            OSCMessage frameMessage = TUIO_2DObj.frameMessage(_Frame);
            objectBundle.Append(frameMessage);
            _Frame++;
            _OSCSender.Send(objectBundle);
        }
Exemple #14
0
        /// <summary>
        /// Sends a /tuio/2Dcur message
        /// The remote Host is specified in the appConfig
        /// The message is built according to TUIO 1.1 specifications (see http://www.tuio.org/?specification)
        /// </summary>
        /// <param name="contacts">Current active contacts</param>
        /// <param name="previousContacts">Contacts from the previous frame</param>
        public void sendTUIO_2DCur(List<TouchPoint> contacts, ReadOnlyTouchPointCollection previousContacts)
        {
            //if (contacts.Count == 0) return;
            //#warning Properties about the device are now on the InteractiveSurfaceDevice class.
            //InteractiveSurface surface = Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice;
            //double width = InteractiveSurface.PrimarySurfaceDevice.Right - InteractiveSurface.PrimarySurfaceDevice.Left;
            //double height = InteractiveSurface.PrimarySurfaceDevice.Bottom - InteractiveSurface.PrimarySurfaceDevice.Top;
            InteractiveSurfaceDevice surface = InteractiveSurface.PrimarySurfaceDevice;
            double width = surface.Right - surface.Left;
            double height = surface.Bottom - surface.Top;

            OSCBundle cursorBundle = new OSCBundle();
            OSCMessage sourceMessage = TUIO_2DCur.sourceMessage();
            cursorBundle.Append(sourceMessage);

            OSCMessage aliveMessage = TUIO_2DCur.aliveMessage(contacts);
            cursorBundle.Append(aliveMessage);

            for (int i = 0; i < contacts.Count; i++)
            {
                TouchPoint c = contacts[i];

                double x = (c.CenterX - surface.Left) / width;
                double y = (c.CenterY - surface.Top) / height;

                float X = 0.0f;
                float Y = 0.0f;
                getVelocity(c.Id, out X, out Y); //, surface);
                float motionAcceleration = 0.0f;
                getMotionAcceleration(c.Id, out motionAcceleration, c.FrameTimestamp);

                OSCMessage setMessage = TUIO_2DCur.setMessage(c.Id, (float)x, (float)y, X, Y, motionAcceleration);
                cursorBundle.Append(setMessage);
            }
            OSCMessage frameMessage = TUIO_2DCur.frameMessage(_Frame);
            cursorBundle.Append(frameMessage);
            _Frame++;
            _OSCSender.Send(cursorBundle);
        }
Exemple #15
0
        /// <summary>
        /// Sends a /tuio/2Dblb message
        /// The remote Host is specified in the appConfig
        /// The message is built according to TUIO 1.1 specifications (see http://www.tuio.org/?specification)
        /// </summary>
        /// <param name="contacts">Current active contacts</param>
        /// <param name="previousContacts">Contacts from the previous frame</param>
        public void sendTUIO_2DBlb(List<TouchPoint> contacts, ReadOnlyTouchPointCollection previousContacts)
        {
            //if (contacts.Count == 0) return;
            //#warning Properties about the device are now on the InteractiveSurfaceDevice class.
            //InteractiveSurface surface = Microsoft.Surface.Core.InteractiveSurface.PrimarySurfaceDevice;
            //double width = InteractiveSurface.PrimarySurfaceDevice.Right - InteractiveSurface.PrimarySurfaceDevice.Left;
            //double height = InteractiveSurface.PrimarySurfaceDevice.Bottom - InteractiveSurface.PrimarySurfaceDevice.Top;
            InteractiveSurfaceDevice surface = InteractiveSurface.PrimarySurfaceDevice;
            double width = surface.Right - surface.Left;
            double height = surface.Bottom - surface.Top;

            OSCBundle blobBundle = new OSCBundle();
            OSCMessage sourceMessage = TUIO_2DBlb.sourceMessage();
            blobBundle.Append(sourceMessage);

            OSCMessage aliveMessage = TUIO_2DBlb.aliveMessage(contacts);
            blobBundle.Append(aliveMessage);

            for (int i = 0; i < contacts.Count; i++)
            {
                TouchPoint c = contacts[i];
                double x = (c.CenterX - surface.Left) / width;
                double y = (c.CenterY - surface.Top) / height;
                double w = c.MajorAxis / surface.Width;
                double h = c.MinorAxis / surface.Height;
                double f = c.PhysicalArea / (surface.Width * surface.Height);

                float angularVelocity = 0.0f;
                float angularAcceleration = 0.0f;

                if (previousContacts.Contains(c.Id))
                {
                    computeAngularVelocity(c, previousContacts.GetTouchPointFromId(c.Id), out angularVelocity, out angularAcceleration);
                }

                float X = 0.0f;
                float Y = 0.0f;
                getVelocity(c.Id, out X, out Y); //, surface);

                float motionAcceleration = 0.0f;
                getMotionAcceleration(c.Id, out motionAcceleration, c.FrameTimestamp);

                OSCMessage setMessage = TUIO_2DBlb.setMessage(c.Id, (float)x, (float)y, (float)c.Orientation, (float)w, (float)h, (float)(w * h), X, Y, angularVelocity, motionAcceleration, angularAcceleration);
                blobBundle.Append(setMessage);
            }
            OSCMessage frameMessage = TUIO_2DBlb.frameMessage(_Frame);
            blobBundle.Append(frameMessage);
            _Frame++;
            _OSCSender.Send(blobBundle);
        }
        private void sendCursorBundle(ref OSCBundle bundle, int fseq)
        {
            OSCMessage msg = new OSCMessage("/tuio/2Dcur");
            msg.Append("fseq");
            msg.Append(fseq);

            bundle.Append(msg);

            this.socket.Send(bundle);
        }
        public MainWindow()
        {
            this.Loaded += MainWindow_Loaded;

            InitializeComponent();

            TouchInjector.InitializeTouchInjection();

            mainCanvas.Width = Screen.PrimaryScreen.Bounds.Width;
            mainCanvas.Height = Screen.PrimaryScreen.Bounds.Height;

            BitmapImage bi0 = new BitmapImage();
            bi0.BeginInit();
            bi0.UriSource = new Uri(Globals.ExecutablePath + "\\win_cursor_plus\\cursor0.png");
            bi0.EndInit();

            BitmapImage bi1 = new BitmapImage();
            bi1.BeginInit();
            bi1.UriSource = new Uri(Globals.ExecutablePath + "\\win_cursor_plus\\cursor1.png");
            bi1.EndInit();

            cursorImageIndex.Source = bi0;
            cursorImageIndex.Width = cursorImageIndex.Height = 100;

            cursorImageThumb.Source = bi0;
            cursorImageThumb.Width = cursorImageThumb.Height = 100;

            cursorImageIndex.Opacity = 0;
            cursorImageThumb.Opacity = 0;

            IPC ipc = new IPC("win_cursor_plus");

            ipc.MapFunction("exit", delegate(string messageBody)
            {
                ipc.Clear();
                Environment.Exit(0);
                return 1;
            });

            ipc.SetUDPCallback(delegate(string message)
            {
                if (message != "hide_cursor_index" || message != "hide_cursor_thumb")
                {
                    string[] xyStr = message.Split('!');

                    if (xyStr.Length == 5)
                    {
                        cursorIndexDown = false;
                        cursorThumbDown = false;

                        float x;
                        float y;
                        float z;
                        int down;

                        bool b0 = float.TryParse(xyStr[0], System.Globalization.NumberStyles.Float, null, out x);
                        bool b1 = float.TryParse(xyStr[1], System.Globalization.NumberStyles.Float, null, out y);
                        bool b2 = float.TryParse(xyStr[2], System.Globalization.NumberStyles.Float, null, out z);
                        bool b3 = int.TryParse(xyStr[3], System.Globalization.NumberStyles.Float, null, out down);

                        if (b0 && b1 && b2)
                            if (xyStr[4] == "index")
                            {
                                xCursorIndex = x * screenWidth / 1000;
                                if (xCursorIndex < 0)
                                    xCursorIndex = 0;
                                else if (xCursorIndex > screenWidth)
                                    xCursorIndex = screenWidth;

                                yCursorIndex = y * screenHeight / 1000;
                                if (yCursorIndex < 0)
                                    yCursorIndex = 0;
                                else if (yCursorIndex > screenHeight)
                                    yCursorIndex = screenHeight;

                                zCursorIndex = z;

                                showCursorIndex = true;
                                cursorIndexDown = down == 1;
                            }
                            else if (xyStr[4] == "thumb")
                            {
                                xCursorThumb = x * screenWidth / 1000;
                                if (xCursorThumb < 0)
                                    xCursorThumb = 0;
                                else if (xCursorThumb > screenWidth)
                                    xCursorThumb = screenWidth;

                                yCursorThumb = y * screenHeight / 1000;
                                if (yCursorThumb < 0)
                                    yCursorThumb = 0;
                                else if (yCursorThumb > screenHeight)
                                    yCursorThumb = screenHeight;

                                zCursorThumb = z;

                                showCursorThumb = true;
                                cursorIndexDown = true;
                                cursorThumbDown = true;
                            }
                    }
                    else if (message == "hide_cursor_index")
                        showCursorIndex = false;
                    else if (message == "hide_cursor_thumb")
                        showCursorThumb = false;
                    else if (xyStr.Length == 2 && xyStr[0] == "update")
                        updateNumNew = int.Parse(xyStr[1]);
                }

                return 1;
            });

            Timer timer = new Timer();
            timer.Interval = 20;
            timer.Tick += delegate(object o, EventArgs e)
            {
                ipc.Update();

                if (updateNumNew == updateNumOld && showCursorIndex)
                    return;

                updateNumOld = updateNumNew;

                if (!useTUIO && showCursorIndex)
                {
                    List<PointerTouchInfo> contacts = new List<PointerTouchInfo>();

                    if (cursorIndexDown && !cursorIndexDownOld)
                    {
                        PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorIndex, (int)yCursorIndex, 2, 1);
                        contact.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;
                        contacts.Add(contact);
                    }
                    else if (cursorIndexDown && cursorIndexDownOld)
                    {
                        PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorIndex, (int)yCursorIndex, 2, 1);
                        contact.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT;
                        contacts.Add(contact);
                    }
                    else if (!cursorIndexDown && cursorIndexDownOld)
                    {
                        PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorIndexOld, (int)yCursorIndexOld, 2, 1);
                        contact.PointerInfo.PointerFlags = PointerFlags.UP;
                        contacts.Add(contact);
                    }

                    if (cursorThumbDown && !cursorThumbDownOld)
                    {
                        PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorThumb, (int)yCursorThumb, 2, 2);
                        contact.PointerInfo.PointerFlags = PointerFlags.DOWN | PointerFlags.INRANGE | PointerFlags.INCONTACT;
                        contacts.Add(contact);
                    }
                    else if (cursorThumbDown && cursorThumbDownOld)
                    {
                        PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorThumb, (int)yCursorThumb, 2, 2);
                        contact.PointerInfo.PointerFlags = PointerFlags.UPDATE | PointerFlags.INRANGE | PointerFlags.INCONTACT;
                        contacts.Add(contact);
                    }
                    else if (!cursorThumbDown && cursorThumbDownOld)
                    {
                        PointerTouchInfo contact = MakePointerTouchInfo((int)xCursorThumbOld, (int)yCursorThumbOld, 2, 2);
                        contact.PointerInfo.PointerFlags = PointerFlags.UP;
                        contacts.Add(contact);
                    }

                    bool success = TouchInjector.InjectTouchInput(contacts.Count, contacts.ToArray());
                }
                else if (showCursorIndex)
                {
                    Object[] tCur0 = new Object[7];
                    Object[] tCur1 = new Object[7];
                    OSCBundle bundle = new OSCBundle();
                    bundle.Append(TUIO.TUIOFseq(tuioFSeq));
                    ArrayList TUIOSessions = new ArrayList();

                    if (cursorIndexDown)
                    {
                        bundle.Append(TUIO.TUIO2DcurExt(0, xCursorIndex / screenWidth, yCursorIndex / screenHeight, 0, 0, 0, 10, 10));
                        TUIOSessions.Add(0);
                    }
                    if (cursorThumbDown) {
                        bundle.Append(TUIO.TUIO2DcurExt(1, xCursorThumb / screenWidth, yCursorThumb / screenHeight, 0, 0, 0, 10, 10));
                        TUIOSessions.Add(1);
                    }
                    bundle.Append(TUIO.TUIOAlive(TUIOSessions));
                    transmitter.Send(bundle);
                    tuioFSeq++;
                }

                if (showCursorIndex)
                {
                    if (cursorIndexDown)
                        cursorImageIndex.Source = bi1;
                    else
                        cursorImageIndex.Source = bi0;

                    if (cursorImageIndex.Opacity < 1)
                        cursorImageIndex.Opacity += 0.2;

                    int cursorSize = (int)(zCursorIndex * 5 * (float)windowWidth / (float)screenWidth);
                    if (cursorSize > 150)
                        cursorSize = 150;
                    else if (cursorSize < 50)
                        cursorSize = 50;

                    cursorImageIndex.Width = cursorImageIndex.Height = cursorSize;

                    int xPosRemapped = (int)map_val(xCursorIndex, 0, screenWidth, 0, windowWidth);
                    int yPosRemapped = (int)map_val(yCursorIndex, 0, screenHeight, 0, windowHeight);

                    if (xPosRemapped < 0)
                        xPosRemapped = 0;
                    else if (xPosRemapped > screenWidth)
                        xPosRemapped = screenWidth;
                    if (yPosRemapped < 0)
                        yPosRemapped = 0;
                    else if (yPosRemapped > screenHeight)
                        yPosRemapped = screenHeight;

                    Canvas.SetLeft(cursorImageIndex, xPosRemapped - (cursorSize / 2));
                    Canvas.SetTop(cursorImageIndex, yPosRemapped - (cursorSize / 2));
                }
                else if (cursorImageIndex.Opacity > 0)
                    cursorImageIndex.Opacity -= 0.2;

                if (showCursorThumb)
                {
                    if (cursorThumbDown)
                        cursorImageThumb.Source = bi1;
                    else
                        cursorImageThumb.Source = bi0;

                    if (cursorImageThumb.Opacity < 1)
                        cursorImageThumb.Opacity += 0.2;

                    int cursorSize = (int)(zCursorThumb * 5 * (float)windowWidth / (float)screenWidth);
                    if (cursorSize > 150)
                        cursorSize = 150;
                    else if (cursorSize < 50)
                        cursorSize = 50;

                    cursorImageThumb.Width = cursorImageThumb.Height = cursorSize;

                    int xPosRemapped = (int)map_val(xCursorThumb, 0, screenWidth, 0, windowWidth);
                    int yPosRemapped = (int)map_val(yCursorThumb, 0, screenHeight, 0, windowHeight);

                    if (xPosRemapped < 0)
                        xPosRemapped = 0;
                    else if (xPosRemapped > screenWidth)
                        xPosRemapped = screenWidth;
                    if (yPosRemapped < 0)
                        yPosRemapped = 0;
                    else if (yPosRemapped > screenHeight)
                        yPosRemapped = screenHeight;

                    Canvas.SetLeft(cursorImageThumb, xPosRemapped - (cursorSize / 2));
                    Canvas.SetTop(cursorImageThumb, yPosRemapped - (cursorSize / 2));
                }
                else if (cursorImageThumb.Opacity > 0)
                    cursorImageThumb.Opacity -= 0.2;

                cursorIndexDownOld = cursorIndexDown;
                cursorThumbDownOld = cursorThumbDown;

                xCursorThumbOld = xCursorThumb;
                yCursorThumbOld = yCursorThumb;
                zCursorThumbOld = zCursorThumb;

                xCursorIndexOld = xCursorIndex;
                yCursorIndexOld = yCursorIndex;
                zCursorIndexOld = zCursorIndex;
            };

            timer.Start();
        }
Exemple #18
0
        /// <summary>
        /// Sends a /tuio/2Dobj message
        /// The remote Host is specified in the appConfig
        /// The message is built according to TUIO 1.1 specifications (see http://www.tuio.org/?specification)
        /// </summary>
        /// <param name="contacts">Current acitve Contacts</param>
        /// <param name="previousContacts">Contacts from the previous frame</param>
        public void sendTUIO_2DObj(List<Contact> contacts, ReadOnlyContactCollection previousContacts)
        {
            //if (contacts.Count == 0) return;
            InteractiveSurface surface = Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface;
            double width = surface.Right - surface.Left;
            double height = surface.Bottom - surface.Top;

            OSCBundle objectBundle = new OSCBundle();
            OSCMessage sourceMessage = TUIO_2DObj.sourceMessage();
            objectBundle.Append(sourceMessage);

            OSCMessage aliveMessage = TUIO_2DObj.aliveMessage(contacts);
            objectBundle.Append(aliveMessage);

            for (int i = 0; i < contacts.Count; i++)
            {
                Contact c = contacts[i];
                double x = (c.CenterX-surface.Left)/width;
                double y = (c.CenterY-surface.Top)/height;

                float angularVelocity = 0.0f;
                float angularAcceleration = 0.0f;

                if( previousContacts.Contains( c.Id ))
                {
                    computeAngularVelocity(c, previousContacts.GetContactFromId(c.Id), out angularVelocity, out angularAcceleration);
                }

                float X = 0.0f;
                float Y = 0.0f;
                getVelocity(c.Id, out X, out Y, surface);
                float motionAcceleration = 0.0f;
                getMotionAcceleration(c.Id, out motionAcceleration, c.FrameTimestamp);

                if (c.Tag.Type == TagType.Byte)
                {
                    OSCMessage setMessage = TUIO_2DObj.setMessage(c.Id, (int)c.Tag.Byte.Value, (float)x, (float)y, (float)c.Orientation, X, Y, angularVelocity, motionAcceleration, angularAcceleration);
                    objectBundle.Append(setMessage);
                }
                else if (c.Tag.Type == TagType.Identity)
                {
                    OSCMessage setMessage = TUIO_2DObj.setMessage(c.Id, (int)c.Tag.Identity.Value, (float)x, (float)y, (float)c.Orientation, X, Y, angularVelocity, motionAcceleration, angularAcceleration);
                    objectBundle.Append(setMessage);
                }

            }
            OSCMessage frameMessage = TUIO_2DObj.frameMessage(_Frame);
            objectBundle.Append(frameMessage);
            _Frame++;
            _OSCSender.Send(objectBundle);
        }
Exemple #19
0
        /// <summary>
        /// Sends a /tuio/2Dcur message
        /// The remote Host is specified in the appConfig
        /// The message is built according to TUIO 1.1 specifications (see http://www.tuio.org/?specification)
        /// </summary>
        /// <param name="contacts">Current active contacts</param>
        /// <param name="previousContacts">Contacts from the previous frame</param>
        public void sendTUIO_2DCur(List<Contact> contacts, ReadOnlyContactCollection previousContacts)
        {
            //if (contacts.Count == 0) return;
            InteractiveSurface surface = Microsoft.Surface.Core.InteractiveSurface.DefaultInteractiveSurface;
            double width = surface.Right - surface.Left;
            double height = surface.Bottom - surface.Top;

            OSCBundle cursorBundle = new OSCBundle();
            OSCMessage sourceMessage = TUIO_2DCur.sourceMessage();
            cursorBundle.Append(sourceMessage);

            OSCMessage aliveMessage = TUIO_2DCur.aliveMessage(contacts);
            cursorBundle.Append(aliveMessage);

            for (int i = 0; i < contacts.Count; i++)
            {
                Contact c = contacts[i];

                double x = (c.CenterX - surface.Left) / width;
                double y = (c.CenterY - surface.Top) / height;

                float X = 0.0f;
                float Y = 0.0f;
                getVelocity(c.Id, out X, out Y, surface);
                float motionAcceleration = 0.0f;
                getMotionAcceleration(c.Id, out motionAcceleration, c.FrameTimestamp);

                OSCMessage setMessage = TUIO_2DCur.setMessage(c.Id, (float)x, (float)y, X, Y, motionAcceleration);
                cursorBundle.Append(setMessage);

            }
            OSCMessage frameMessage = TUIO_2DCur.frameMessage(_Frame);
            cursorBundle.Append(frameMessage);
            _Frame++;
            _OSCSender.Send(cursorBundle);
        }
        private void startCursorBundle(ref OSCBundle bundle)
        {
            bundle = new OSCBundle();

            OSCMessage msg = new OSCMessage("/tuio/2Dcur");
            msg.Append("alive");
            foreach (TuioCursor tcur in this.cursorList)
                msg.Append(tcur.SessionID);

            bundle.Append(msg);
        }
        private void addCursorMessage(ref OSCBundle bundle, TuioCursor tcur)
        {
            OSCMessage msg = new OSCMessage("/tuio/2Dcur");
            msg.Append("set");
            msg.Append(tcur.SessionID);
            msg.Append(tcur.X);
            msg.Append(tcur.Y);
            msg.Append(tcur.XSpeed);
            msg.Append(tcur.YSpeed);
            msg.Append(tcur.MotionAccel);

            bundle.Append(msg);
        }
        private void SendStatusUpdate()
        {
            OSCBundle bundle = new OSCBundle();

            OSCMessage message = new OSCMessage("/tuio/2Dcur");
            message.Append("source");
            message.Append("MultiPoint TUIO");

            bundle.Append(message);
            //_oscTransmitter.Send(message);

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

            foreach (Cursor c in _cursors.Values)
            {
                message.Append(c.SessionID);
            }

            bundle.Append(message);
            //_oscTransmitter.Send(message);

            foreach (Cursor c in _cursors.Values)
            {
                float xPos = (float)((1 / (double)_windowWidth) * (c.Position.X - _windowLeft));
                float yPos = (float)((1 / (double)_windowHeight) * (c.Position.Y - _windowTop));

                message = new OSCMessage("/tuio/2Dcur");
                message.Append("set");
                message.Append(c.SessionID);
                message.Append(xPos);
                message.Append(yPos);
                message.Append(0.0f);
                message.Append(0.0f);
                message.Append(0.0f);

                bundle.Append(message as OSCPacket);
            }

            message = new OSCMessage("/tuio/2Dcur");
            message.Append("fseq");
            message.Append(_messageCounter);
            _messageCounter++;

            bundle.Append(message as OSCPacket);

            _oscTransmitter.Send(bundle);
        }
        public MainWindow()
        {
            this.Loaded += MainWindow_Loaded;

            InitializeComponent();

            mainCanvas.Width = Screen.PrimaryScreen.Bounds.Width;
            mainCanvas.Height = Screen.PrimaryScreen.Bounds.Height;

            BitmapImage bi0 = new BitmapImage();
            bi0.BeginInit();
            bi0.UriSource = new Uri(Globals.ExecutablePath + "\\win_cursor_plus\\cursor0.png");
            bi0.EndInit();

            BitmapImage bi1 = new BitmapImage();
            bi1.BeginInit();
            bi1.UriSource = new Uri(Globals.ExecutablePath + "\\win_cursor_plus\\cursor1.png");
            bi1.EndInit();

            cursorImageIndex.Source = bi0;
            cursorImageIndex.Width = cursorImageIndex.Height = 100;

            cursorImageThumb.Source = bi0;
            cursorImageThumb.Width = cursorImageThumb.Height = 100;

            cursorImageIndex.Opacity = 0;
            cursorImageThumb.Opacity = 0;

            IPC ipc = new IPC("win_cursor_plus");

            ipc.MapFunction("exit", delegate(string messageBody)
            {
                Environment.Exit(0);
                return 1;
            });

            ipc.SetUDPCallback(delegate(string message)
            {
                if (message != "hide_cursor_index" || message != "hide_cursor_thumb")
                {
                    string[] xyStr = message.Split('!');

                    if (xyStr.Length == 5)
                    {
                        cursorIndexDown = false;
                        cursorThumbDown = false;

                        float x;
                        float y;
                        float z;
                        int down;

                        bool b0 = float.TryParse(xyStr[0], out x);
                        bool b1 = float.TryParse(xyStr[1], out y);
                        bool b2 = float.TryParse(xyStr[2], out z);
                        bool b3 = int.TryParse(xyStr[3], out down);

                        if (b0 && b1 && b2)
                            if (xyStr[4] == "index")
                            {
                                xCursorIndex = x * screenWidth / 1000;
                                yCursorIndex = y * screenHeight / 1000;
                                zCursorIndex = z;
                                showCursorIndex = true;
                                cursorIndexDown = down == 1;
                            }
                            else if (xyStr[4] == "thumb")
                            {
                                xCursorThumb = x * screenWidth / 1000;
                                yCursorThumb = y * screenHeight / 1000;
                                zCursorThumb = z;
                                showCursorThumb = true;
                                cursorIndexDown = true;
                                cursorThumbDown = true;
                            }
                    }
                    else if (message == "hide_cursor_index")
                        showCursorIndex = false;
                    else if (message == "hide_cursor_thumb")
                        showCursorThumb = false;
                    else if (xyStr.Length == 2 && xyStr[0] == "update")
                        updateNumNew = int.Parse(xyStr[1]);
                }

                return 1;
            });

            Timer timer = new Timer();
            timer.Interval = 20;
            timer.Tick += delegate(object o, EventArgs e)
            {
                ipc.Update();

                if (updateNumNew == updateNumOld)
                    return;

                updateNumOld = updateNumNew;

                if (!useTUIO && showCursorIndex)
                {
                    System.Windows.Forms.Cursor.Position = new System.Drawing.Point((int)xCursorIndex, (int)yCursorIndex);

                    if (cursorIndexDown)
                        mouseDown();
                    else
                        mouseUp();
                }
                else if (showCursorIndex)
                {
                    Object[] tCur0 = new Object[7];
                    Object[] tCur1 = new Object[7];
                    OSCBundle bundle = new OSCBundle();
                    bundle.Append(TUIO.TUIOFseq(tuioFSeq));
                    ArrayList TUIOSessions = new ArrayList();

                    if (cursorIndexDown)
                    {
                        bundle.Append(TUIO.TUIO2DcurExt(0, xCursorIndex / screenWidth, yCursorIndex / screenHeight, 0, 0, 0, 10, 10));
                        TUIOSessions.Add(0);
                    }
                    if (cursorThumbDown) {
                        bundle.Append(TUIO.TUIO2DcurExt(1, xCursorThumb / screenWidth, yCursorThumb / screenHeight, 0, 0, 0, 10, 10));
                        TUIOSessions.Add(1);
                    }
                    bundle.Append(TUIO.TUIOAlive(TUIOSessions));
                    transmitter.Send(bundle);
                    tuioFSeq++;
                }

                if (showCursorIndex)
                {
                    if (cursorIndexDown)
                        cursorImageIndex.Source = bi1;
                    else
                        cursorImageIndex.Source = bi0;

                    if (cursorImageIndex.Opacity < 1)
                        cursorImageIndex.Opacity += 0.2;

                    int cursorSize = (int)(zCursorIndex * 5 * (float)windowWidth / (float)screenWidth);
                    if (cursorSize > 200)
                        cursorSize = 200;
                    else if (cursorSize < 50)
                        cursorSize = 50;

                    cursorImageIndex.Width = cursorImageIndex.Height = cursorSize;

                    int xPosRemapped = (int)map_val(xCursorIndex, 0, screenWidth, 0, windowWidth);
                    int yPosRemapped = (int)map_val(yCursorIndex, 0, screenHeight, 0, windowHeight);

                    Canvas.SetLeft(cursorImageIndex, xPosRemapped - (cursorSize / 2));
                    Canvas.SetTop(cursorImageIndex, yPosRemapped - (cursorSize / 2));
                }
                else if (cursorImageIndex.Opacity > 0)
                    cursorImageIndex.Opacity -= 0.2;

                if (showCursorThumb)
                {
                    if (cursorThumbDown)
                        cursorImageThumb.Source = bi1;
                    else
                        cursorImageThumb.Source = bi0;

                    if (cursorImageThumb.Opacity < 1)
                        cursorImageThumb.Opacity += 0.2;

                    int cursorSize = (int)(zCursorThumb * 5 * (float)windowWidth / (float)screenWidth);
                    if (cursorSize > 200)
                        cursorSize = 200;
                    else if (cursorSize < 50)
                        cursorSize = 50;

                    cursorImageThumb.Width = cursorImageThumb.Height = cursorSize;

                    int xPosRemapped = (int)map_val(xCursorThumb, 0, screenWidth, 0, windowWidth);
                    int yPosRemapped = (int)map_val(yCursorThumb, 0, screenHeight, 0, windowHeight);

                    Canvas.SetLeft(cursorImageThumb, xPosRemapped - (cursorSize / 2));
                    Canvas.SetTop(cursorImageThumb, yPosRemapped - (cursorSize / 2));
                }
                else if (cursorImageThumb.Opacity > 0)
                    cursorImageThumb.Opacity -= 0.2;

                cursorIndexDownOld = cursorIndexDown;
                cursorThumbDownOld = cursorThumbDown;

                xCursorThumbOld = xCursorThumb;
                yCursorThumbOld = yCursorThumb;
                zCursorThumbOld = zCursorThumb;

                xCursorIndexOld = xCursorIndex;
                yCursorIndexOld = yCursorIndex;
                zCursorIndexOld = zCursorIndex;
            };

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