Last active
December 17, 2015 03:09
-
-
Save dotKokott/5541074 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
interactionStream = new InteractionStream(Sensor, new InteractionClient()); | |
//..SNIP... | |
void ProcessDepthFrame() { | |
using (var dif = this.Sensor.DepthStream.OpenNextFrame(0)) { | |
if (dif != null) { | |
DepthImagePixel[] data = new DepthImagePixel[dif.PixelDataLength]; | |
dif.CopyDepthImagePixelDataTo(data); | |
//Feed depth data to interactionStream | |
interactionStream.ProcessDepth(data, dif.Timestamp); | |
} | |
} | |
} | |
void ProcessSkeletonFrame() { | |
using (var skeletonFrame = this.Sensor.SkeletonStream.OpenNextFrame(0)) { | |
if (skeletonFrame != null) { | |
Skeleton[] skeletons = new Skeleton[skeletonFrame.SkeletonArrayLength]; | |
skeletonFrame.CopySkeletonDataTo(skeletons); | |
//Feed skeleton data to interactionStream | |
var accelerometerReading = this.Sensor.AccelerometerGetCurrentReading(); | |
interactionStream.ProcessSkeleton(skeletons, accelerometerReading, skeletonFrame.Timestamp); | |
Skeletons.Clear(); | |
foreach (Skeleton skel in skeletons) { | |
if (skel.TrackingState == SkeletonTrackingState.Tracked) { | |
Skeletons.Add(skel); | |
} | |
} | |
} | |
} | |
} | |
void ProcessInteractionFrame() { | |
using(var interactionFrame = interactionStream.OpenNextFrame(0)) { | |
if (interactionFrame != null) { | |
UserInfo[] userInfo = new UserInfo[InteractionFrame.UserInfoArrayLength]; | |
interactionFrame.CopyInteractionDataTo(userInfo); | |
//Query the UserInfo for every skeleton and save it in a dictionary | |
UserInfos.Clear(); | |
foreach (var skel in Skeletons) { | |
var ui = (from UserInfo u in userInfo where u.SkeletonTrackingId == skel.TrackingId select u).FirstOrDefault(); | |
if (ui != null) | |
UserInfos.Add(skel.TrackingId, ui); | |
} | |
} | |
} | |
} | |
public void Update() { | |
if (this.Sensor != null) { | |
ProcessColorFrame(); | |
ProcessSkeletonFrame(); | |
ProcessDepthFrame(); | |
ProcessInteractionFrame(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment