Game Development Reference
In-Depth Information
To determine whether this device returns values in degrees or radians, we look at the
maximum range value of the gyroscope sensor. We set the mUsesDegrees member
variable to true if the maximum range is greater than 100, as there does not appear
to be any more robust way of determining this.
We then set our class instance to be a listener for gyroscope data. Periodically, the
onSensorChanged method (which we have yet to implement) will be called with
new gyroscope values.
Next we will implement the GyroscopeStop function, which should look like this:
public void GyroscopeStop()
{
SensorManager lSensorManager = GetSensorManager();
if (lSensorManager != null)
{
lSensorManager.unregisterListener(this);
}
x = 0.0f;
y = 0.0f;
z = 0.0f;
}
Yet again we obtain the SensorManager class reference and tell it that we no longer
want to receive gyroscope data. We also clear the cached gyroscope values just in
case our code tries to access them while the gyroscope hardware is not active.
The next three methods we need to implement are those that return the cached
gyroscope values. These are easy to implement and should look like this:
public float GyroscopeGetX()
{
return x;
}
public float GyroscopeGetY()
{
return y;
}
public float GyroscopeGetZ()
{
return z;
}
 
Search WWH ::




Custom Search