Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

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 sensorRotation2Matrix(float[] gravity, float[] geomagnetic, int rotation, float[] output) {
        switch (rotation) {
        case Surface.ROTATION_0:
        case Surface.ROTATION_180: /* Notice: not supported for ROTATION_180! */
            SensorManager.getRotationMatrix(output, null, gravity, geomagnetic);
            break;
        case Surface.ROTATION_90:
            SensorManager.getRotationMatrix(mTmp, null, gravity, geomagnetic);
            SensorManager.remapCoordinateSystem(mTmp, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, output);
            break;
        case Surface.ROTATION_270:
            SensorManager.getRotationMatrix(mTmp, null, gravity, geomagnetic);
            SensorManager.remapCoordinateSystem(mTmp, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_X, output);
            break;
        }
        Matrix.rotateM(output, 0, 90.0F, 1.0F, 0.0F, 0.0F);
    }
}