Tossing Motion
The following handler for Accelerometer
’s ReadingChanged
event contains a simple algorithm for detecting a tossing motion, such as pretending to flip a coin in the air (except in this case, the coin is the device):
// Process data coming from the accelerometer void OnReadingChanged(Accelerometer sender, AccelerometerReadingChangedEventArgs e) { // We want the threshold to be negative, so // forward motion is up and out of the screen double threshold = -1; // Only pay attention to large-enough magnitudes in the Z dimension if (Math.Abs(e.Reading.AccelerationZ) < Math.Abs(threshold)) return; // See if the force is in the same direction as the threshold // (forward ...
Get Universal Windows® Apps with XAML and C# Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.