Shake Detection

The phone SDK does not come with any built-in support for detecting when the device is being shaken. This section extends the custom EnhancedAccelerometer to provide shake detection.

The EnhancedAccelerometer.IsShake method returns true if the difference between the current and previous acceleration readings exceeds a threshold value for two or more dimensional components, in which case, the movement is deemed a shake. Thanks to Mark Monster, http://bit.ly/9GMDJX, on which this code is based. See the following excerpt:

static bool IsShake(Vector3 currentAcceleration,                    Vector3 previousAcceleration, double threshold){    double deltaX = Math.Abs(previousAcceleration.X - currentAcceleration.X); ...

Get Windows® Phone 8 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.