public static void SetJointTrackingState(this BodyData self, int jointIndex, ref NuiSkeletonPositionTrackingState State) { State = (NuiSkeletonPositionTrackingState)self.trackingState[jointIndex]; }
//public int footNotTrackedCount = 0; // Waterstrong update return type private void processSkeleton() { int[] tracked = new int[Kinect.Constants.NuiSkeletonMaxTracked]; tracked[0] = -1; tracked[1] = -1; int trackedCount = 0; //update players for (int ii = 0; ii < Kinect.Constants.NuiSkeletonCount; ii++) { players[ii] = kinect.getSkeleton().SkeletonData[ii].eTrackingState; if (players[ii] == Kinect.NuiSkeletonTrackingState.SkeletonTracked) { tracked[trackedCount] = ii; trackedCount++; } } playerState[0] = -4; // -4 refer to no skeleton tracking // Waterstrong Add playerState[1] = -4; //this should really use trackingID instead of index, but for now this is fine switch (trackedCount) { case 0: trackedPlayers[0] = -1; trackedPlayers[1] = -1; offsetCalibrated = false; break; case 1: if (trackedPlayers[1] >= 0) { offsetCalibrated = false; } trackedPlayers[0] = tracked[0]; trackedPlayers[1] = -1; // Waterstrong Alter for only one player /* Waterstrong Comments * //last frame there were no players: assign new player to p1 * if (trackedPlayers[0] < 0 && trackedPlayers[1] < 0) * trackedPlayers[0] = tracked[0]; * //last frame there was one player, keep that player in the same spot * else if (trackedPlayers[0] < 0) * trackedPlayers[1] = tracked[0]; * else if (trackedPlayers[1] < 0) * trackedPlayers[0] = tracked[0]; * //there were two players, keep the one with the same index (if possible) * else * { * if (tracked[0] == trackedPlayers[0]) * trackedPlayers[1] = -1; * else if (tracked[0] == trackedPlayers[1]) * trackedPlayers[0] = -1; * else * { * trackedPlayers[0] = tracked[0]; * trackedPlayers[1] = -1; * } * }*/ break; case 2: //last frame there were no players: assign new players to p1 and p2 if (trackedPlayers[0] < 0 && trackedPlayers[1] < 0) { trackedPlayers[0] = tracked[0]; trackedPlayers[1] = tracked[1]; } //last frame there was one player, keep that player in the same spot else if (trackedPlayers[0] < 0) { if (trackedPlayers[1] == tracked[0]) { trackedPlayers[0] = tracked[1]; } else { trackedPlayers[0] = tracked[0]; trackedPlayers[1] = tracked[1]; } } else if (trackedPlayers[1] < 0) { if (trackedPlayers[0] == tracked[1]) { trackedPlayers[1] = tracked[0]; } else { trackedPlayers[0] = tracked[0]; trackedPlayers[1] = tracked[1]; } } //there were two players, keep the one with the same index (if possible) else { if (trackedPlayers[0] == tracked[1] || trackedPlayers[1] == tracked[0]) { trackedPlayers[0] = tracked[1]; trackedPlayers[1] = tracked[0]; } else { trackedPlayers[0] = tracked[0]; trackedPlayers[1] = tracked[1]; } } break; } //update the bone positions, velocities, and tracking states) for (int player = 0; player < 2; player++) { //print(player + ", " +trackedPlayers[player]); if (trackedPlayers[player] >= 0) { ///////////////////////////////////////////////////////////// // get player position // Waterstrong Add //playerPos[player] = kinectToWorld.MultiplyPoint3x4(kinect.getSkeleton().SkeletonData[trackedPlayers[player]].Position); // playerPos[player].z = playerPos[player].z; // get player position // Waterstrong Add playerPos[player] = kinectToWorld.MultiplyPoint3x4(kinect.getSkeleton().SkeletonData[trackedPlayers[player]].SkeletonPositions[(int)NuiSkeletonPositionIndex.HipCenter]); // if user is not in range return false; // Waterstorng Add if (kinect.getKinectCenter().z - playerPos[player].z < 1.7f) { playerState[player] = -3; continue; // should be continue, not break, or the second player can't get data // Waterstrong Attention } if (kinect.getKinectCenter().z - playerPos[player].z > 3.5f) { playerState[player] = 3; continue; } if (kinect.getKinectCenter().x - playerPos[player].x < -0.7f) { playerState[player] = -1; continue; } if (kinect.getKinectCenter().x - playerPos[player].x > 0.7f) { playerState[player] = 1; continue; } playerState[player] = 0; // skeleton tracking is ok // Waterstrong Add //footNotTrackedCount = 0; ///////////////////////////////////////////////////////////// for (int bone = 0; bone < (int)Kinect.NuiSkeletonPositionIndex.Count; bone++) { NuiSkeletonPositionTrackingState jointTrackingState = kinect.getSkeleton().SkeletonData[trackedPlayers[player]].eSkeletonPositionTrackingState[bone]; if (jointTrackingState == NuiSkeletonPositionTrackingState.NotTracked) { //if (bone >= (int)NuiSkeletonPositionIndex.KneeLeft && // bone <= (int)NuiSkeletonPositionIndex.FootRight && // bone != (int)NuiSkeletonPositionIndex.HipRight) //{ // ++footNotTrackedCount; //} continue; } Vector3 oldpos = bonePos[player, bone]; bonePos[player, bone] = kinectToWorld.MultiplyPoint3x4(kinect.getSkeleton().SkeletonData[trackedPlayers[player]].SkeletonPositions[bone]); //bonePos[player,bone] = kinectToWorld.MultiplyPoint3x4(bonePos[player, bone]); rawBonePos[player, bone] = kinect.getSkeleton().SkeletonData[trackedPlayers[player]].SkeletonPositions[bone]; Kinect.NuiSkeletonBoneOrientation[] or = kinect.getBoneOrientations(kinect.getSkeleton().SkeletonData[trackedPlayers[player]]); boneLocalOrientation[player, bone] = or[bone].hierarchicalRotation.rotationQuaternion.GetQuaternion(); boneAbsoluteOrientation[player, bone] = or[bone].absoluteRotation.rotationQuaternion.GetQuaternion(); //print("index " + bone + ", start" + (int)or[bone].startJoint + ", end" + (int)or[bone].endJoint); boneVel[player, bone] = (bonePos[player, bone] - oldpos) / deltaTime; boneState[player, bone] = kinect.getSkeleton().SkeletonData[trackedPlayers[player]].eSkeletonPositionTrackingState[bone]; //print(kinect.getSkeleton().SkeletonData[player].Position.z); } //if (footNotTrackedCount > 2) //{ // return false; //} } } }