Java Code Examples for android.hardware.SensorManager#AXIS_Y
The following examples show how to use
android.hardware.SensorManager#AXIS_Y .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GyroscopeController.java From crazyflie-android-client with GNU General Public License v2.0 | 6 votes |
private void update(float[] vectors) { int AMP_MAX = 50; int AMPLIFICATION = AMP_MAX / mControls.getGyroAmplification(); float[] rotationMatrix = new float[9]; SensorManager.getRotationMatrixFromVector(rotationMatrix, vectors); int worldAxisX = SensorManager.AXIS_X; int worldAxisY = SensorManager.AXIS_Y; float[] adjustedRotationMatrix = new float[9]; SensorManager.remapCoordinateSystem(rotationMatrix, worldAxisX, worldAxisY, adjustedRotationMatrix); float[] orientation = new float[3]; SensorManager.getOrientation(adjustedRotationMatrix, orientation); float pitch = (orientation[2] * FROM_RADS_TO_DEGS * -1) / AMPLIFICATION; float roll = (orientation[1] * FROM_RADS_TO_DEGS) / AMPLIFICATION; mSensorRoll = roll; mSensorPitch = pitch; updateFlightData(); }
Example 2
Source File: LocationProvider.java From open-location-code with Apache License 2.0 | 6 votes |
/** * Read the screen rotation so we can correct the device heading. */ @SuppressWarnings("SuspiciousNameCombination") private void readDisplayRotation() { mAxisX = SensorManager.AXIS_X; mAxisY = SensorManager.AXIS_Y; switch (mDisplay.getRotation()) { case Surface.ROTATION_0: break; case Surface.ROTATION_90: mAxisX = SensorManager.AXIS_Y; mAxisY = SensorManager.AXIS_MINUS_X; break; case Surface.ROTATION_180: mAxisY = SensorManager.AXIS_MINUS_Y; break; case Surface.ROTATION_270: mAxisX = SensorManager.AXIS_MINUS_Y; mAxisY = SensorManager.AXIS_X; break; default: break; } }
Example 3
Source File: CompassActivity.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 5 votes |
private float[] calculateOrientation(float[] values) { float[] rotationMatrix = new float[9]; float[] remappedMatrix = new float[9]; float[] orientation = new float[3]; // Determine the rotation matrix SensorManager.getRotationMatrixFromVector(rotationMatrix, values); // Remap the coordinates based on the natural device orientation. int x_axis = SensorManager.AXIS_X; int y_axis = SensorManager.AXIS_Y; switch (mScreenRotation) { case (Surface.ROTATION_90): x_axis = SensorManager.AXIS_Y; y_axis = SensorManager.AXIS_MINUS_X; break; case (Surface.ROTATION_180): y_axis = SensorManager.AXIS_MINUS_Y; break; case (Surface.ROTATION_270): x_axis = SensorManager.AXIS_MINUS_Y; y_axis = SensorManager.AXIS_X; break; default: break; } SensorManager.remapCoordinateSystem(rotationMatrix, x_axis, y_axis, remappedMatrix); // Obtain the current, corrected orientation. SensorManager.getOrientation(remappedMatrix, orientation); // Convert from Radians to Degrees. values[0] = (float) Math.toDegrees(orientation[0]); values[1] = (float) Math.toDegrees(orientation[1]); values[2] = (float) Math.toDegrees(orientation[2]); return values; }
Example 4
Source File: MainActivity.java From Wrox-ProfessionalAndroid-4E with Apache License 2.0 | 5 votes |
private void listing16_14() { float[] values = new float[3]; float[] inR = new float[9]; float[] outR = new float[9]; SensorManager.getRotationMatrix(inR, null, mAccelerometerValues, mMagneticFieldValues); // Listing 16-14: Remapping the orientation reference frame based on the natural orientation of the device // Determine the current orientation relative to the natural orientation WindowManager wm = (WindowManager) getSystemService(Context.WINDOW_SERVICE); Display display = wm.getDefaultDisplay(); int rotation = display.getRotation(); int x_axis = SensorManager.AXIS_X; int y_axis = SensorManager.AXIS_Y; switch (rotation) { case (Surface.ROTATION_0): break; case (Surface.ROTATION_90): x_axis = SensorManager.AXIS_Y; y_axis = SensorManager.AXIS_MINUS_X; break; case (Surface.ROTATION_180): y_axis = SensorManager.AXIS_MINUS_Y; break; case (Surface.ROTATION_270): x_axis = SensorManager.AXIS_MINUS_Y; y_axis = SensorManager.AXIS_X; break; default: break; } SensorManager.remapCoordinateSystem(inR, x_axis, y_axis, outR); // Obtain the new, remapped, orientation values. SensorManager.getOrientation(outR, values); }
Example 5
Source File: AndroidSensorJoyInput.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
private boolean remapCoordinates(float[] inR, float[] outR) { int xDir = SensorManager.AXIS_X; int yDir = SensorManager.AXIS_Y; int curRotation = getScreenRotation(); if (lastRotation != curRotation) { logger.log(Level.FINE, "Device Rotation changed to: {0}", curRotation); } lastRotation = curRotation; // logger.log(Level.FINE, "Screen Rotation: {0}", getScreenRotation()); switch (getScreenRotation()) { // device natural position case Surface.ROTATION_0: xDir = SensorManager.AXIS_X; yDir = SensorManager.AXIS_Y; break; // device rotated 90 deg counterclockwise case Surface.ROTATION_90: xDir = SensorManager.AXIS_Y; yDir = SensorManager.AXIS_MINUS_X; break; // device rotated 180 deg counterclockwise case Surface.ROTATION_180: xDir = SensorManager.AXIS_MINUS_X; yDir = SensorManager.AXIS_MINUS_Y; break; // device rotated 270 deg counterclockwise case Surface.ROTATION_270: xDir = SensorManager.AXIS_MINUS_Y; yDir = SensorManager.AXIS_X; break; default: break; } return SensorManager.remapCoordinateSystem(inR, xDir, yDir, outR); }
Example 6
Source File: ShaderRenderer.java From ShaderEditor with MIT License | 4 votes |
private void setRotationMatrix() { boolean haveInclination = false; if (gravityListener != null && magneticFieldListener != null && SensorManager.getRotationMatrix( rotationMatrix, inclinationMatrix, gravityValues, magneticFieldListener.filtered)) { haveInclination = true; } else if (rotationVectorListener != null) { SensorManager.getRotationMatrixFromVector( rotationMatrix, rotationVectorListener.values); } else { return; } if (deviceRotation != 0) { int x = SensorManager.AXIS_Y; int y = SensorManager.AXIS_MINUS_X; switch (deviceRotation) { default: break; case 270: x = SensorManager.AXIS_MINUS_Y; y = SensorManager.AXIS_X; break; } SensorManager.remapCoordinateSystem( rotationMatrix, x, y, rotationMatrix); } if (rotationMatrixLoc > -1) { GLES20.glUniformMatrix3fv(rotationMatrixLoc, 1, true, rotationMatrix, 0); } if (orientationLoc > -1) { SensorManager.getOrientation(rotationMatrix, orientation); GLES20.glUniform3fv(orientationLoc, 1, orientation, 0); } if (inclinationMatrixLoc > -1 && haveInclination) { GLES20.glUniformMatrix3fv(inclinationMatrixLoc, 1, true, inclinationMatrix, 0); } if (inclinationLoc > -1 && haveInclination) { GLES20.glUniform1f(inclinationLoc, SensorManager.getInclination(inclinationMatrix)); } }