示例#1
0
        public void ProcessMessage(OscMessage message)
        {
            if (message.Address != "/tuio/2Dblb") return;

            var command = message.Data[0].ToString();
            switch (command)
            {
                case "set":
                    if (message.Data.Count < 13) return;

                    var id = (int)message.Data[1];
                    var xPos = (float)message.Data[2];
                    var yPos = (float)message.Data[3];
                    var angle = (float)message.Data[4];
                    var width = (float)message.Data[5];
                    var height = (float)message.Data[6];
                    var area = (float)message.Data[7];
                    var velocityX = (float)message.Data[8];
                    var velocityY = (float)message.Data[9];
                    var rotationVelocity = (float)message.Data[10];
                    var acceleration = (float)message.Data[11];
                    var rotationAcceleration = (float)message.Data[12];

                    TuioBlob blob;
                    if (!blobs.TryGetValue(id, out blob)) blob = new TuioBlob(id);
                    blob.Update(xPos, yPos, angle, width, height, area, velocityX, velocityY, rotationVelocity, acceleration, rotationAcceleration);
                    updatedBlobs.Add(blob);
                    break;
                case "alive":
                    var total = message.Data.Count;
                    for (var i = 1; i < total; i++)
                    {
                        addedBlobs.Add((int)message.Data[i]);
                    }
                    foreach (KeyValuePair<int, TuioBlob> value in blobs)
                    {
                        if (!addedBlobs.Contains(value.Key))
                        {
                            removedBlobs.Add(value.Key);
                        }
                        addedBlobs.Remove(value.Key);
                    }
                    break;
                case "fseq":
                    if (message.Data.Count < 2) return;
                    FrameNumber = (int)message.Data[1];
                    var count = updatedBlobs.Count;
                    for (var i = 0; i < count; i++)
                    {
                        var updatedBlob = updatedBlobs[i];
                        if (addedBlobs.Contains(updatedBlob.Id) && !blobs.ContainsKey(updatedBlob.Id))
                        {
                            blobs.Add(updatedBlob.Id, updatedBlob);
                            if (BlobAdded != null) BlobAdded(this, new TuioBlobEventArgs(updatedBlob));
                        }
                        else
                        {
                            if (BlobUpdated != null) BlobUpdated(this, new TuioBlobEventArgs(updatedBlob));
                        }
                    }
                    count = removedBlobs.Count;
                    for (var i = 0; i < count; i++)
                    {
                        var blobId = removedBlobs[i];
                        blob = blobs[blobId];
                        blobs.Remove(blobId);
                        if (BlobRemoved != null) BlobRemoved(this, new TuioBlobEventArgs(blob));
                    }

                    addedBlobs.Clear();
                    removedBlobs.Clear();
                    updatedBlobs.Clear();
                    break;
            }
        }
示例#2
0
        public void ProcessMessage(OscMessage message)
        {
            if (message.Address != "/tuio/2Dobj") return;

            var command = message.Data[0].ToString();
            switch (command)
            {
                case "set":
                    if (message.Data.Count < 11) return;

                    var id = (int)message.Data[1];
                    var classId = (int)message.Data[2];
                    var xPos = (float)message.Data[3];
                    var yPos = (float)message.Data[4];
                    var angle = (float)message.Data[5];
                    var velocityX = (float)message.Data[6];
                    var velocityY = (float)message.Data[7];
                    var rotationVelocity = (float)message.Data[8];
                    var acceleration = (float)message.Data[9];
                    var rotationAcceleration = (float)message.Data[10];

                    TuioObject obj;
                    if (!objects.TryGetValue(id, out obj)) obj = new TuioObject(id, classId);
                    obj.Update(xPos, yPos, angle, velocityX, velocityY, rotationVelocity, acceleration, rotationAcceleration);
                    updatedObjects.Add(obj);
                    break;
                case "alive":
                    var total = message.Data.Count;
                    for (var i = 1; i < total; i++)
                    {
                        addedObjects.Add((int)message.Data[i]);
                    }
                    foreach (KeyValuePair<int, TuioObject> value in objects)
                    {
                        if (!addedObjects.Contains(value.Key))
                        {
                            removedObjects.Add(value.Key);
                        }
                        addedObjects.Remove(value.Key);
                    }
                    break;
                case "fseq":
                    if (message.Data.Count < 2) return;
                    FrameNumber = (int)message.Data[1];
                    var count = updatedObjects.Count;
                    for (var i = 0; i < count; i++)
                    {
                        var updatedObject = updatedObjects[i];
                        if (addedObjects.Contains(updatedObject.Id) && !objects.ContainsKey(updatedObject.Id))
                        {
                            objects.Add(updatedObject.Id, updatedObject);
                            if (ObjectAdded != null) ObjectAdded(this, new TuioObjectEventArgs(updatedObject));
                        }
                        else
                        {
                            if (ObjectUpdated != null) ObjectUpdated(this, new TuioObjectEventArgs(updatedObject));
                        }
                    }
                    count = removedObjects.Count;
                    for (var i = 0; i < count; i++)
                    {
                        var objectId = removedObjects[i];
                        obj = objects[objectId];
                        objects.Remove(objectId);
                        if (ObjectRemoved != null) ObjectRemoved(this, new TuioObjectEventArgs(obj));
                    }

                    addedObjects.Clear();
                    removedObjects.Clear();
                    updatedObjects.Clear();
                    break;
            }
        }
示例#3
0
        public static OscMessage FromByteArray(byte[] data, ref int start)
        {
            string address = ValueFromByteArray<string>(data, ref start);
            OscMessage message = new OscMessage(address);

            char[] tags = ValueFromByteArray<string>(data, ref start).ToCharArray();
            foreach (char tag in tags)
            {
                object value;
                switch (tag)
                {
                    case TAG_DEFAULT:
                        continue;

                    case TAG_INTEGER:
                        value = ValueFromByteArray<int>(data, ref start);
                        break;

                    case TAG_LONG:
                        value = ValueFromByteArray<long>(data, ref start);
                        break;

                    case TAG_FLOAT:
                        value = ValueFromByteArray<float>(data, ref start);
                        break;

                    case TAG_DOUBLE:
                        value = ValueFromByteArray<double>(data, ref start);
                        break;

                    case TAG_STRING:
                    case TAG_SYMBOL:
                        value = ValueFromByteArray<string>(data, ref start);
                        break;

                    case TAG_BLOB:
                        value = ValueFromByteArray<byte[]>(data, ref start);
                        break;

                    case TAG_TIME:
                        value = ValueFromByteArray<OscTimeTag>(data, ref start);
                        break;

                    case TAG_CHARACTER:
                        value = ValueFromByteArray<char>(data, ref start);
                        break;

                    case TAG_TRUE:
                        value = true;
                        break;

                    case TAG_FALSE:
                        value = false;
                        break;

                    case TAG_NIL:
                        value = null;
                        break;

                    case TAG_INFINITY:
                        value = float.PositiveInfinity;
                        break;

                    default:
                        continue;
                }

                message.Append(value);
            }

            return message;
        }
 public OscMessageReceivedEventArgs(OscMessage message)
 {
     Message = message;
 }
示例#5
0
        private void processMessage(OscMessage message)
        {
            if (message.Data.Count == 0) return;

            var count = processors.Count;
            for (var i = 0; i < count; i++)
            {
                processors[i].ProcessMessage(message);
            }
        }
