- Accelerometer
- Compass
- Geolocation
- Gyrometer
- Inclinometer
- Light Sensor
- Orientation Sensor
Orientation Sensor
The orientation sensor provides a matrix that represents rotation and a Quaternion that can be used to adjust the user’s perspective within an application. Unlike the simple orientation sensor that was used earlier in this chapter to change from portrait to landscape modes, the full orientation sensor is typically used in games to render the graphics differently based on the orientation of the tablet. A Quaternion is specific notation used to describe orientations and rotations.
Listing 4.10 illustrates how to obtain orientation readings.
Listing 4.10: Reading the Orientation
async private void ReadingChanged(object sender, OrientationSensorReadingChangedEventArgs e) { await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { OrientationSensorReading reading = e.Reading; // Quaternion values SensorQuaternion quaternion = reading.Quaternion; ScenarioOutput_X.Text = String.Format("{0,8:0.00000}", quaternion.X); ScenarioOutput_Y.Text = String.Format("{0,8:0.00000}", quaternion.Y); ScenarioOutput_Z.Text = String.Format("{0,8:0.00000}", quaternion.Z); ScenarioOutput_W.Text = String.Format("{0,8:0.00000}", quaternion.W); // Rotation Matrix values SensorRotationMatrix rotationMatrix = reading.RotationMatrix; ScenarioOutput_M11.Text = String.Format("{0,8:0.00000}", rotationMatrix.M11); ScenarioOutput_M12.Text = String.Format("{0,8:0.00000}", rotationMatrix.M12); ScenarioOutput_M13.Text = String.Format("{0,8:0.00000}", rotationMatrix.M13); ScenarioOutput_M21.Text = String.Format("{0,8:0.00000}", rotationMatrix.M21); ScenarioOutput_M22.Text = String.Format("{0,8:0.00000}", rotationMatrix.M22); ScenarioOutput_M23.Text = String.Format("{0,8:0.00000}", rotationMatrix.M23); ScenarioOutput_M31.Text = String.Format("{0,8:0.00000}", rotationMatrix.M31); ScenarioOutput_M32.Text = String.Format("{0,8:0.00000}", rotationMatrix.M32); ScenarioOutput_M33.Text = String.Format("{0,8:0.00000}", rotationMatrix.M33); }); }
You can learn more about the orientation sensor online at http://msdn.microsoft.com/en-us/library/windows/apps/windows.devices.sensors.orientationsensor.aspx.