Game Development Reference
In-Depth Information
Gyrometer^, GyrometerReadingChangedEventArgs^>
(
this,
&MyClass::ReadingChanged
));
Just as with the accelerometer, this sets the Gyrometer to report new readings
(based on the ReportInterval ) to the ReadingChanged() method. An example
of that method looks like the following code snippet:
void MyClass::ReadingChanged(Gyrometer^ g,
GyrometerReadingChangedEventArgs^ args)
{
GyrometerReading^ reading = args->Reading;
double velocityX = reading->AngularVelocityX;
double velocityY = reading->AngularVelocityY;
double velocityZ = reading->AngularVelocityZ;
}
Here we can retrieve the angular velocities as well as the timestamp, and make use
of them as required. Now if we want to poll, as earlier, we just need to set up the
code, and call the gyro->GetCurrentReading() method to retrieve the Gyro-
meterReading object that contains the velocities.
Compass
Knowing the rotation of the device is great, but the values aren't relative to anything
else. You don't know if the device is pointing North or South. This is where the com-
pass (also known as the magnetometer) comes into play. Many devices have this
sensor so you can usually rely on it for some basic but useful orientation information.
The Compass API in Windows 8 is very similar to both the accelerometer and the
gyro. You get the Compass object through GetDefault() , and you can gather
readings through events or polling after setting the ReportInterval .
Search WWH ::




Custom Search