void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { if (closing) { return; } //Get a skeleton Skeleton first = GetFirstSkeleton(e); if (first == null) { return; } canvas1.Children.Clear(); foreach (var player in this.players) { player.Value.Draw(canvas1.Children); } //label1.Content = "players size: " + players.Count; using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { int skeletonSlot = 0; if ((this.allSkeletons == null) || (this.allSkeletons.Length != skeletonFrame.SkeletonArrayLength)) { this.allSkeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; } skeletonFrame.CopySkeletonDataTo(this.allSkeletons); foreach (Skeleton skeleton in this.allSkeletons) { if (SkeletonTrackingState.Tracked == skeleton.TrackingState) { Player player; if (this.players.ContainsKey(skeletonSlot)) { player = this.players[skeletonSlot]; } else { player = new Player(skeletonSlot); player.SetBounds(this.playerBounds); this.players.Add(skeletonSlot, player); } player.LastUpdated = DateTime.Now; // Update player's bone and joint positions if (skeleton.Joints.Count > 0) { player.IsAlive = true; // Head, hands, feet (hit testing happens in order here) player.UpdateJointPosition(skeleton.Joints, JointType.Head); player.UpdateJointPosition(skeleton.Joints, JointType.HandLeft); player.UpdateJointPosition(skeleton.Joints, JointType.HandRight); player.UpdateJointPosition(skeleton.Joints, JointType.FootLeft); player.UpdateJointPosition(skeleton.Joints, JointType.FootRight); // Hands and arms player.UpdateBonePosition(skeleton.Joints, JointType.HandRight, JointType.WristRight); player.UpdateBonePosition(skeleton.Joints, JointType.WristRight, JointType.ElbowRight); player.UpdateBonePosition(skeleton.Joints, JointType.ElbowRight, JointType.ShoulderRight); player.UpdateBonePosition(skeleton.Joints, JointType.HandLeft, JointType.WristLeft); player.UpdateBonePosition(skeleton.Joints, JointType.WristLeft, JointType.ElbowLeft); player.UpdateBonePosition(skeleton.Joints, JointType.ElbowLeft, JointType.ShoulderLeft); // Head and Shoulders player.UpdateBonePosition(skeleton.Joints, JointType.ShoulderCenter, JointType.Head); player.UpdateBonePosition(skeleton.Joints, JointType.ShoulderLeft, JointType.ShoulderCenter); player.UpdateBonePosition(skeleton.Joints, JointType.ShoulderCenter, JointType.ShoulderRight); // Legs player.UpdateBonePosition(skeleton.Joints, JointType.HipLeft, JointType.KneeLeft); player.UpdateBonePosition(skeleton.Joints, JointType.KneeLeft, JointType.AnkleLeft); player.UpdateBonePosition(skeleton.Joints, JointType.AnkleLeft, JointType.FootLeft); player.UpdateBonePosition(skeleton.Joints, JointType.HipRight, JointType.KneeRight); player.UpdateBonePosition(skeleton.Joints, JointType.KneeRight, JointType.AnkleRight); player.UpdateBonePosition(skeleton.Joints, JointType.AnkleRight, JointType.FootRight); player.UpdateBonePosition(skeleton.Joints, JointType.HipLeft, JointType.HipCenter); player.UpdateBonePosition(skeleton.Joints, JointType.HipCenter, JointType.HipRight); // Spine player.UpdateBonePosition(skeleton.Joints, JointType.HipCenter, JointType.ShoulderCenter); //label1.Content = player.ToString(); } } skeletonSlot++; } } } //set scaled position //ScalePosition(headImage, first.Joints[JointType.Head]); //ScalePosition(leftEllipse, first.Joints[JointType.HandLeft]); //ScalePosition(rightEllipse, first.Joints[JointType.HandRight]); GetCameraPoint(first, e); //throw new NotImplementedException(); checkForHit(); }
private void SkeletonsReady(object sender, SkeletonFrameReadyEventArgs e) { using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { int skeletonSlot = 0; if ((this.skeletonData == null) || (this.skeletonData.Length != skeletonFrame.SkeletonArrayLength)) { this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength]; } skeletonFrame.CopySkeletonDataTo(this.skeletonData); foreach (Skeleton skeleton in this.skeletonData) { if (SkeletonTrackingState.Tracked == skeleton.TrackingState) { Player player; if (this.players.ContainsKey(skeletonSlot)) { player = this.players[skeletonSlot]; } else { player = new Player(skeletonSlot); player.SetBounds(this.playerBounds); this.players.Add(skeletonSlot, player); } player.LastUpdated = DateTime.Now; // Update player's bone and joint positions if (skeleton.Joints.Count > 0) { player.IsAlive = true; // Head, hands, feet (hit testing happens in order here) player.UpdateJointPosition(skeleton.Joints, JointType.Head); player.UpdateJointPosition(skeleton.Joints, JointType.HandLeft); player.UpdateJointPosition(skeleton.Joints, JointType.HandRight); player.UpdateJointPosition(skeleton.Joints, JointType.FootLeft); player.UpdateJointPosition(skeleton.Joints, JointType.FootRight); // Hands and arms player.UpdateBonePosition(skeleton.Joints, JointType.HandRight, JointType.WristRight); player.UpdateBonePosition(skeleton.Joints, JointType.WristRight, JointType.ElbowRight); player.UpdateBonePosition(skeleton.Joints, JointType.ElbowRight, JointType.ShoulderRight); player.UpdateBonePosition(skeleton.Joints, JointType.HandLeft, JointType.WristLeft); player.UpdateBonePosition(skeleton.Joints, JointType.WristLeft, JointType.ElbowLeft); player.UpdateBonePosition(skeleton.Joints, JointType.ElbowLeft, JointType.ShoulderLeft); // Head and Shoulders player.UpdateBonePosition(skeleton.Joints, JointType.ShoulderCenter, JointType.Head); player.UpdateBonePosition(skeleton.Joints, JointType.ShoulderLeft, JointType.ShoulderCenter); player.UpdateBonePosition(skeleton.Joints, JointType.ShoulderCenter, JointType.ShoulderRight); // Legs player.UpdateBonePosition(skeleton.Joints, JointType.HipLeft, JointType.KneeLeft); player.UpdateBonePosition(skeleton.Joints, JointType.KneeLeft, JointType.AnkleLeft); player.UpdateBonePosition(skeleton.Joints, JointType.AnkleLeft, JointType.FootLeft); player.UpdateBonePosition(skeleton.Joints, JointType.HipRight, JointType.KneeRight); player.UpdateBonePosition(skeleton.Joints, JointType.KneeRight, JointType.AnkleRight); player.UpdateBonePosition(skeleton.Joints, JointType.AnkleRight, JointType.FootRight); player.UpdateBonePosition(skeleton.Joints, JointType.HipLeft, JointType.HipCenter); player.UpdateBonePosition(skeleton.Joints, JointType.HipCenter, JointType.HipRight); // Spine player.UpdateBonePosition(skeleton.Joints, JointType.HipCenter, JointType.ShoulderCenter); } } skeletonSlot++; } } } }
void SkeletonsReady(object sender, SkeletonFrameReadyEventArgs e) { SkeletonFrame skeletonFrame = e.SkeletonFrame; //KinectSDK TODO: This nullcheck shouldn't be required. //Unfortunately, this version of the Kinect Runtime will continue to fire some skeletonFrameReady events after the Kinect USB is unplugged. if (skeletonFrame == null) { return; } int iSkeletonSlot = 0; foreach (SkeletonData data in skeletonFrame.Skeletons) { if (SkeletonTrackingState.Tracked == data.TrackingState) { Player player; if (players.ContainsKey(iSkeletonSlot)) { player = players[iSkeletonSlot]; } else { player = new Player(iSkeletonSlot); player.setBounds(playerBounds); players.Add(iSkeletonSlot, player); } player.lastUpdated = DateTime.Now; // Update player's bone and joint positions if (data.Joints.Count > 0) { player.isAlive = true; // Head, hands, feet (hit testing happens in order here) player.UpdateJointPosition(data.Joints, JointID.Head); player.UpdateJointPosition(data.Joints, JointID.HandLeft); player.UpdateJointPosition(data.Joints, JointID.HandRight); player.UpdateJointPosition(data.Joints, JointID.FootLeft); player.UpdateJointPosition(data.Joints, JointID.FootRight); // Hands and arms player.UpdateBonePosition(data.Joints, JointID.HandRight, JointID.WristRight); player.UpdateBonePosition(data.Joints, JointID.WristRight, JointID.ElbowRight); player.UpdateBonePosition(data.Joints, JointID.ElbowRight, JointID.ShoulderRight); player.UpdateBonePosition(data.Joints, JointID.HandLeft, JointID.WristLeft); player.UpdateBonePosition(data.Joints, JointID.WristLeft, JointID.ElbowLeft); player.UpdateBonePosition(data.Joints, JointID.ElbowLeft, JointID.ShoulderLeft); // Head and Shoulders player.UpdateBonePosition(data.Joints, JointID.ShoulderCenter, JointID.Head); player.UpdateBonePosition(data.Joints, JointID.ShoulderLeft, JointID.ShoulderCenter); player.UpdateBonePosition(data.Joints, JointID.ShoulderCenter, JointID.ShoulderRight); // Legs player.UpdateBonePosition(data.Joints, JointID.HipLeft, JointID.KneeLeft); player.UpdateBonePosition(data.Joints, JointID.KneeLeft, JointID.AnkleLeft); player.UpdateBonePosition(data.Joints, JointID.AnkleLeft, JointID.FootLeft); player.UpdateBonePosition(data.Joints, JointID.HipRight, JointID.KneeRight); player.UpdateBonePosition(data.Joints, JointID.KneeRight, JointID.AnkleRight); player.UpdateBonePosition(data.Joints, JointID.AnkleRight, JointID.FootRight); player.UpdateBonePosition(data.Joints, JointID.HipLeft, JointID.HipCenter); player.UpdateBonePosition(data.Joints, JointID.HipCenter, JointID.HipRight); // Spine player.UpdateBonePosition(data.Joints, JointID.HipCenter, JointID.ShoulderCenter); } } iSkeletonSlot++; } }
private void SkeletonsReady(object sender, SkeletonFrameReadyEventArgs e) { using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { int skeletonSlot = 0; if ((this.skeletonData == null) || (this.skeletonData.Length != skeletonFrame.SkeletonArrayLength)) { this.skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength]; } skeletonFrame.CopySkeletonDataTo(this.skeletonData); foreach (Skeleton skeleton in this.skeletonData) { if (SkeletonTrackingState.Tracked == skeleton.TrackingState) { Player player; if (this.players.ContainsKey(skeletonSlot)) { player = this.players[skeletonSlot]; } else { player = new Player(skeletonSlot, myViewport3D); player.SetBounds(this.playerBounds); this.players.Add(skeletonSlot, player); } player.LastUpdated = DateTime.Now; // Update player's bone and joint positions if (skeleton.Joints.Count > 0) { player.IsAlive = true; player.UpdateAllJoints(skeleton.Joints); } } skeletonSlot++; } } } }
void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e) { if (closing) { return; } canvas1.Children.Clear(); canvas2.Children.Clear(); foreach (var player in this.players) { if (player.Key == 0) { player.Value.Draw(canvas1.Children);//if player 1 } else { player.Value.Draw(canvas2.Children);//if player 2 } } using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame()) { if (skeletonFrame != null) { int skeletonSlot = 0; if ((this.allSkeletons == null) || (this.allSkeletons.Length != skeletonFrame.SkeletonArrayLength)) { this.allSkeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; } skeletonFrame.CopySkeletonDataTo(this.allSkeletons); foreach (Skeleton skeleton in this.allSkeletons) { if (SkeletonTrackingState.Tracked == skeleton.TrackingState) { Player player; if (this.players.ContainsKey(skeletonSlot)) { player = this.players[skeletonSlot]; } else { player = new Player(skeletonSlot); //skeletonslot 0 is player1 skeletonslot 1 is player 2 player.SetBounds(this.playerBounds); //this would be where we change player bounds - will this work? this.players.Add(skeletonSlot, player); } player.LastUpdated = DateTime.Now; // Update player's bone and joint positions if (skeleton.Joints.Count > 0) { player.IsAlive = true; // Head, hands, feet (hit testing happens in order here) player.UpdateJointPosition(skeleton.Joints, JointType.Head); player.UpdateJointPosition(skeleton.Joints, JointType.HandLeft); player.UpdateJointPosition(skeleton.Joints, JointType.HandRight); player.UpdateJointPosition(skeleton.Joints, JointType.FootLeft); player.UpdateJointPosition(skeleton.Joints, JointType.FootRight); // Hands and arms player.UpdateBonePosition(skeleton.Joints, JointType.HandRight, JointType.WristRight); player.UpdateBonePosition(skeleton.Joints, JointType.WristRight, JointType.ElbowRight); player.UpdateBonePosition(skeleton.Joints, JointType.ElbowRight, JointType.ShoulderRight); player.UpdateBonePosition(skeleton.Joints, JointType.HandLeft, JointType.WristLeft); player.UpdateBonePosition(skeleton.Joints, JointType.WristLeft, JointType.ElbowLeft); player.UpdateBonePosition(skeleton.Joints, JointType.ElbowLeft, JointType.ShoulderLeft); // Head and Shoulders player.UpdateBonePosition(skeleton.Joints, JointType.ShoulderCenter, JointType.Head); player.UpdateBonePosition(skeleton.Joints, JointType.ShoulderLeft, JointType.ShoulderCenter); player.UpdateBonePosition(skeleton.Joints, JointType.ShoulderCenter, JointType.ShoulderRight); // Legs player.UpdateBonePosition(skeleton.Joints, JointType.HipLeft, JointType.KneeLeft); player.UpdateBonePosition(skeleton.Joints, JointType.KneeLeft, JointType.AnkleLeft); player.UpdateBonePosition(skeleton.Joints, JointType.AnkleLeft, JointType.FootLeft); player.UpdateBonePosition(skeleton.Joints, JointType.HipRight, JointType.KneeRight); player.UpdateBonePosition(skeleton.Joints, JointType.KneeRight, JointType.AnkleRight); player.UpdateBonePosition(skeleton.Joints, JointType.AnkleRight, JointType.FootRight); player.UpdateBonePosition(skeleton.Joints, JointType.HipLeft, JointType.HipCenter); player.UpdateBonePosition(skeleton.Joints, JointType.HipCenter, JointType.HipRight); // Spine player.UpdateBonePosition(skeleton.Joints, JointType.HipCenter, JointType.ShoulderCenter); GetCameraPoint(skeleton, e, skeletonSlot); if (skeletonSlot == 0 && p1righty == true) { ScalePosition(p1racket, skeleton.Joints[JointType.HandRight], skeletonSlot); } else if (skeletonSlot == 0 && p1righty == false) { ScalePosition(p1racket, skeleton.Joints[JointType.HandLeft], skeletonSlot); } else if (skeletonSlot != 0 && p2righty == false) { ScalePosition(p2racket, skeleton.Joints[JointType.HandLeft], skeletonSlot); } else { ScalePosition(p2racket, skeleton.Joints[JointType.HandRight], skeletonSlot); } } } skeletonSlot++; } } } if (serve==true && firsthit == true && gameover==false) { checkForHit(); if (hit == true) { firsthit=false; } } if (serve == true && firsthit==false && gameover==false) { if (ellipse1.Width > 40 && ellipse1.Height > 40 && hit==false) //determines when the ball can be hit { hitable = true; } else { hitable = false; } //checks for hit when hitable if (hitable == true && hit == false) { checkForHit(); } if (hit==true) { ellipse1.Width--; ellipse1.Height--; hitable=false; } if (ellipse1.Width <= 5 && ellipse1.Height <= 5) //once the ball is at min, start getting bigger { if (Canvas.GetLeft(ellipse1) < (MainCanvas.Width/2)) { int x = rdm.Next(405, 760); //int y = rdm.Next((int)((MainCanvas.Height/2)+50); Canvas.SetLeft(ellipse1, x); //Canvas.SetTop(ellipse1, y); } else { int x = rdm.Next((int)((MainCanvas.Width / 2)-50)); //int y = rdm.Next((int)((MainCanvas.Height/2)+50); Canvas.SetLeft(ellipse1, x); //Canvas.SetTop(ellipse1, y); } hit = false; } if(ellipse1.Width<50 && ellipse1.Height<50 && hit==false) { ellipse1.Width++; ellipse1.Height++; } if (ellipse1.Width >= 50 && ellipse1.Height >= 50 && hit == false) { //player missed ball ellipse1.Opacity = 0; serve = false; //increment score label if (Canvas.GetLeft(ellipse1)>=(MainCanvas.Width/2)) {//do this by ball position in relation to canvas instead? p1score += 15; label1.Content = p1score; Canvas.SetLeft(ellipse1, 100.0); //reset position to canvas1 and max size } if (Canvas.GetLeft(ellipse1) < (MainCanvas.Width / 2)) { p2score += 15; label2.Content = p2score; Canvas.SetLeft(ellipse1, 505.0); //reset position to canvas2 and max size } } } if (p1score >= 60 || p2score >= 60) { gameover = true; label1.Content="Game Over: " + p1score; label2.Content = "Game Over: " + p2score; ellipse1.Opacity = 0; p1racket.Opacity = 0; p2racket.Opacity = 0; } }
public HitType LookForHits(Dictionary<Bone, BoneData> segments, Player player) { DateTime cur = DateTime.Now; HitType allHits = HitType.None; // Zero out score if necessary if (!this.scores.ContainsKey(player.GetId())) { this.scores.Add(player.GetId(), 0); } foreach (var pair in segments) { if (pair.Key.Joint1 != JointType.HandLeft && pair.Key.Joint1 != JointType.HandRight && pair.Key.Joint1 != JointType.FootLeft && pair.Key.Joint1 != JointType.FootRight) { continue; } var hitCenter = new System.Windows.Point(0, 0); double lineHitLocation = 0; Segment seg = pair.Value.GetEstimatedSegment(cur); if (player.Holding.ContainsKey(pair.Key.Joint1)) { Thing heldThing = (Thing)player.Holding[pair.Key.Joint1]; if (heldThing.Hit(seg, ref hitCenter, ref lineHitLocation)) { continue; } else { player.Holding.Remove(pair.Key.Joint1); heldThing.State = ThingState.Falling; } } if (player.Holding.Count == 3) { continue; } for (int i = 0; i < this.things.Count; i++) { Thing thing = this.things[i]; if ((thing.ValueType == StoredValueType.Number && player.Holding.countOfNumberThings() >= 2) || thing.ValueType != StoredValueType.Number && player.Holding.countOfOperatorThings() >= 1 || player.Holding.ContainsValue(thing)) { continue; } if (thing.Hit(seg, ref hitCenter, ref lineHitLocation)) { double fMs = 1000; if (thing.TimeLastHit != DateTime.MinValue) { fMs = cur.Subtract(thing.TimeLastHit).TotalMilliseconds; thing.AvgTimeBetweenHits = (thing.AvgTimeBetweenHits * 0.8) + (0.2 * fMs); } thing.TimeLastHit = cur; thing.TouchedBy = player.GetId(); player.Holding[pair.Key.Joint1] = thing; thing.State = ThingState.Held; break; } } } return allHits; }
void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { SkeletonFrame skeletonFrame = e.SkeletonFrame; int iSkeletonSlot = 0; foreach (SkeletonData data in skeletonFrame.Skeletons) { if (SkeletonTrackingState.Tracked == data.TrackingState) { Player player; if (players.ContainsKey(iSkeletonSlot)) { player = players[iSkeletonSlot]; } else { player = new Player(iSkeletonSlot); player.setBounds(playerBounds); players.Add(iSkeletonSlot, player); } player.lastUpdated = DateTime.Now; // Update player's bone and joint positions if (data.Joints.Count > 0) { player.isAlive = true; // Head, hands, feet (hit testing happens in order here) player.UpdateJointPosition(data.Joints, JointID.Head); player.UpdateJointPosition(data.Joints, JointID.HandLeft); player.UpdateJointPosition(data.Joints, JointID.HandRight); player.UpdateJointPosition(data.Joints, JointID.FootLeft); player.UpdateJointPosition(data.Joints, JointID.FootRight); // Hands and arms player.UpdateBonePosition(data.Joints, JointID.HandRight, JointID.WristRight); player.UpdateBonePosition(data.Joints, JointID.WristRight, JointID.ElbowRight); player.UpdateBonePosition(data.Joints, JointID.ElbowRight, JointID.ShoulderRight); player.UpdateBonePosition(data.Joints, JointID.HandLeft, JointID.WristLeft); player.UpdateBonePosition(data.Joints, JointID.WristLeft, JointID.ElbowLeft); player.UpdateBonePosition(data.Joints, JointID.ElbowLeft, JointID.ShoulderLeft); // Head and Shoulders player.UpdateBonePosition(data.Joints, JointID.ShoulderCenter, JointID.Head); player.UpdateBonePosition(data.Joints, JointID.ShoulderLeft, JointID.ShoulderCenter); player.UpdateBonePosition(data.Joints, JointID.ShoulderCenter, JointID.ShoulderRight); // Legs player.UpdateBonePosition(data.Joints, JointID.HipLeft, JointID.KneeLeft); player.UpdateBonePosition(data.Joints, JointID.KneeLeft, JointID.AnkleLeft); player.UpdateBonePosition(data.Joints, JointID.AnkleLeft, JointID.FootLeft); player.UpdateBonePosition(data.Joints, JointID.HipRight, JointID.KneeRight); player.UpdateBonePosition(data.Joints, JointID.KneeRight, JointID.AnkleRight); player.UpdateBonePosition(data.Joints, JointID.AnkleRight, JointID.FootRight); player.UpdateBonePosition(data.Joints, JointID.HipLeft, JointID.HipCenter); player.UpdateBonePosition(data.Joints, JointID.HipCenter, JointID.HipRight); // Spine player.UpdateBonePosition(data.Joints, JointID.HipCenter, JointID.ShoulderCenter); } } iSkeletonSlot++; } }