1

I have make a game (pong) using a kinect, I can recognize one skeleton and I can make gestures to control the left stick, but when I try to play with two players don´t recognize the skeleton of other player. This is what I do so far:

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);
                }
                if (skeletons.Length != 0)
                {
                    foreach (Skeleton skel in skeletons)
                    {
                        if (skel.TrackingState == SkeletonTrackingState.Tracked)
                        {
                            this.tracked(skel);
                            this.trackedLeft(skel);
                        }
                    }
                }
            }
        }

        public void tracked(Skeleton skeleton)
        {
            Joint jHandRight = skeleton.Joints[JointType.HandRight];
            Joint jHipCenter = skeleton.Joints[JointType.HipCenter];
            if ((jHipCenter.Position.Z - jHandRight.Position.Z) > 0.2)
            {
                //Consider hand raised in front of them
                //System.Diagnostics.Debug.WriteLine("Hand: Raised");
                //MessageBox.Show("POR FAVORRRRRRRR");
                //movement[0] = false;
                movement[0] = true;
                movement[1] = false;
            }
            else
            {
                //Hand is lowered by the users side
                //System.Diagnostics.Debug.WriteLine("Hand: Lowered");
                //MessageBox.Show("A SERRRRIIIIIOOOOOOOOOOOOOO");
                //movement[1] = false;
                movement[1] = true;
                movement[0] = false;
            }
        }

Someone could help me.

seal
  • 520
  • 2
  • 5
  • 20

1 Answers1

1

You need a way to distinguish between skeleton one and two. See Kinect user Detection for how to do this. You can then pass the skeleton for player one and two to your two different methods. I use the player ID because if a skeleton is lost for a frame or two, their ID remains the same

int id1 = 0, id2 = 0;

... 

if (skeletons.Length != 0)
{
    foreach (Skeleton skel in skeletons)
    {
         if (skel.TrackingState == SkeletonTrackingState.Tracked)
         {
                if (skel.TrackingID == id1)
                    this.tracked(skel);
                else if (skel.TrackingID == id2)
                    this.trackedLeft(skel);
                else
                {
                     if (id1 != 0 && id2 == 0)
                         id2 = skel.TrackingID;
                     else if (id2 != 0 && id1 == 0)
                         id1 = skel.TrackingID;
                }
         }
     }
  }
Community
  • 1
  • 1
Liam McInroy
  • 4,339
  • 5
  • 32
  • 53
  • Did you mean to have both ID's the same? – mason Jun 23 '14 at 15:14
  • @mason No haha accidentally messed up my code... Check my edits – Liam McInroy Jun 23 '14 at 15:33
  • I have a question, in which case will the code enter this `if (id1 != 0 && id2 == 0) id2 = skel.TrackingID; else if (id2 != 0 && id1 == 0) id1 = skel.TrackingID;` i tried it and it never passes there... am i missing something? – seal Jun 24 '14 at 09:42
  • I found the way to distinguish the two players, thank you for your help :) – seal Jun 24 '14 at 10:10
  • @seal That condition is satisfied when the first id has been assigned (id1) so it is not zero, but id2 still has the starting value of zero, so it assigns the new id to id2 – Liam McInroy Jun 24 '14 at 13:36