Last active
August 29, 2015 14:18
-
-
Save Razzlegames/bd3e902843bc966d0c08 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Matrix values for orientation */ | |
static final int ACCELEROMETER_AXIS_SWAP[][] = { | |
{1, -1, 0, 1}, // ROTATION_0 | |
{-1, -1, 1, 0}, // ROTATION_90 | |
{-1, 1, 0, 1}, // ROTATION_180 | |
{1, 1, 1, 0}}; // ROTATION_270 | |
//***************************************************************************** | |
@Override | |
public void onSensorChanged(SensorEvent event) | |
{ | |
WindowManager window_mng = | |
(WindowManager)application.getSystemService( Activity.WINDOW_SERVICE); | |
orientation = window_mng.getDefaultDisplay().getOrientation(); | |
final int[] as = ACCELEROMETER_AXIS_SWAP[orientation]; | |
final float x = (float)as[0] * event.values[as[2]]; | |
final float y = (float)as[1] * event.values[as[3]]; | |
final float z = event.values[2]; | |
// use screenX, screenY and screenZ as your accelerometer values now! | |
// | |
//Log.e(Logging.TAG, "Orientation: "+ orientation); | |
// Logging.E( | |
// "Screen orientation: x: " + screenX + | |
// " y: " + screenY + | |
// " z: " + screenZ + | |
// "\n"); | |
// gl_surface.queueEvent(new Runnable() { | |
// public void run() | |
// { | |
// processTilt(x, y, z); | |
// } }); | |
processTilt(x, y, z); | |
// processTilt( | |
// x-tilt_initial_value.x, | |
// y-tilt_initial_value.y, | |
// z); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment