コード例 #1
0
        private void processTouchOnlyAddEvent(TuioCursor tcur)
        {
            lock (touchOnlyLock)
            {
                // Make sure touch point isn't already dragging something else
                if (!draggedObjects.Keys.Contains(tcur.getSessionID()))
                {
                    // Find the closest touched freeObject to this touch point
                    Vector2 tcurStartPos = new Vector2(tcur.getPath()[0].getScreenX(Settings.RESOLUTION_X), tcur.getPath()[0].getScreenY(Settings.RESOLUTION_Y));
                    float closestDistance = float.PositiveInfinity;
                    TuioObject closestTobj = null;

                    foreach (TuioObject tobj in freeObjects.Values)
                    //foreach (TuioObject tobj in tuioObjects.Values)
                    {
                        if (!draggedObjects.ContainsKey(tobj.getSessionID()))
                        {
                            Vector2 tobjPosition = new Vector2(tobj.getScreenX(Settings.RESOLUTION_X), tobj.getScreenY(Settings.RESOLUTION_Y));
                            float distance = Vector2.Distance(tcurStartPos, tobjPosition);
                            if (distance < closestDistance && distance < Settings.CIRCLE_RADIUS)
                            {
                                // Found a closer freeObject
                                closestDistance = distance;
                                closestTobj = tobj;
                            }
                        }
                    }
                    if (closestTobj != null)
                    {
                        Vector2 closestTobjPosition = new Vector2(closestTobj.getScreenX(Settings.RESOLUTION_X), closestTobj.getScreenY(Settings.RESOLUTION_Y));
                        draggedObjects.TryAdd(tcur.getSessionID(), closestTobj);
                        dragDiffVectors.TryAdd(tcur.getSessionID(), tcurStartPos - closestTobjPosition);
                        TuioObject outTobj;
                        freeObjects.TryRemove(closestTobj.getSymbolID(), out outTobj);
                        Debug.WriteLine("Grabbing  " + closestTobj.getSymbolID() + " with " + +tcur.getSessionID());
                    }
                }
            }
        }