android.hardware.SensorManager.getOrientation()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(8.4k)|赞(0)|评价(0)|浏览(311)

本文整理了Java中android.hardware.SensorManager.getOrientation()方法的一些代码示例,展示了SensorManager.getOrientation()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SensorManager.getOrientation()方法的具体详情如下:
包路径:android.hardware.SensorManager
类名称:SensorManager
方法名:getOrientation

SensorManager.getOrientation介绍

暂无

代码示例

代码示例来源:origin: libgdx/libgdx

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]);
}

代码示例来源:origin: libgdx/libgdx

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]);
}

代码示例来源:origin: nisrulz/sensey

@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]);
  }
}

代码示例来源:origin: aporter/coursera-android

SensorManager.getOrientation(rotationMatrix, orientationMatrix);

代码示例来源:origin: google/ExoPlayer

SensorManager.AXIS_MINUS_Z,
  remappedPhoneMatrix);
SensorManager.getOrientation(remappedPhoneMatrix, angles);
float roll = angles[2];
touchTracker.setRoll(roll);

代码示例来源:origin: novoda/android-demos

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);
}

代码示例来源:origin: jMonkeyEngine/jmonkeyengine

final float [] orientValues = new float[3];
if (remapCoordinates(curRotationMat, rotatedRotationMat)) {
  SensorManager.getOrientation(rotatedRotationMat, orientValues);

代码示例来源:origin: nisrulz/sensey

if (success) {
  float[] orientationData = new float[3];
  SensorManager.getOrientation(R, orientationData);
  averagePitch = addValue(orientationData[1], pitches);
  averageRoll = addValue(orientationData[2], rolls);

代码示例来源:origin: westnordost/StreetComplete

@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;
    }
  }
}

代码示例来源:origin: apacha/sensor-fusion-demo

/**
   * Get the current rotation of the device in the Euler angles
   */
  public void getEulerAngles(float angles[]) {
    synchronized (synchronizationToken) {
      SensorManager.getOrientation(currentOrientationRotationMatrix.matrix, angles);
    }
  }
}

代码示例来源:origin: retomeier/Wrox-ProfessionalAndroid-4E

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
}

代码示例来源:origin: StevenRudenko/BleSensorTag

public void calculateAccMagOrientation() {
  if (SensorManager.getRotationMatrix(rotationMatrix, null, accel, magnet)) {
    SensorManager.getOrientation(rotationMatrix, accMagOrientation);
  }
}

代码示例来源:origin: Phantast/smartnavi

/**
   * @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]);
    }
  }
}

代码示例来源:origin: Phantast/smartnavi

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);
    }

  }
}

代码示例来源:origin: retomeier/Wrox-ProfessionalAndroid-4E

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
}

代码示例来源:origin: lycha/augmented-reality-example

@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);
}

代码示例来源:origin: neXenio/BLE-Indoor-Positioning

private void updateOrientationAngles() {
  SensorManager.getRotationMatrix(rotationMatrix, null, accelerometerReading, magnetometerReading);
  SensorManager.getOrientation(rotationMatrix, orientationAngles);
  beaconRadar.startDeviceAngleAnimation((float) Math.toDegrees(orientationAngles[0]));
}

代码示例来源:origin: domsu/compass

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]);
      }
    }
  }
}

代码示例来源:origin: tvbarthel/ChaseWhisplyProject

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());
}

代码示例来源:origin: InnoFang/Android-Code-Demos

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);
  }
}

相关文章