private void DrawSkeleton(Skeleton skeleton) { drawBone(skeleton.Joints[JointType.Head], skeleton.Joints[JointType.ShoulderCenter]); drawBone(skeleton.Joints[JointType.ShoulderCenter], skeleton.Joints[JointType.Spine]); drawBone(skeleton.Joints[JointType.ShoulderCenter], skeleton.Joints[JointType.ShoulderLeft]); drawBone(skeleton.Joints[JointType.ShoulderLeft], skeleton.Joints[JointType.ElbowLeft]); drawBone(skeleton.Joints[JointType.ElbowLeft], skeleton.Joints[JointType.WristLeft]); drawBone(skeleton.Joints[JointType.WristLeft], skeleton.Joints[JointType.HandLeft]); drawBone(skeleton.Joints[JointType.ShoulderCenter], skeleton.Joints[JointType.ShoulderRight]); drawBone(skeleton.Joints[JointType.ShoulderRight], skeleton.Joints[JointType.ElbowRight]); drawBone(skeleton.Joints[JointType.ElbowRight], skeleton.Joints[JointType.WristRight]); drawBone(skeleton.Joints[JointType.WristRight], skeleton.Joints[JointType.HandRight]); drawBone(skeleton.Joints[JointType.Spine], skeleton.Joints[JointType.HipCenter]); drawBone(skeleton.Joints[JointType.HipCenter], skeleton.Joints[JointType.HipLeft]); drawBone(skeleton.Joints[JointType.HipLeft], skeleton.Joints[JointType.KneeLeft]); drawBone(skeleton.Joints[JointType.KneeLeft], skeleton.Joints[JointType.AnkleLeft]); drawBone(skeleton.Joints[JointType.AnkleLeft], skeleton.Joints[JointType.FootLeft]); drawBone(skeleton.Joints[JointType.HipCenter], skeleton.Joints[JointType.HipRight]); drawBone(skeleton.Joints[JointType.HipRight], skeleton.Joints[JointType.KneeRight]); drawBone(skeleton.Joints[JointType.KneeRight], skeleton.Joints[JointType.AnkleRight]); drawBone(skeleton.Joints[JointType.AnkleRight], skeleton.Joints[JointType.FootRight]); // Draw head! Ellipse head = new Ellipse(); head.Height = 80; head.Width = 50; head.Fill = Brushes.Blue; head.Stroke = Brushes.Black; head.StrokeThickness = 2; Canvas.SetLeft(head, ScalePosition(skeleton.Joints[JointType.Head].Position).X - 25); Canvas.SetTop(head, ScalePosition(skeleton.Joints[JointType.Head].Position).Y - 40); UIElementExtensions.SetGroupID(head, 1); mainCanvas.Children.Add(head); }
private void ClearSkeleton() { var childrenToRemove = mainCanvas.Children.OfType <UIElement>(). Where(c => UIElementExtensions.GetGroupID(c) == 1); foreach (var child in childrenToRemove.ToArray()) { mainCanvas.Children.Remove(child); } //statusBar.Text += childrenToRemove.ToString(); }
private void DrawGameFrame(int numberOfBoxes) { int frame_width = 300; this.resultZones = new resultZone[numberOfBoxes]; for (int i = 0; i < numberOfBoxes; i++) { Line frameH = new Line(); frameH.Stroke = Brushes.LightGray; frameH.StrokeThickness = 3; // add horizontal lines frameH.X1 = mainCanvas.Width - frame_width; frameH.Y1 = (mainCanvas.Height / numberOfBoxes) * i; frameH.X2 = mainCanvas.Width; frameH.Y2 = (mainCanvas.Height / numberOfBoxes) * i; UIElementExtensions.SetGroupID(frameH, 2); mainCanvas.Children.Add(frameH); // create resultZone boundaries resultZones[i].X1 = (int)frameH.X1; resultZones[i].X2 = (int)frameH.X2; resultZones[i].Y1 = (int)((mainCanvas.Height / numberOfBoxes) * i); resultZones[i].Y2 = (int)((mainCanvas.Height / numberOfBoxes) * (i + 1)); resultZones[i].center.X = (int)((resultZones[i].X1 + resultZones[i].X2) / 2); resultZones[i].center.Y = (int)((resultZones[i].Y1 + resultZones[i].Y2) / 2); } Line frameV = new Line(); frameV.Stroke = Brushes.LightGray; frameV.StrokeThickness = 2; // add vertical line frameV.X1 = mainCanvas.Width - frame_width; frameV.Y1 = mainCanvas.Height; frameV.X2 = mainCanvas.Width - frame_width; frameV.Y2 = 0; UIElementExtensions.SetGroupID(frameV, 2); mainCanvas.Children.Add(frameV); }
// Drop zone fixed objects private void DrawDropZone() { // Create drop objects this.drop_object = new dropObject[NUM_DROP_OBJ]; //Red Circle drop_object[0].shape = new Ellipse(); drop_object[0].shape.Width = 140; drop_object[0].shape.Height = 140; drop_object[0].shape.Fill = Brushes.Red; //Green Square drop_object[1].shape = new Rectangle(); drop_object[1].shape.Width = 140; drop_object[1].shape.Height = 140; drop_object[1].shape.Fill = Brushes.Green; //Blue Triangle var triangle = new Polygon(); triangle.Points.Add(new Point(70, 30)); triangle.Points.Add(new Point(0, 150)); triangle.Points.Add(new Point(140, 150)); drop_object[2].shape = triangle; drop_object[2].shape.Fill = Brushes.Blue; // Place drop objects into drop zone //Set positions and properties //drop_object[0].shape.SetValue(Canvas.LeftProperty, 25.0); //left-align position value drop_object[0].shape.SetValue(Canvas.LeftProperty, mainCanvas.Width - (140.0 + 75.0)); drop_object[0].shape.SetValue(Canvas.TopProperty, 20.0); //drop_object[1].shape.SetValue(Canvas.LeftProperty, 25.0); //left-align position value drop_object[1].shape.SetValue(Canvas.LeftProperty, mainCanvas.Width - (140.0 + 75.0)); drop_object[1].shape.SetValue(Canvas.TopProperty, 200.0); //drop_object[2].shape.SetValue(Canvas.LeftProperty, 25.0); //left-align position value drop_object[2].shape.SetValue(Canvas.LeftProperty, mainCanvas.Width - (140.0 + 75.0)); drop_object[2].shape.SetValue(Canvas.TopProperty, 350.0); //Add to canvas UIElementExtensions.SetGroupID(drop_object[0].shape, 2); UIElementExtensions.SetGroupID(drop_object[1].shape, 2); UIElementExtensions.SetGroupID(drop_object[2].shape, 2); mainCanvas.Children.Add(drop_object[0].shape); mainCanvas.Children.Add(drop_object[1].shape); mainCanvas.Children.Add(drop_object[2].shape); }
// draw single bone private void drawBone(Joint trackedJoint1, Joint trackedJoint2) { Line bone = new Line(); bone.Stroke = Brushes.Blue; bone.StrokeThickness = 4; Point joint1 = this.ScalePosition(trackedJoint1.Position); bone.X1 = joint1.X; bone.Y1 = joint1.Y; Point joint2 = this.ScalePosition(trackedJoint2.Position); bone.X2 = joint2.X; bone.Y2 = joint2.Y; UIElementExtensions.SetGroupID(bone, 1); mainCanvas.Children.Add(bone); }