private void updateOrientation () { if (rotationVectorAvailable){ SensorManager.getRotationMatrixFromVector(R, rotationVectorValues); } else if (!SensorManager.getRotationMatrix(R, null, accelerometerValues, magneticFieldValues)) { return; // compass + accelerometer in free fall } SensorManager.getOrientation(R, orientation); azimuth = (float)Math.toDegrees(orientation[0]); pitch = (float)Math.toDegrees(orientation[1]); roll = (float)Math.toDegrees(orientation[2]); }
private void updateOrientation () { if (rotationVectorAvailable){ SensorManager.getRotationMatrixFromVector(R, rotationVectorValues); } else if (!SensorManager.getRotationMatrix(R, null, accelerometerValues, magneticFieldValues)) { return; // compass + accelerometer in free fall } SensorManager.getOrientation(R, orientation); azimuth = (float)Math.toDegrees(orientation[0]); pitch = (float)Math.toDegrees(orientation[1]); roll = (float)Math.toDegrees(orientation[2]); }
@Override protected void onSensorEvent(SensorEvent sensorEvent) { // Get rotation matrix float[] rotationMatrix = new float[16]; SensorManager.getRotationMatrixFromVector(rotationMatrix, sensorEvent.values); // Remap coordinate system float[] remappedRotationMatrix = new float[16]; SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z, remappedRotationMatrix); // Convert to orientations float[] orientations = new float[3]; SensorManager.getOrientation(remappedRotationMatrix, orientations); // Convert values in radian to degrees for (int i = 0; i < 3; i++) { orientations[i] = (float) (Math.toDegrees(orientations[i])); } rotationAngleListener.onRotation(orientations[0], orientations[1], orientations[2]); } }
SensorManager.getOrientation(rotationMatrix, orientationMatrix);
SensorManager.AXIS_MINUS_Z, remappedPhoneMatrix); SensorManager.getOrientation(remappedPhoneMatrix, angles); float roll = angles[2]; touchTracker.setRoll(roll);
private void updateSensorValues(SensorEvent event) { if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { setAcclValues(event); } else if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { setmagValues(event); } SensorManager.getRotationMatrix(rotation, null, grav, mag); SensorManager.getOrientation(rotation, orientation); double floatBearing = orientation[0]; floatBearing = Math.toDegrees(floatBearing); if (magField != null) floatBearing += magField.getDeclination(); if (floatBearing < 0) floatBearing += 360; setBearing(floatBearing); setRotationInDegrees(floatBearing); }
final float [] orientValues = new float[3]; if (remapCoordinates(curRotationMat, rotatedRotationMat)) { SensorManager.getOrientation(rotatedRotationMat, orientValues);
if (success) { float[] orientationData = new float[3]; SensorManager.getOrientation(R, orientationData); averagePitch = addValue(orientationData[1], pitches); averageRoll = addValue(orientationData[2], rolls);
@Override public void onSensorChanged(SensorEvent event) { if (listener == null) return; if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { geomagnetic = event.values.clone(); } else if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { gravity = event.values.clone(); } if (gravity != null && geomagnetic != null) { float R[] = new float[9]; float I[] = new float[9]; boolean success = SensorManager.getRotationMatrix(R, I, gravity, geomagnetic); if (success) { R = remapToDisplayRotation(R); float orientation[] = new float[3]; SensorManager.getOrientation(R, orientation); float azimut = orientation[0] - declination; float pitch = orientation[1]; float roll = orientation[2]; rotation = azimut; tilt = pitch; } } }
/** * Get the current rotation of the device in the Euler angles */ public void getEulerAngles(float angles[]) { synchronized (synchronizationToken) { SensorManager.getOrientation(currentOrientationRotationMatrix.matrix, angles); } } }
public void onSensorChanged(SensorEvent sensorEvent) { float[] rotationMatrix = new float[9]; float[] orientation = new float[3]; // Convert the result Vector to a Rotation Matrix. SensorManager.getRotationMatrixFromVector(rotationMatrix, sensorEvent.values); // Extract the orientation from the Rotation Matrix. SensorManager.getOrientation(rotationMatrix, orientation); Log.d(TAG, "Yaw: " + orientation[0]); // Yaw Log.d(TAG, "Pitch: " + orientation[1]); // Pitch Log.d(TAG, "Roll: " + orientation[2]); // Roll }
public void calculateAccMagOrientation() { if (SensorManager.getRotationMatrix(rotationMatrix, null, accel, magnet)) { SensorManager.getOrientation(rotationMatrix, accMagOrientation); } }
/** * @return Returns the current rotation of the device in the Euler-Angles */ public EulerAngles getEulerAngles() { synchronized (syncToken) { float[] angles = new float[3]; SensorManager.getOrientation(currentOrientationRotationMatrix.matrix, angles); return new EulerAngles(angles[0], angles[1], angles[2]); } } }
public float getAzimuth(float decl) { SensorManager.remapCoordinateSystem(currentOrientationRotationMatrix.matrix, SensorManager.AXIS_X, SensorManager.AXIS_Y, RMatrixRemapped); SensorManager.getOrientation(RMatrixRemapped, orientation); if (orientation[0] >= 0) { // Azimuth-Calculation (rad in degree) + difference to true north (decl) return (orientation[0] * 57.29577951f + decl); } else { // Azimuth-Calculation (rad in degree) +360 + difference to true north (decl) return (orientation[0] * 57.29577951f + 360 + decl); } } }
private void listing16_12() { // Listing 16-12: Finding the current orientation using the accelerometer and magnetometer float[] values = new float[3]; float[] R = new float[9]; SensorManager.getRotationMatrix(R, null, mAccelerometerValues, mMagneticFieldValues); SensorManager.getOrientation(R, values); // Convert from radians to degrees if preferred. values[0] = (float) Math.toDegrees(values[0]); // Azimuth values[1] = (float) Math.toDegrees(values[1]); // Pitch values[2] = (float) Math.toDegrees(values[2]); // Roll }
@Override public void onSensorChanged(SensorEvent event) { azimuthFrom = azimuthTo; float[] orientation = new float[3]; float[] rMat = new float[9]; SensorManager.getRotationMatrixFromVector(rMat, event.values); azimuthTo = (int) ( Math.toDegrees( SensorManager.getOrientation( rMat, orientation )[0] ) + 360 ) % 360; mAzimuthListener.onAzimuthChanged(azimuthFrom, azimuthTo); }
private void updateOrientationAngles() { SensorManager.getRotationMatrix(rotationMatrix, null, accelerometerReading, magnetometerReading); SensorManager.getOrientation(rotationMatrix, orientationAngles); beaconRadar.startDeviceAngleAnimation((float) Math.toDegrees(orientationAngles[0])); }
private void emitAzimuth() { if (gravity != null && geomagnetic != null) { boolean success = SensorManager.getRotationMatrix(rotationMatrix, null, gravity, geomagnetic); if (success) { SensorManager.getOrientation(rotationMatrix, rotationMatrixResult); emitData(rotationMatrixResult[0]); } } } }
private void updateCoordinate(float[] rotationVector) { SensorManager.getRotationMatrixFromVector(mRotationMatrix, rotationVector); SensorManager.remapCoordinateSystem(mRotationMatrix, mRemappedXAxis, mRemappedYAxis, mRemappedRotationMatrix); SensorManager.getOrientation(mRemappedRotationMatrix, mOrientationVals); if (mCurrentRotation == Surface.ROTATION_0) { //For some reasons, there is a difference of 100° on the Y coordinate //between landscape and portrait orientation. This is a poor //attempt at fixing this issue. mOrientationVals[2] -= 1.7453292519; } onSmoothCoordinateChanged(mOrientationVals.clone()); }
public void onSensorChanged(SensorEvent event) { if (event.accuracy == SensorManager.SENSOR_STATUS_ACCURACY_LOW) return; if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) { arrayCopy(event.values, geomagnetic); } if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) { arrayCopy(event.values, gravity); } if (SensorManager.getRotationMatrix(R, I, gravity, geomagnetic)) { SensorManager.getOrientation(R, orientation); azimuth += easing * (orientation[0] - azimuth); pitch += easing * (orientation[1] - pitch); roll += easing * (orientation[2] - roll); } }