May 2013
Intermediate to advanced
1152 pages
82h 34m
English
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); ...