Java tutorial
//package com.java2s; //License from project: Apache License import android.hardware.SensorEvent; import android.hardware.SensorManager; import android.opengl.Matrix; import android.view.Surface; public class Main { private static float[] mTmp = new float[16]; public static void sensorRotationVector2Matrix(SensorEvent event, int rotation, float[] output) { float[] values = event.values; switch (rotation) { case Surface.ROTATION_0: case Surface.ROTATION_180: /* Notice: not supported for ROTATION_180! */ SensorManager.getRotationMatrixFromVector(output, values); break; case Surface.ROTATION_90: SensorManager.getRotationMatrixFromVector(mTmp, values); SensorManager.remapCoordinateSystem(mTmp, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, output); break; case Surface.ROTATION_270: SensorManager.getRotationMatrixFromVector(mTmp, values); SensorManager.remapCoordinateSystem(mTmp, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_X, output); break; } Matrix.rotateM(output, 0, 90.0F, 1.0F, 0.0F, 0.0F); } }