public TuioCursorEventArgs(TuioCursor cursor) { Cursor = cursor; }
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; } }
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; } }