/// <summary> /// Draws a skeleton's bones and joints /// </summary> /// <param name="skeleton">skeleton to draw</param> /// <param name="drawingContext">drawing context to draw to</param> private void DrawBonesAndJoints(Skeleton skeleton, DrawingContext drawingContext, MrSpooks s) { MrSpooks spooks = s; // Render Torso spooks.boneEnhance(SkeletonPointToScreen(skeleton.Joints[JointType.Head].Position), SkeletonPointToScreen(skeleton.Joints[JointType.ShoulderCenter].Position), drawingContext, JointType.Head, JointType.ShoulderCenter); spooks.boneEnhance(SkeletonPointToScreen(skeleton.Joints[JointType.ShoulderCenter].Position), SkeletonPointToScreen(skeleton.Joints[JointType.ShoulderLeft].Position), drawingContext, JointType.ShoulderCenter, JointType.ShoulderLeft); spooks.boneEnhance(SkeletonPointToScreen(skeleton.Joints[JointType.ShoulderCenter].Position), SkeletonPointToScreen(skeleton.Joints[JointType.ShoulderRight].Position), drawingContext, JointType.ShoulderCenter, JointType.ShoulderRight); spooks.boneEnhance(SkeletonPointToScreen(skeleton.Joints[JointType.ShoulderCenter].Position), SkeletonPointToScreen(skeleton.Joints[JointType.Spine].Position), drawingContext, JointType.ShoulderCenter, JointType.Spine); spooks.boneEnhance(SkeletonPointToScreen(skeleton.Joints[JointType.Spine].Position), SkeletonPointToScreen(skeleton.Joints[JointType.HipCenter].Position), drawingContext, JointType.Spine, JointType.HipCenter); spooks.boneEnhance(SkeletonPointToScreen(skeleton.Joints[JointType.HipCenter].Position), SkeletonPointToScreen(skeleton.Joints[JointType.HipLeft].Position), drawingContext, JointType.HipCenter, JointType.HipLeft); spooks.boneEnhance(SkeletonPointToScreen(skeleton.Joints[JointType.HipCenter].Position), SkeletonPointToScreen(skeleton.Joints[JointType.HipRight].Position), drawingContext, JointType.HipCenter, JointType.HipRight); // Left Arm spooks.boneEnhance(SkeletonPointToScreen(skeleton.Joints[JointType.ShoulderLeft].Position), SkeletonPointToScreen(skeleton.Joints[JointType.ElbowLeft].Position), drawingContext, JointType.ShoulderLeft, JointType.ElbowLeft); spooks.boneEnhance(SkeletonPointToScreen(skeleton.Joints[JointType.ElbowLeft].Position), SkeletonPointToScreen(skeleton.Joints[JointType.WristLeft].Position), drawingContext, JointType.ElbowLeft, JointType.WristLeft); spooks.boneEnhance(SkeletonPointToScreen(skeleton.Joints[JointType.WristLeft].Position), SkeletonPointToScreen(skeleton.Joints[JointType.HandLeft].Position), drawingContext, JointType.WristLeft, JointType.HandLeft); // Right Arm spooks.boneEnhance(SkeletonPointToScreen(skeleton.Joints[JointType.ShoulderRight].Position), SkeletonPointToScreen(skeleton.Joints[JointType.ElbowRight].Position), drawingContext, JointType.ShoulderRight, JointType.ElbowRight); spooks.boneEnhance(SkeletonPointToScreen(skeleton.Joints[JointType.ElbowRight].Position), SkeletonPointToScreen(skeleton.Joints[JointType.WristRight].Position), drawingContext, JointType.ElbowRight, JointType.WristRight); spooks.boneEnhance(SkeletonPointToScreen(skeleton.Joints[JointType.WristRight].Position), SkeletonPointToScreen(skeleton.Joints[JointType.HandRight].Position), drawingContext, JointType.WristRight, JointType.HandRight); // Left Leg spooks.boneEnhance(SkeletonPointToScreen(skeleton.Joints[JointType.HipLeft].Position), SkeletonPointToScreen(skeleton.Joints[JointType.KneeLeft].Position), drawingContext, JointType.HipLeft, JointType.KneeLeft); spooks.boneEnhance(SkeletonPointToScreen(skeleton.Joints[JointType.KneeLeft].Position), SkeletonPointToScreen(skeleton.Joints[JointType.AnkleLeft].Position), drawingContext, JointType.KneeLeft, JointType.AnkleLeft); spooks.boneEnhance(SkeletonPointToScreen(skeleton.Joints[JointType.AnkleLeft].Position), SkeletonPointToScreen(skeleton.Joints[JointType.FootLeft].Position), drawingContext, JointType.AnkleLeft, JointType.FootLeft); // Right Leg spooks.boneEnhance(SkeletonPointToScreen(skeleton.Joints[JointType.HipRight].Position), SkeletonPointToScreen(skeleton.Joints[JointType.KneeRight].Position), drawingContext, JointType.HipRight, JointType.KneeRight); spooks.boneEnhance(SkeletonPointToScreen(skeleton.Joints[JointType.KneeRight].Position), SkeletonPointToScreen(skeleton.Joints[JointType.AnkleRight].Position), drawingContext, JointType.KneeRight, JointType.AnkleRight); spooks.boneEnhance(SkeletonPointToScreen(skeleton.Joints[JointType.AnkleRight].Position), SkeletonPointToScreen(skeleton.Joints[JointType.FootRight].Position), drawingContext, JointType.AnkleRight, JointType.FootRight); /*// Render Torso * spooks.boneShadow(SkeletonPointToScreen(skeleton.Joints[JointType.Head].Position), SkeletonPointToScreen(skeleton.Joints[JointType.ShoulderCenter].Position), drawingContext); * spooks.boneShadow(SkeletonPointToScreen(skeleton.Joints[JointType.ShoulderCenter].Position), SkeletonPointToScreen(skeleton.Joints[JointType.ShoulderLeft].Position), drawingContext); * spooks.boneShadow(SkeletonPointToScreen(skeleton.Joints[JointType.ShoulderCenter].Position), SkeletonPointToScreen(skeleton.Joints[JointType.ShoulderRight].Position), drawingContext); * spooks.boneShadow(SkeletonPointToScreen(skeleton.Joints[JointType.ShoulderCenter].Position), SkeletonPointToScreen(skeleton.Joints[JointType.Spine].Position), drawingContext); * spooks.boneShadow(SkeletonPointToScreen(skeleton.Joints[JointType.Spine].Position), SkeletonPointToScreen(skeleton.Joints[JointType.HipCenter].Position), drawingContext); * spooks.boneShadow(SkeletonPointToScreen(skeleton.Joints[JointType.HipCenter].Position), SkeletonPointToScreen(skeleton.Joints[JointType.HipLeft].Position), drawingContext); * spooks.boneShadow(SkeletonPointToScreen(skeleton.Joints[JointType.HipCenter].Position), SkeletonPointToScreen(skeleton.Joints[JointType.HipRight].Position), drawingContext); * * * // Left Arm * spooks.boneShadow(SkeletonPointToScreen(skeleton.Joints[JointType.ShoulderLeft].Position), SkeletonPointToScreen(skeleton.Joints[JointType.ElbowLeft].Position), drawingContext); * spooks.boneShadow(SkeletonPointToScreen(skeleton.Joints[JointType.ElbowLeft].Position), SkeletonPointToScreen(skeleton.Joints[JointType.WristLeft].Position), drawingContext); * spooks.boneShadow(SkeletonPointToScreen(skeleton.Joints[JointType.WristLeft].Position), SkeletonPointToScreen(skeleton.Joints[JointType.HandLeft].Position), drawingContext); * * // Right Arm * spooks.boneShadow(SkeletonPointToScreen(skeleton.Joints[JointType.ShoulderRight].Position), SkeletonPointToScreen(skeleton.Joints[JointType.ElbowRight].Position), drawingContext); * spooks.boneShadow(SkeletonPointToScreen(skeleton.Joints[JointType.ElbowRight].Position), SkeletonPointToScreen(skeleton.Joints[JointType.WristRight].Position), drawingContext); * spooks.boneShadow(SkeletonPointToScreen(skeleton.Joints[JointType.WristRight].Position), SkeletonPointToScreen(skeleton.Joints[JointType.HandRight].Position), drawingContext); * * * // Left Leg * spooks.boneShadow(SkeletonPointToScreen(skeleton.Joints[JointType.HipLeft].Position), SkeletonPointToScreen(skeleton.Joints[JointType.KneeLeft].Position), drawingContext); * spooks.boneShadow(SkeletonPointToScreen(skeleton.Joints[JointType.KneeLeft].Position), SkeletonPointToScreen(skeleton.Joints[JointType.AnkleLeft].Position), drawingContext); * spooks.boneShadow(SkeletonPointToScreen(skeleton.Joints[JointType.AnkleLeft].Position), SkeletonPointToScreen(skeleton.Joints[JointType.FootLeft].Position), drawingContext); * * // Right Leg * spooks.boneShadow(SkeletonPointToScreen(skeleton.Joints[JointType.HipRight].Position), SkeletonPointToScreen(skeleton.Joints[JointType.KneeRight].Position), drawingContext); * spooks.boneShadow(SkeletonPointToScreen(skeleton.Joints[JointType.KneeRight].Position), SkeletonPointToScreen(skeleton.Joints[JointType.AnkleRight].Position), drawingContext); * spooks.boneShadow(SkeletonPointToScreen(skeleton.Joints[JointType.AnkleRight].Position), SkeletonPointToScreen(skeleton.Joints[JointType.FootRight].Position), drawingContext); */ double distance = Math.Sqrt(((SkeletonPointToScreen(skeleton.Joints[JointType.Spine].Position).X - SkeletonPointToScreen(skeleton.Joints[JointType.HipCenter].Position).X) * (SkeletonPointToScreen(skeleton.Joints[JointType.Spine].Position).X - SkeletonPointToScreen(skeleton.Joints[JointType.HipCenter].Position).X)) + ((SkeletonPointToScreen(skeleton.Joints[JointType.Spine].Position).Y - SkeletonPointToScreen(skeleton.Joints[JointType.HipCenter].Position).Y) * (SkeletonPointToScreen(skeleton.Joints[JointType.Spine].Position).Y - SkeletonPointToScreen(skeleton.Joints[JointType.HipCenter].Position).Y))); spooks.drawHead(this.SkeletonPointToScreen(skeleton.Joints[JointType.Head].Position), drawingContext, distance); }
private void SensorSkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { Skeleton[] skeletons = new Skeleton[0]; using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; skeletonFrame.CopySkeletonDataTo(skeletons); } } using (DrawingContext dc = this.drawingGroup.Open()) { // Draw a transparent background to set the render size dc.DrawRectangle(System.Windows.Media.Brushes.Black, null, new Rect(0.0, 0.0, RenderWidth, RenderHeight)); for (int i = 0; i < balls.Length; i++) { if (balls[i].getColor() == 'g') { dc.DrawEllipse(System.Windows.Media.Brushes.Lime, null, balls[i].getPosition(), balls[i].getRadius(), balls[i].getRadius()); } else if (balls[i].getColor() == 'r') { dc.DrawEllipse(System.Windows.Media.Brushes.Red, null, balls[i].getPosition(), balls[i].getRadius(), balls[i].getRadius()); } else if (balls[i].getColor() == 'b') { dc.DrawEllipse(System.Windows.Media.Brushes.DeepSkyBlue, null, balls[i].getPosition(), balls[i].getRadius(), balls[i].getRadius()); } else if (balls[i].getColor() == 'y') { dc.DrawEllipse(System.Windows.Media.Brushes.Yellow, null, balls[i].getPosition(), balls[i].getRadius(), balls[i].getRadius()); } else if (balls[i].getColor() == 'p') { dc.DrawEllipse(System.Windows.Media.Brushes.MediumVioletRed, null, balls[i].getPosition(), balls[i].getRadius(), balls[i].getRadius()); } else if (balls[i].getColor() == 'o') { dc.DrawEllipse(System.Windows.Media.Brushes.Orange, null, balls[i].getPosition(), balls[i].getRadius(), balls[i].getRadius()); } //dc.DrawEllipse(System.Windows.Media.Brushes.Black, null, balls[i].getPosition(), balls[i].getRadius()-2, balls[i].getRadius()-2); balls[i].update(); } for (int i = 0; i < balls.Length; i++) { for (int j = 0; j < balls.Length; j++) { if (i != j) { balls[i].checkBallCollision(balls[j]); } } } MrSpooks spooks = new MrSpooks(); if (skeletons.Length != 0) { foreach (Skeleton skel in skeletons) { //RenderClippedEdges(skel, dc); if (skel.TrackingState == SkeletonTrackingState.Tracked) { this.DrawBonesAndJoints(skel, dc, spooks); spooks.newId(); } } } //Fixes Disapearing Ball Glitch for (int i = 0; i < balls.Length; i++) { if (Double.IsNaN(balls[i].getPosition().X) || Double.IsNaN(balls[i].getPosition().Y)) { System.Windows.Point ErrorPoint = new System.Windows.Point(); ErrorPoint.X = (float)ran.Next((int)RenderWidth); ErrorPoint.Y = (float)ran.Next((int)RenderHeight); balls[i].position = ErrorPoint; balls[i].dX = 0; balls[i].dY = 0; balls[i].ax = 0; balls[i].ay = 0; } } // prevent drawing outside of our render area this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, RenderWidth, RenderHeight)); } }