Game Development Reference
In-Depth Information
and does its best to give you useful rotation information that you can immediately
make use of. As with the individual sensors, you can use this API in an event-based
fashion, or you can poll for data.
Note
This process is called
sensor fusion
, and is available on many different plat-
forms, including Windows Phone.
You can prepare this system using the same techniques as the individual sensors,
by calling the
GetDefault()
method and setting the
ReportInterval
as well as
the event handler, if required, by using the following type:
TypedEventHandler<
OrientationSensor^,
OrientationSensorReadingChangedEventArgs^>
The
OrientationSensorReadingChangedEventArgs
provides you with an
OrientationSensorReading
object that contains the following values:
property DateTime Timestamp;
property SensorQuaternion Quaternion;
property SensorRotationMatrix RotationMatrix;
There are some new types here that you may not have encountered before, in par-
ticular, the
SensorQuaternion
. A
Quaternion
in this context is a numeric repres-
entation of the rotation, in four components, XYZW. By representing the rotation in
this form rather than the traditional RollPitchYaw or XYZ angles we can avoid some
issues that occur, such as Gimbal Lock, where you lose an axis of rotation if the ob-
ject rotates 90 degrees up or down.
The other type here is the
SensorRotationMatrix
, which is a 4 x 4 matrix con-
taining the rotation values of the device, ready to be used in a 3D setting.