Skip to content

Instantly share code, notes, and snippets.

@tkowalczyk
Created April 3, 2014 12:52
Show Gist options
  • Save tkowalczyk/9953733 to your computer and use it in GitHub Desktop.
Save tkowalczyk/9953733 to your computer and use it in GitHub Desktop.
Stick on one skeleton via ID
int _trackedSkeletonId = 0;
Skeleton _currentSkeleton;
void sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
_currentSkeleton = null;
using (SkeletonFrame frame = e.OpenSkeletonFrame())
{
if (frame == null)
return;
if (_skeletons == null) _skeletons = new Skeleton[frame.SkeletonArrayLength];
frame.CopySkeletonDataTo(_skeletons);
bool bSklFound = false;
foreach (Skeleton skl in _skeletons)
{
if (skl.TrackingState == SkeletonTrackingState.Tracked)
{
if (_currentSkeleton == null)
{
_currentSkeleton = skl;
bSklFound = true;
break;
}
else if (skl.TrackingId == _trackedSkeletonId)
{
_currentSkeleton = skl;
bSklFound = true;
break;
}
}
}
if (bSklFound == true)
{
_trackedSkeletonId = _currentSkeleton.TrackingId;
//do what you want with one found skeleton
}
else
{
_currentSkeleton = null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment