List of usage examples for android.hardware SensorManager AXIS_Y
int AXIS_Y
To view the source code for android.hardware SensorManager AXIS_Y.
Click Source Link
From source file:Main.java
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;// w w w .ja v a 2 s .c o m 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); }
From source file:Main.java
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;//from www . j a va2 s. com 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); }
From source file:Main.java
public static void sensorRotationVector2Matrix(SensorEvent event, int rotation, float[] output) { if (!sIsTruncated) { try {/* ww w . ja va 2 s . com*/ SensorManager.getRotationMatrixFromVector(sUIThreadTmp, event.values); } catch (Exception e) { // On some Samsung devices, SensorManager#getRotationMatrixFromVector throws an exception // if the rotation vector has more than 4 elements. Since only the four first elements are used, // we can truncate the vector without losing precision. Log.e(TAG, "maybe Samsung bug, will truncate vector"); sIsTruncated = true; } } if (sIsTruncated) { System.arraycopy(event.values, 0, sTruncatedVector, 0, 4); SensorManager.getRotationMatrixFromVector(sUIThreadTmp, sTruncatedVector); } 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(sUIThreadTmp, values); SensorManager.remapCoordinateSystem(sUIThreadTmp, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, output); break; case Surface.ROTATION_270: SensorManager.getRotationMatrixFromVector(sUIThreadTmp, values); SensorManager.remapCoordinateSystem(sUIThreadTmp, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_X, output); break; } Matrix.rotateM(output, 0, 90.0F, 1.0F, 0.0F, 0.0F); }
From source file:com.tritop.androsense2.fragments.GpsFragment.java
@Override public void onSensorChanged(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { mAccel = event.values;/*from w ww . j ava 2 s .c o m*/ } if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { mMag = event.values; } if ((mAccel != null) && (mMag != null)) { float R[] = new float[9]; float I[] = new float[9]; float Rot[] = new float[9]; if (SensorManager.getRotationMatrix(R, I, mAccel, mMag)) { float orientation[] = new float[3]; int axisX = 0, axisY = 0; switch (display.getRotation()) { case Surface.ROTATION_0: axisX = SensorManager.AXIS_X; axisY = SensorManager.AXIS_Y; break; case Surface.ROTATION_90: axisX = SensorManager.AXIS_Y; axisY = SensorManager.AXIS_MINUS_X; break; case Surface.ROTATION_180: axisX = SensorManager.AXIS_MINUS_X; axisY = SensorManager.AXIS_MINUS_Y; break; case Surface.ROTATION_270: axisX = SensorManager.AXIS_MINUS_Y; axisY = SensorManager.AXIS_X; break; default: break; } SensorManager.remapCoordinateSystem(R, axisX, axisY, Rot); SensorManager.getOrientation(Rot, orientation); aRotation = orientation[0]; aRotation = (int) Math.toDegrees(aRotation); satView.setAzimutRotation(-aRotation); satView.invalidate(); } } }
From source file:com.metinkale.prayerapp.compass.Main.java
@Override public void onRotationUpdate(float[] newMatrix) { if (mMode == Mode.Map) { return;// w ww . java2s .c om } // remap matrix values according to display rotation, as in // SensorManager documentation. switch (mDisplayRotation) { case Surface.ROTATION_0: case Surface.ROTATION_180: break; case Surface.ROTATION_90: SensorManager.remapCoordinateSystem(newMatrix, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, newMatrix); break; case Surface.ROTATION_270: SensorManager.remapCoordinateSystem(newMatrix, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_X, newMatrix); break; default: break; } mRotationMatrix.set(newMatrix); mOrientationCalculator.getOrientation(mRotationMatrix, mDisplayRotation, mDerivedDeviceOrientation); updateFrag((mDerivedDeviceOrientation[1] > -55f) ? Mode.ThreeDim : Mode.TwoDim); mList.onUpdateSensors(mDerivedDeviceOrientation); }
From source file:com.shadowmaps.example.GpsTestActivity.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD) @Override/*w ww. j a va 2 s. c o m*/ public void onSensorChanged(SensorEvent event) { double orientation = Double.NaN; double tilt = Double.NaN; switch (event.sensor.getType()) { case Sensor.TYPE_ROTATION_VECTOR: // Modern rotation vector sensors if (!mTruncateVector) { try { SensorManager.getRotationMatrixFromVector(mRotationMatrix, event.values); } catch (IllegalArgumentException e) { // On some Samsung devices, an exception is thrown if this vector > 4 (see #39) // Truncate the array, since we can deal with only the first four values Log.e(TAG, "Samsung device error? Will truncate vectors - " + e); mTruncateVector = true; // Do the truncation here the first time the exception occurs getRotationMatrixFromTruncatedVector(event.values); } } else { // Truncate the array to avoid the exception on some devices (see #39) getRotationMatrixFromTruncatedVector(event.values); } int rot = getWindowManager().getDefaultDisplay().getRotation(); switch (rot) { case Surface.ROTATION_0: // No orientation change, use default coordinate system SensorManager.getOrientation(mRotationMatrix, mValues); // Log.d(TAG, "Rotation-0"); break; case Surface.ROTATION_90: // Log.d(TAG, "Rotation-90"); SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, mRemappedMatrix); SensorManager.getOrientation(mRemappedMatrix, mValues); break; case Surface.ROTATION_180: // Log.d(TAG, "Rotation-180"); SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_MINUS_X, SensorManager.AXIS_MINUS_Y, mRemappedMatrix); SensorManager.getOrientation(mRemappedMatrix, mValues); break; case Surface.ROTATION_270: // Log.d(TAG, "Rotation-270"); SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_X, mRemappedMatrix); SensorManager.getOrientation(mRemappedMatrix, mValues); break; default: // This shouldn't happen - assume default orientation SensorManager.getOrientation(mRotationMatrix, mValues); // Log.d(TAG, "Rotation-Unknown"); break; } orientation = Math.toDegrees(mValues[0]); // azimuth tilt = Math.toDegrees(mValues[1]); break; case Sensor.TYPE_ORIENTATION: // Legacy orientation sensors orientation = event.values[0]; break; default: // A sensor we're not using, so return return; } // Correct for true north, if preference is set if (mFaceTrueNorth && mGeomagneticField != null) { orientation += mGeomagneticField.getDeclination(); } for (GpsTestListener listener : mGpsTestListeners) { listener.onOrientationChanged(orientation, tilt); } }
From source file:com.android.gpstest.GpsTestActivity.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD) @Override/*w ww.java 2 s .c o m*/ public void onSensorChanged(SensorEvent event) { double orientation = Double.NaN; double tilt = Double.NaN; switch (event.sensor.getType()) { case Sensor.TYPE_ROTATION_VECTOR: // Modern rotation vector sensors if (!mTruncateVector) { try { SensorManager.getRotationMatrixFromVector(mRotationMatrix, event.values); } catch (IllegalArgumentException e) { // On some Samsung devices, an exception is thrown if this vector > 4 (see #39) // Truncate the array, since we can deal with only the first four values Log.e(TAG, "Samsung device error? Will truncate vectors - " + e); mTruncateVector = true; // Do the truncation here the first time the exception occurs getRotationMatrixFromTruncatedVector(event.values); } } else { // Truncate the array to avoid the exception on some devices (see #39) getRotationMatrixFromTruncatedVector(event.values); } int rot = getWindowManager().getDefaultDisplay().getRotation(); switch (rot) { case Surface.ROTATION_0: // No orientation change, use default coordinate system SensorManager.getOrientation(mRotationMatrix, mValues); // Log.d(TAG, "Rotation-0"); break; case Surface.ROTATION_90: // Log.d(TAG, "Rotation-90"); SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, mRemappedMatrix); SensorManager.getOrientation(mRemappedMatrix, mValues); break; case Surface.ROTATION_180: // Log.d(TAG, "Rotation-180"); SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_MINUS_X, SensorManager.AXIS_MINUS_Y, mRemappedMatrix); SensorManager.getOrientation(mRemappedMatrix, mValues); break; case Surface.ROTATION_270: // Log.d(TAG, "Rotation-270"); SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_X, mRemappedMatrix); SensorManager.getOrientation(mRemappedMatrix, mValues); break; default: // This shouldn't happen - assume default orientation SensorManager.getOrientation(mRotationMatrix, mValues); // Log.d(TAG, "Rotation-Unknown"); break; } orientation = Math.toDegrees(mValues[0]); // azimuth tilt = Math.toDegrees(mValues[1]); break; case Sensor.TYPE_ORIENTATION: // Legacy orientation sensors orientation = event.values[0]; break; default: // A sensor we're not using, so return return; } // Correct for true north, if preference is set if (mFaceTrueNorth && mGeomagneticField != null) { orientation += mGeomagneticField.getDeclination(); // Make sure value is between 0-360 orientation = MathUtils.mod((float) orientation, 360.0f); } for (GpsTestListener listener : mGpsTestListeners) { listener.onOrientationChanged(orientation, tilt); } }
From source file:com.example.zoetablet.BasicFragmentActivity.java
public float[] calculateOrientation() { float[] values = new float[3]; float[] R = new float[9]; float[] outR = new float[9]; SensorManager.getRotationMatrix(R, null, aValues, mValues); SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_X, SensorManager.AXIS_Y, outR); SensorManager.getOrientation(outR, values); // Convert from Radians to Degrees. values[0] = (float) Math.toDegrees(values[0]); values[1] = (float) Math.toDegrees(values[1]); values[2] = (float) Math.toDegrees(values[2]); // System.out.println("Compass " + values[0] + " " + values[1] + " " + values[2]); if (values[0] != 0.0 && values[1] != 0.0) { compassV0 = values[0];//ww w .j a va 2 s .c o m compassV1 = values[1]; compassV2 = values[2]; } if (values[0] == 0.0 && values[1] == 0.0) { //If data is spitting out zeros, keep last good value values[0] = compassV0; values[1] = compassV1; values[2] = compassV2; } return values; }
From source file:org.mixare.MixViewActivity.java
public void onSensorChanged(SensorEvent evt) { try {//w ww. j a va 2s . co m if (getMixViewData().getSensorGyro() != null) { if (evt.sensor.getType() == Sensor.TYPE_GYROSCOPE) { getMixViewData().setGyro(evt.values); } if (evt.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { getMixViewData().setGrav( getMixViewData().getGravFilter().lowPassFilter(evt.values, getMixViewData().getGrav())); } else if (evt.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { getMixViewData().setMag( getMixViewData().getMagFilter().lowPassFilter(evt.values, getMixViewData().getMag())); } getMixViewData().setAngle(getMixViewData().getMagFilter().complementaryFilter( getMixViewData().getGrav(), getMixViewData().getGyro(), 30, getMixViewData().getAngle())); SensorManager.getRotationMatrix(getMixViewData().getRTmp(), getMixViewData().getI(), getMixViewData().getGrav(), getMixViewData().getMag()); } else { if (evt.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { getMixViewData().setGrav(evt.values); } else if (evt.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { getMixViewData().setMag(evt.values); } SensorManager.getRotationMatrix(getMixViewData().getRTmp(), getMixViewData().getI(), getMixViewData().getGrav(), getMixViewData().getMag()); } // augmentedView.postInvalidate(); hudView.postInvalidate(); projectedMapView.postInvalidate(); int rotation = Compatibility.getRotation(this); if (rotation == 1) { SensorManager.remapCoordinateSystem(getMixViewData().getRTmp(), SensorManager.AXIS_X, SensorManager.AXIS_MINUS_Z, getMixViewData().getRot()); } else { SensorManager.remapCoordinateSystem(getMixViewData().getRTmp(), SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_Z, getMixViewData().getRot()); } getMixViewData().getTempR().set(getMixViewData().getRot()[0], getMixViewData().getRot()[1], getMixViewData().getRot()[2], getMixViewData().getRot()[3], getMixViewData().getRot()[4], getMixViewData().getRot()[5], getMixViewData().getRot()[6], getMixViewData().getRot()[7], getMixViewData().getRot()[8]); getMixViewData().getFinalR().toIdentity(); getMixViewData().getFinalR().prod(getMixViewData().getM4()); getMixViewData().getFinalR().prod(getMixViewData().getM1()); getMixViewData().getFinalR().prod(getMixViewData().getTempR()); getMixViewData().getFinalR().prod(getMixViewData().getM3()); getMixViewData().getFinalR().prod(getMixViewData().getM2()); getMixViewData().getFinalR().invert(); getMixViewData().getHistR()[getMixViewData().getrHistIdx()].set(getMixViewData().getFinalR()); int histRLenght = getMixViewData().getHistR().length; getMixViewData().setrHistIdx(getMixViewData().getrHistIdx() + 1); if (getMixViewData().getrHistIdx() >= histRLenght) getMixViewData().setrHistIdx(0); getMixViewData().getSmoothR().set(0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f, 0f); for (int i = 0; i < histRLenght; i++) { getMixViewData().getSmoothR().add(getMixViewData().getHistR()[i]); } getMixViewData().getSmoothR().mult(1 / (float) histRLenght); MixContext.getInstance().updateSmoothRotation(getMixViewData().getSmoothR()); // float[] orientation = new float[3]; // float[] rTemp = getMixViewData().getRTmp(); // SensorManager.getOrientation(rTemp, orientation); // Log.d("PROJECT_MAP", "Sensor Angles"); // Log.d("PROJECT_MAP", orientation[0] + ", " + orientation[1] + ", " + orientation[2]); // Log.d("PROJECT_MAP", "Rotation Matrix Before Smoothing"); // Log.d("PROJECT_MAP", rTemp[0] + ", " + rTemp[1] + ", " + rTemp[2]); // Log.d("PROJECT_MAP", rTemp[3] + ", " + rTemp[4] + ", " + rTemp[5]); // Log.d("PROJECT_MAP", rTemp[6] + ", " + rTemp[7] + ", " + rTemp[8]); } catch (Exception ex) { ex.printStackTrace(); } }