Game Development Reference
In-Depth Information
Starting and stopping the gyroscope hardware is also little more than calling a
method of the CMMotionManager class. For safety we wrap these calls with further
checks to make sure the gyroscope is available and not already started or stopped.
void GyroscopeStart_platform()
{
if (gpMotionManager.gyroAvailable && !gpMotionManager.gyroActive)
{
[gpMotionManager startGyroUpdates];
}
}
void GyroscopeStop_platform()
{
if (gpMotionManager.gyroAvailable && gpMotionManager.gyroActive)
{
[gpMotionManager stopGyroUpdates];
}
}
The only thing left to do is get hold of the current gyroscope input values. The
CMMotionManager class contains a property called gyroData of class CMGyroData ,
which in turn contains a CMRotationRate property called, funnily enough,
rotationRate that holds the current gyroscope data.
The following code shows the implementation for getting hold of the gyroscope
data for the x axis. How to obtain the y and z axes values should be fairly obvious
from this!
float GyroscopeGetX_platform()
{
CMGyroData* lpGyroData = [gpMotionManager gyroData];
if (lpGyroData)
{
CMRotationRate lpRotRate = [lpGyroData rotationRate];
return lpRotRate.x;
}
else
{
return 0.0f;
}
}
There is one final thing we have to do before we can build the extension, and that
is to tell the EDK build tools that we need to include the iOS SDK framework
CoreMotion , as this contains the code for the CMMotionManager class.
 
Search WWH ::




Custom Search