示例#6
0
        public void ProcessMessage(OscMessage message)
        {
            if (message.Address != "/tuio/2Dcur") return;

            var command = message.Data[0].ToString();
            switch (command)
            {
                case "set":
                    if (message.Data.Count < 7) return;

                    var id = (int)message.Data[1];
                    var xPos = (float)message.Data[2];
                    var yPos = (float)message.Data[3];
                    var velocityX = (float)message.Data[4];
                    var velocityY = (float)message.Data[5];
                    var acceleration = (float)message.Data[6];

                    TuioCursor cursor;
                    if (!cursors.TryGetValue(id, out cursor)) cursor = new TuioCursor(id);
                    cursor.Update(xPos, yPos, velocityX, velocityY, acceleration);
                    updatedCursors.Add(cursor);
                    break;
                case "alive":
                    var total = message.Data.Count;
                    for (var i = 1; i < total; i++)
                    {
                        addedCursors.Add((int)message.Data[i]);
                    }
                    foreach (KeyValuePair<int, TuioCursor> value in cursors)
                    {
                        if (!addedCursors.Contains(value.Key))
                        {
                            removedCursors.Add(value.Key);
                        }
                        addedCursors.Remove(value.Key);
                    }
                    break;
                case "fseq":
                    if (message.Data.Count < 2) return;
                    FrameNumber = (int)message.Data[1];
                    var count = updatedCursors.Count;
                    for (var i = 0; i < count; i++)
                    {
                        var updatedCursor = updatedCursors[i];
                        if (addedCursors.Contains(updatedCursor.Id) && !cursors.ContainsKey(updatedCursor.Id))
                        {
                            cursors.Add(updatedCursor.Id, updatedCursor);
                            if (CursorAdded != null) CursorAdded(this, new TuioCursorEventArgs(updatedCursor));
                        }
                        else
                        {
                            if (CursorUpdated != null) CursorUpdated(this, new TuioCursorEventArgs(updatedCursor));
                        }
                    }
                    count = removedCursors.Count;
                    for (var i = 0; i < count; i++)
                    {
                        var cursorId = removedCursors[i];
                        cursor = cursors[cursorId];
                        cursors.Remove(cursorId);
                        if (CursorRemoved != null) CursorRemoved(this, new TuioCursorEventArgs(cursor));
                    }

                    addedCursors.Clear();
                    removedCursors.Clear();
                    updatedCursors.Clear();
                    break;
            }
        }
示例#7
0
        private void parseOscMessage(OscMessage message)
        {
            switch (message.Address)
            {
                case "/tuio/2Dcur":
                    if (message.Data.Count == 0) return;
                    var command = message.Data[0].ToString();
                    switch (command)
                    {
                        case "set":
                            if (message.Data.Count < 4) return;
                            var id = (int)message.Data[1];
                            var xPos = (float)message.Data[2];
                            var yPos = (float)message.Data[3];
                            TuioCursor cursor;
                            if (!cursors.TryGetValue(id, out cursor))
                            {
                                cursor = new TuioCursor(id);
                            }
                            var deltaX = cursor.X - xPos;
                            var deltaY = cursor.Y - yPos;
                            if (deltaX*deltaX + deltaY*deltaY >= movementThresholdSq)
                            {
                                cursor.Update(xPos, yPos);
                                updatedCursors.Add(cursor);
                            }
                            break;
                        case "alive":
                            var aliveCursors = new List<int>();
                            for (var i = 1; i < message.Data.Count; i++)
                            {
                                aliveCursors.Add((int)message.Data[i]);
                            }
                            foreach (KeyValuePair<int, TuioCursor> value in cursors)
                            {
                                if (!aliveCursors.Contains(value.Key))
                                {
                                    removedCursors.Add(value.Key);
                                }
                                aliveCursors.Remove(value.Key);
                            }
                            addedCursors.AddRange(aliveCursors);
                            break;
                        case "fseq":
                            if (message.Data.Count < 2) return;
                            FrameNumber = (int)message.Data[1];
                            foreach (var updatedCursor in updatedCursors)
                            {
                                if (addedCursors.Contains(updatedCursor.Id) && !cursors.ContainsKey(updatedCursor.Id))
                                {
                                    cursors.Add(updatedCursor.Id, updatedCursor);
                                    if (CursorAdded != null) CursorAdded(this, new TuioCursorEventArgs(updatedCursor));
                                } else
                                {
                                    if (CursorUpdated != null) CursorUpdated(this, new TuioCursorEventArgs(updatedCursor));
                                }
                            }
                            foreach (var cursorId in removedCursors)
                            {
                                cursor = cursors[cursorId];
                                cursors.Remove(cursorId);
                                if (CursorRemoved != null) CursorRemoved(this, new TuioCursorEventArgs(cursor));
                            }

                            addedCursors.Clear();
                            removedCursors.Clear();
                            updatedCursors.Clear();
                            break;
                    }
                    break;
            }
        }
示例#8
0
 private void onMessageReceived(OscMessage message)
 {
     if (messageReceivedInvoker != null) messageReceivedInvoker(this, new OscMessageReceivedEventArgs(message));
 }