/// <summary> /// This updates the Range drawing for a given tracker /// </summary> /// <param name="tracker"></param> public void updateRange(Tracker tracker) { double FOVAngle = tracker.FieldOfView.Value / 2; // We want to adjust the MinRange triangle, so we're using sin law if (tracker.MinRange.HasValue) { double leftX = (tracker.MinRange.Value * Math.Sin(Util.DEGREES_TO_RADIANS * FOVAngle)) / (Util.DEGREES_TO_RADIANS * (180.0 - FOVAngle - 90)); double leftXPixels = DrawingResources.ConvertFromMetersToPixelsX(leftX, MainWindow.SharedCanvas); double YPixels = DrawingResources.ConvertFromMetersToPixelsY(tracker.MinRange.Value, MainWindow.SharedCanvas); NearTriangle.Points.Clear(); NearTriangle.Points.Add(new Point(50, 15)); NearTriangle.Points.Add(new Point(50 + leftXPixels, 15 + YPixels)); NearTriangle.Points.Add(new Point(50 - leftXPixels, 15 + YPixels)); } // Adjusting the FarLine if (tracker.MaxRange.HasValue) { double leftX = (tracker.MaxRange.Value * Math.Sin(Util.DEGREES_TO_RADIANS * FOVAngle)) / (Util.DEGREES_TO_RADIANS * (180.0 - FOVAngle - 90)); double leftXPixels = DrawingResources.ConvertFromMetersToPixelsX(leftX, MainWindow.SharedCanvas); double YPixels = DrawingResources.ConvertFromMetersToPixelsY(tracker.MaxRange.Value, MainWindow.SharedCanvas); FarLine.X1 = 50 + leftXPixels; FarLine.Y1 = YPixels; FarLine.X2 = 50 - leftXPixels; FarLine.Y2 = YPixels; } }
/// <summary> /// This updates the FOV draw lines for a given tracker /// </summary> /// <param name="tracker"></param> public void updateFOV(Tracker tracker) { double FOVAngle = tracker.FieldOfView.Value / 2; double leftX = (tracker.MaxRange.Value * Math.Sin(Util.DEGREES_TO_RADIANS * FOVAngle)) / (Util.DEGREES_TO_RADIANS * (180.0 - FOVAngle - 90)); double leftXPixels = DrawingResources.ConvertFromMetersToPixelsX(leftX, MainWindow.SharedCanvas); double YPixels = DrawingResources.ConvertFromMetersToPixelsY(tracker.MaxRange.Value, MainWindow.SharedCanvas); RightLine.X2 = 50 + leftXPixels; RightLine.Y2 = YPixels; LeftLine.X2 = 50 - leftXPixels; LeftLine.Y2 = YPixels; //double topAngle = Util.NormalizeAngle(270 + FOVAngle); //double topX = Math.Cos(topAngle * Math.PI / 180); //double topY = Math.Sin(topAngle * Math.PI / 180); //Point newLeft = DrawingResources.ConvertPointToProperLength(new Point(topX, topY), DrawingResources.TRACKER_FOV_LENGTH); //LeftLine.X2 = newLeft.X; //LeftLine.Y2 = -newLeft.Y; //double bottomAngle = Util.NormalizeAngle(270 - FOVAngle); //double bottomX = Math.Cos(bottomAngle * Math.PI / 180); //double bottomY = Math.Sin(bottomAngle * Math.PI / 180); //Point newRight = DrawingResources.ConvertPointToProperLength(new Point(bottomX, bottomY), DrawingResources.TRACKER_FOV_LENGTH); //RightLine.X2 = newRight.X; //RightLine.Y2 = -newRight.Y; }
protected override void OnDrop(DragEventArgs e) { string DataType = e.Data.GetFormats(true)[0]; //if the object dropped is a tracker if (DataType == "trackerControl") { base.OnDrop(e); Point mouseLocation = e.GetPosition(sharedCanvas); // Grab the data we packed into the DataObject TrackerControl trackerControl = (TrackerControl)e.Data.GetData("trackerControl"); // Hide the Ghost and Text since a Drop has been made MainWindow.GhostBorder.Visibility = System.Windows.Visibility.Hidden; ghostTextBlock.Visibility = System.Windows.Visibility.Hidden; // Return the Opacity of the TrackerControl trackerControl.Opacity = 1; trackerControl.Tracker.Location = DrawingResources.ConvertFromDisplayCoordinatesToMeters(mouseLocation, sharedCanvas); // Check if the TrackerControl is already a child of Shared Canvas Point canvasBounds = new Point(DrawingResources.ConvertFromMetersToPixelsX(DrawingResources.ROOM_WIDTH, sharedCanvas), DrawingResources.ConvertFromMetersToPixelsY(DrawingResources.ROOM_HEIGHT, sharedCanvas)); if (!trackerControl.IsDescendantOf(SharedCanvas)) { trackerControl.formatForCanvas(); kinectWrapPanel.Children.Remove(trackerControl); SharedCanvas.Children.Add(trackerControl); if (trackerControl.Tracker.Orientation == null) { trackerControl.Tracker.Orientation = 270; } } // if the cursor is outside the canvas, put the tracker back in stackpanel. else if (!(mouseLocation.X < canvasBounds.X && mouseLocation.Y < canvasBounds.Y)) { trackerControl.Tracker.StopStreaming(); cleanUpKinectPersons(trackerControl.Tracker.Identifier); trackerControl.formatForStackPanel(); SharedCanvas.Children.Remove(trackerControl); kinectWrapPanel.Children.Add(trackerControl); } } //if the objet dropped is a device. else if (DataType == "deviceControl") { base.OnDrop(e); Point mouseLocation = e.GetPosition(sharedCanvas); // Grab the data we packed into the DataObject DeviceControl deviceControl = (DeviceControl)e.Data.GetData("deviceControl"); // Hide the Ghost and Text since a Drop has been made MainWindow.GhostBorder.Visibility = System.Windows.Visibility.Hidden; ghostTextBlock.Visibility = System.Windows.Visibility.Hidden; // Return the Opacity of the DeviceControl deviceControl.Opacity = 1; PairableDevice device = deviceControl.PairableDevice; IADevice iaDevice = deviceControl.IADevice; IARequest request = new IARequest(Routes.SetLocationRoute); request.Parameters["identifier"] = iaDevice.Name; Point canvasBounds = new Point(DrawingResources.ConvertFromMetersToPixelsX(DrawingResources.ROOM_WIDTH, sharedCanvas), DrawingResources.ConvertFromMetersToPixelsY(DrawingResources.ROOM_HEIGHT, sharedCanvas)); //if the dragged device is a pairable device (i.e iPad) if (!iaDevice.SupportedRoutes.Contains(Routes.GetLocationRoute)) { Point mouseLocationOnCanvas = mouseLocation = DrawingResources.ConvertFromDisplayCoordinatesToMeters(mouseLocation, sharedCanvas); bool pairedToNewDevice = false; foreach (KeyValuePair <PairablePerson, PersonControl> keyPair in PersonControlDictionary) { Point personLocation = keyPair.Key.Location.Value; double distance = Math.Sqrt(Math.Pow(mouseLocationOnCanvas.X - personLocation.X, 2) + Math.Pow(mouseLocationOnCanvas.Y - personLocation.Y, 2)); //if the mouse drop is close to a person, pair the device with that person. if (distance < 0.3 && (device.HeldByPersonIdentifier == keyPair.Key.Identifier || keyPair.Key.PairingState != PairingState.Paired)) { if (device.PairingState == PairingState.Paired || device.PairingState == PairingState.PairedButOccluded) { kinectManager.PairingRecognizer.UnpairDevice(device); } kinectManager.PairingRecognizer.Pair(device, keyPair.Key); pairedToNewDevice = true; break; } } //if the mouse drop is not close to a person then unpair the device. if (!pairedToNewDevice) { kinectManager.PairingRecognizer.UnpairDevice(device); } } //if the dragged device is not a pairable device (i.e table-top) else if (iaDevice.SupportedRoutes.Contains(Routes.GetLocationRoute)) { if (mouseLocation.X < canvasBounds.X && mouseLocation.Y < canvasBounds.Y) { // Dropped within Canvas, so we want to place it on the canvas device.Location = DrawingResources.ConvertFromDisplayCoordinatesToMeters(mouseLocation, sharedCanvas); request.SetBodyWith(new IntermediatePoint(device.Location.Value)); } else { // Not dropped within Canvas, so we want to put it back on the stack panel device.Location = null; request.SetBodyWith(null); } // Send a request to the Device that their location has changed kinectManager.IntAirAct.SendRequest(request, iaDevice); } } }
protected override void OnDragOver(DragEventArgs e) { base.OnDragOver(e); Point mouseLocation = e.GetPosition(sharedCanvas); Point canvasBounds = new Point(DrawingResources.ConvertFromMetersToPixelsX(DrawingResources.ROOM_WIDTH, sharedCanvas), DrawingResources.ConvertFromMetersToPixelsY(DrawingResources.ROOM_HEIGHT, sharedCanvas)); // If the Cursor is within the Canvas if (mouseLocation.X < canvasBounds.X && mouseLocation.Y < canvasBounds.Y) { // Ensure the Ghost and Text are Visible while dragging MainWindow.GhostBorder.Visibility = System.Windows.Visibility.Visible; ghostTextBlock.Visibility = System.Windows.Visibility.Visible; // Relocate Ghost Canvas.SetLeft(MainWindow.GhostBorder, mouseLocation.X - (MainWindow.GhostBorder.Width / 2)); Canvas.SetTop(MainWindow.GhostBorder, mouseLocation.Y - (MainWindow.GhostBorder.Height / 2)); // Update Location Text Point p = DrawingResources.ConvertFromDisplayCoordinatesToMeters(mouseLocation, sharedCanvas); ghostTextBlock.Text = "(" + Math.Round(p.X, 1) + ", " + Math.Round(p.Y, 1) + ")"; // Relocate Ghost Text Canvas.SetLeft(ghostTextBlock, mouseLocation.X - (MainWindow.GhostBorder.Width / 2)); Canvas.SetTop(ghostTextBlock, mouseLocation.Y - (MainWindow.GhostBorder.Height / 2)); } // If the Cursor is not within the Canvas else { // Hide the Ghost and Text because it would be drawn off the Canvas MainWindow.GhostBorder.Visibility = System.Windows.Visibility.Hidden; ghostTextBlock.Visibility = System.Windows.Visibility.Hidden; } }