Exemple #1
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 #2
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);
        }
Exemple #3
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 #4
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);
        }
        public void processTouchPoints(ReadOnlyTouchPointCollection touches, List<BlobPair> blobPairs, GameTime gameTime)
        {
            lastTouchPosition = touchPosition;
            int tagID = -1;
            int tagValue = -1;
            Boolean manipulatorControl = false;
            
            if (touches.Count == 2 && touches[0].IsFingerRecognized && touches[1].IsFingerRecognized)
            {
                manipulatorControl = true;
                Manipulator2D[] manipulators;
                manipulators = new Manipulator2D[] { 
                    new Manipulator2D(1, touches[1].X, touches[1].Y),
                    new Manipulator2D(3, touches[0].X, touches[0].Y)
                };

                manipulationProcessor.Pivot.X = touches[0].X;
                manipulationProcessor.Pivot.Y = touches[0].Y;

                manipulationProcessor.ProcessManipulators(Timestamp, manipulators);
            }
            else
            {
                manipulationProcessor.CompleteManipulation(Timestamp);
            }

            if (touches.Count >= 1)
            {
                for (int i = 0; i < touches.Count; i++)
                {
                    if (touches[i].IsTagRecognized)
                    {
                        tagID = touches[i].Id;
                        tagValue = (int)touches[i].Tag.Value;
                        break;
                    }
                }

                /*switch (tagValue)
                {
                    case 4:
                        viewManager.rotateToSide(4,t);
                        break;
                    case 5:
                        viewManager.rotateToSide(5,t);
                        break;
                    case 6:
                        viewManager.rotateToSide(6,t);
                        break;
                    case 7:
                        viewManager.rotateToSide(7,t);
                        break;
                    case 8:
                        viewManager.rotateToSide(8,t);
                        break;
                }
                */
                touchPosition = touches[0];
                //First time touch
                if (lastTouchPosition == null)
                {
                    Segment s;
                    s.P1 = game.GraphicsDevice.Viewport.Unproject(new Vector3(touchPosition.X, touchPosition.Y, 0f),
                        viewManager.Projection, viewManager.View, Matrix.Identity);
                    s.P2 = game.GraphicsDevice.Viewport.Unproject(new Vector3(touchPosition.X, touchPosition.Y, 1f),
                        viewManager.Projection, viewManager.View, Matrix.Identity);
                    float scalar;
                    Vector3 point;
                    var c = physics.BroadPhase.Intersect(ref s, out scalar, out point);

                    if (c != null && c is BodySkin && !(((SolidThing)((BodySkin)c).Owner).getThingType() == 1) && !(((SolidThing)((BodySkin)c).Owner).getThingType() == 2))
                    {
                        pickedObject = ((BodySkin)c).Owner;
                        orientation = pickedObject.Orientation;
                        pickedDistance = scalar;
                        pickedObject.IsActive = true;
                        pickedObjectOffset = pickedObject.Position - point;
                        pickedObject.IsWeightless = true;
                    }
                    //lastOrientation = touches.Count == 1 ? touches[0].Orientation : touches[1].Orientation;
                    lastOrientation = touches[0].Orientation;
                }
                else if (pickedObject != null)
                {
                    Segment s;
                    s.P1 = game.GraphicsDevice.Viewport.Unproject(new Vector3(touchPosition.X, touchPosition.Y, 0f),
                        viewManager.Projection, viewManager.View, Matrix.Identity);
                    s.P2 = game.GraphicsDevice.Viewport.Unproject(new Vector3(touchPosition.X, touchPosition.Y, 1f),
                        viewManager.Projection, viewManager.View, Matrix.Identity);

                    Vector3 diff, point;
                    Vector3.Subtract(ref s.P2, ref s.P1, out diff);
                    Vector3.Multiply(ref diff, pickedDistance, out diff);
                    Vector3.Add(ref s.P1, ref diff, out point);                    
                    pickedObject.SetVelocity(Vector3.Zero, Vector3.Zero);

                    if (!manipulatorControl)
                    {
                        Vector3 position = Vector3.Add(point, pickedObjectOffset);
                        pickedObject.SetWorld(position, orientation);
                    }
                    
                    pickedObject.IsActive = true;
                    SolidThing pickedObjectST = (SolidThing)pickedObject;

                    switch (tagValue)
                    {

                        //Pin a block
                        case 0:
                            pickedObject.Unfreeze();
                            pickedObject.Freeze();
                            break;
                        //unPin a block
                        case 1:
                            if (pickedObjectST.getThingType() == 1)
                            {
                        
                                break;
                            }
                            else
                            {
                                pickedObject.Unfreeze();
                                break;
                            }

                        //Rotate a block
                        case 2:
                            pickedObject.SetWorld(pickedObject.Position, Quaternion.CreateFromAxisAngle(new Vector3(0, 0, -1.0f), touchPosition.Orientation));
                            break;
                        //Move a block towards or away from camera
                        case 3:
                            TouchPoint tagPoint = touches.GetTouchPointFromId(tagID);
                            float deltaRotation = MathHelper.ToDegrees(lastOrientation) - MathHelper.ToDegrees(tagPoint.Orientation);

                            Vector3 direction = new Vector3(0, 0, 1.0f);
                            direction.Normalize();
                            pickedObject.SetWorld(Vector3.Add(pickedObject.Position, Vector3.Multiply(direction, deltaRotation * 0.03f)));
                            lastOrientation = tagPoint.Orientation;
                            break;
                            
                    }




                }
                else if (pickedObject != null)
                {
                    pickedObject.IsWeightless = false;
                    pickedObject = null;                    
                }
            }
            else if (pickedObject != null)
            {
                pickedObject.IsWeightless = false;
                pickedObject = null;
                touchPosition = null;
                lastTouchPosition = null;
                
            }
            else
            {
                touchPosition = null;
            }

        }