Rotation matrix

The rotation matrix sensor type returns a rotation matrix based on the position of the device by fusing sensor data from different sources. You can use this matrix to rotate screen items to match the position of the device. For example, rotating text fields in an augmented reality app.

A BPS event with the code SENSOR_ROTATION_MATRIX_READING is generated when a new rotation matrix is available. You can call the function sensor_event_get_rotation_matrix() to retrieve the rotation matrix from the event.

The code sample below demonstrates how you can use the rotation matrix in your app:

#include <stddef.h>
#include <bps/bps.h>
#include <bps/sensor.h>

int main(void)
{
  int event_domain;
  unsigned int event_code;

  // Create variables to store the current rotation matrix.
  sensor_rotation_matrix_t rotation_matrix;

  bps_initialize();

  if (sensor_is_supported(SENSOR_TYPE_ROTATION_MATRIX))
  {
    sensor_request_events(SENSOR_TYPE_ROTATION_MATRIX);
  }

  while (1)
  {
    bps_event_t *current_event = NULL;
    bps_get_event(&current_event, -1);

    event_domain = bps_event_get_domain(current_event);
    event_code = bps_event_get_code(current_event);

    if (event_domain == sensor_get_domain())
    {
      switch (event_code)
      {
        case SENSOR_ROTATION_MATRIX_READING:
          // Get the rotation matrix for this event.
          sensor_event_get_rotation_matrix(current_event, 
                                        &rotation_matrix);

          // Adjust position of on-screen items 
          // using the rotation matrix.
          break;

        default:
          break;
      }
    }
  }

  // Program cleanup
  sensor_stop_events(SENSOR_TYPE_ROTATION_MATRIX);
  bps_shutdown();

  return 0;
}               
            

Last modified: 2013-12-21



Got questions about leaving a comment? Get answers from our Disqus FAQ.

comments powered by Disqus