Sensors Coordinate System
Sensors such as the accelerometer, gyroscope, and magnetometer use a right-handed coordinate system to report their readings. The x-axis, or abscissa, increases as you move toward the right of the screen, and the y-axis, or ordinate, increases as you move toward the top of the screen. Finally, the z-axis is perpendicular to the screen (see Figure 9-3).
Figure 9-3. Right-handed coordinate system (image source: BlackBerry web site)
Sensors inheriting from QOrientableSensorBase (such as the accelerometer) can react to screen orientation changes. Therefore, these sensors can report their readings differently according to the screen's orientation. Their reporting behavior is controlled by the QOrientableSensorBase::axesOrien tationMode property, which can take the following values:
n QOrientableSensorBase::FixedOrientation: This is the default behavior and the readings remain unaffected by the screen's orientation change. When the screen orientation changes, the application will have to “compensate” the returned values in order to take into account the new screen orientation (the application will also need to detect screen orientation changes).
n QOrientableSensorBase::AutomaticOrientation: The sensor readings are automatically remapped based on the current screen orientation. Therefore, the application need not worry about screen orientation changes (this is the recommended value to use in your application).
n QOrientatableSensorBase::UserOrientation: This is similar to the previous setting except that the readings are rotated by fixed angles of 0, 90, 180, and 270 degrees (no intermediate values).
Notice that applying the device rotation to the sensor readings is equivalent to rotating the coordinate system when the screen orientation changes. Finally, angular displacements around the coordinate system's axes are also reported as right-hand rotations. You can visualize this by imagining that you are holding an imaginary screwdriver in your hand along a coordinate system axis. Positive rotations along an axis are then defined by using the screwdriver so that an imaginary screw would move toward increasing values along the axis
(see Figure 9-4).
Figure 9-4. Right-handed rotations around coordinate system (image source: BlackBerry web site)
Accelerometer and Gyroscope
Before finishing this chapter, I want to give you some tips on how to process the data readings provided by the accelerometer and gyroscope sensors. As you noticed throughout the chapter, receiving sensor readings is quite simple. The difficulty lies in the handling and interpretation of the data. I don't intend to give you a comprehensive treatment of the data processing, but hopefully this section will put you on the right track should you need to implement more advanced techniques in your own applications.