Game Development Reference
In-Depth Information
can determine how much the device is being rotated (in degrees per second) and
find the current rotation of the device.
In Windows 8 the gyro is accessed through the Gyrometer class, inside the Win-
dows::Devices::Sensors namespace, as shown. You can access the readings
using events, or through a polling method similar to the accelerometer.
Gyrometer^ gyro = Gyrometer::GetDefault();
To access the gyro you first need to get the default instance, done by calling the
GetDefault() method. Once you have this you can set the reporting interval and
then register for an event handler or use the GetCurrentReading() method to
poll the device. This is shown in the following code snippet:
// Setup
Gyrometer^ gyro = Gyrometer::GetDefault();
if (gyro != nullptr)
gyro->ReportInterval =
gyro->MinimumReportInterval > 16 ?
gyro->MinimumReportInterval : 16;
// Shut-down
gyro->ReportInterval = 0;
The given code shows the setup and shutdown code for the Gyrometer class,
which is necessary for both forms of data retrieval. We retrieved the default gyro and
checked if the gyro exists on the device by checking if the returned value is null. If
a gyro does exist we will set the report interval in milliseconds, without going below
the minimum report interval.
Finally, when we're ready to shut the device down, we will set the report interval to
zero, which releases the resources and saves power. Now let's take a look at some
examples of reading from the gyro:
gyro->ReadingChanged::add(
ref new TypedEventHandler<
Search WWH ::




Custom Search