本文整理了Java中android.hardware.SensorManager.getRotationMatrix()
方法的一些代码示例,展示了SensorManager.getRotationMatrix()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SensorManager.getRotationMatrix()
方法的具体详情如下:
包路径:android.hardware.SensorManager
类名称:SensorManager
方法名:getRotationMatrix
暂无
代码示例来源:origin: libgdx/libgdx
/** Returns the rotation matrix describing the devices rotation as per <a href=
* "http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix(float[], float[], float[], float[])"
* >SensorManager#getRotationMatrix(float[], float[], float[], float[])</a>. Does not manipulate the matrix if the platform
* does not have an accelerometer and compass, or a rotation vector sensor.
* @param matrix */
public void getRotationMatrix (float[] matrix) {
if (rotationVectorAvailable)
SensorManager.getRotationMatrixFromVector(matrix, rotationVectorValues);
else // compass + accelerometer
SensorManager.getRotationMatrix(matrix, null, accelerometerValues, magneticFieldValues);
}
代码示例来源:origin: aporter/coursera-android
boolean success = SensorManager.getRotationMatrix(rotationMatrix,
null, mGravity, mGeomagnetic);
代码示例来源: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: libgdx/libgdx
/** Returns the rotation matrix describing the devices rotation as per <a href=
* "http://developer.android.com/reference/android/hardware/SensorManager.html#getRotationMatrix(float[], float[], float[], float[])"
* >SensorManager#getRotationMatrix(float[], float[], float[], float[])</a>. Does not manipulate the matrix if the platform
* does not have an accelerometer and compass, or a rotation vector sensor.
* @param matrix */
public void getRotationMatrix (float[] matrix) {
if (rotationVectorAvailable)
SensorManager.getRotationMatrixFromVector(matrix, rotationVectorValues);
else // compass + accelerometer
SensorManager.getRotationMatrix(matrix, null, accelerometerValues, magneticFieldValues);
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
if (SensorManager.getRotationMatrix(curRotationMat, curInclinationMat, accValues, magValues)) {
final float [] orientValues = new float[3];
if (remapCoordinates(curRotationMat, rotatedRotationMat)) {
代码示例来源: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
float[] R = new float[9];
float[] I = new float[9];
boolean success = SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic);
if (success) {
float[] orientationData = new float[3];
代码示例来源: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: 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: StevenRudenko/BleSensorTag
public void calculateAccMagOrientation() {
if (SensorManager.getRotationMatrix(rotationMatrix, null, accel, magnet)) {
SensorManager.getOrientation(rotationMatrix, accMagOrientation);
}
}
代码示例来源: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: 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: apacha/sensor-fusion-demo
@Override
public void onSensorChanged(SensorEvent event) {
// we received a sensor event. it is a good practice to check
// that we received the proper event
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
System.arraycopy(event.values, 0, magnitudeValues, 0, magnitudeValues.length);
} else if (event.sensor.getType() == Sensor.TYPE_GRAVITY) {
System.arraycopy(event.values, 0, gravityValues, 0, gravityValues.length);
}
if (magnitudeValues != null && gravityValues != null) {
// Fuse gravity-sensor (virtual sensor) with compass
SensorManager.getRotationMatrix(currentOrientationRotationMatrix.matrix, inclinationValues, gravityValues, magnitudeValues);
// Transform rotation matrix to quaternion
currentOrientationQuaternion.setRowMajor(currentOrientationRotationMatrix.matrix);
}
}
}
代码示例来源:origin: apacha/sensor-fusion-demo
@Override
public void onSensorChanged(SensorEvent event) {
// we received a sensor event. it is a good practice to check
// that we received the proper event
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
System.arraycopy(event.values, 0, magnitudeValues, 0, magnitudeValues.length);
} else if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
System.arraycopy(event.values, 0, accelerometerValues, 0, accelerometerValues.length);
}
if (magnitudeValues != null && accelerometerValues != null) {
// Fuse accelerometer with compass
SensorManager.getRotationMatrix(currentOrientationRotationMatrix.matrix, inclinationValues, accelerometerValues,
magnitudeValues);
// Transform rotation matrix to quaternion
currentOrientationQuaternion.setRowMajor(currentOrientationRotationMatrix.matrix);
}
}
}
代码示例来源: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);
}
}
代码示例来源:origin: Fewlaps/flone-android
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
mGravity = event.values;
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
mGeomagnetic = event.values;
if (mGravity != null && mGeomagnetic != null) {
boolean success = SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic);
if (success) {
SensorManager.getOrientation(R, orientation);
}
}
setHeading(restrictAngle((int) Math.toDegrees((double) orientation[0])));
setPitch(restrictAngle((int) Math.toDegrees((double) orientation[2])));
setRoll(restrictAngle((int) Math.toDegrees((double) orientation[1])));
EventBus.getDefault().post(new PhoneSensorsData(heading, pitch, roll));
}
代码示例来源:origin: Phantast/smartnavi
public void calculateAzimuth() {
SensorManager.getRotationMatrix(RMatrix, iMatrix, gravity, magn);
SensorManager.remapCoordinateSystem(RMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Y, RMatrixRemapped);
SensorManager.getOrientation(RMatrixRemapped, orientation);
Matrix.transposeM(RMatrixTranspose, 0, RMatrix, 0);
Matrix.multiplyMV(linearRemapped, 0, RMatrixTranspose, 0, linear, 0);
//If Gyroscope exists, use ImprovedOrientationProvider, else use accelerometer and magentic field
if (gyroExists) {
azimuth = mOrientationProvider.getAzimuth(decl);
} else {
if (orientation[0] >= 0) {
// Azimuth-Calculation (rad in degree)
azimuth = (orientation[0] * 57.29577951f + decl);
} else {
// Azimuth-Calculation (rad in degree) +360
azimuth = (orientation[0] * 57.29577951f + 360 + decl);
}
if (azimuth >= 360) {
azimuth -= 360;
}
}
}
代码示例来源:origin: dozingcat/Vector-Pinball
/**
* SensorEventListener method called when sensor values are updated. Reads gravitational and
* magnetic field information, and when both are available computes the orientation values
* and calls the delegate with them.
*/
@Override public void onSensorChanged(SensorEvent event) {
switch(event.sensor.getType()) {
case Sensor.TYPE_MAGNETIC_FIELD:
mags = event.values.clone();
break;
case Sensor.TYPE_ACCELEROMETER:
accels = event.values.clone();
break;
}
if (mags!=null && accels!=null) {
SensorManager.getRotationMatrix(R, I, accels, mags);
SensorManager.getOrientation(R, orientationValues);
delegate.receivedOrientationValues(
orientationValues[0], orientationValues[1], orientationValues[2]);
}
}
代码示例来源:origin: KalebKE/FSensor
/**
* Calculates orientation vector from accelerometer and magnetometer output.
*
* @param acceleration the acceleration measurement.
* @param magnetic the magnetic measurement.
* @return
*/
public static Quaternion getOrientationVectorFromAccelerationMagnetic(float[] acceleration, float[] magnetic) {
float[] rotationMatrix = new float[9];
if (SensorManager.getRotationMatrix(rotationMatrix, null, acceleration, magnetic)) {
float[] rv = new float[3];
SensorManager.getOrientation(rotationMatrix,rv);
// SensorManager.getOrientation() returns an orientation in Earth frame and that needs to be rotated into device frame so the reported angles
// are indexed with the orientation of the sensors
Rotation rotation = new Rotation(RotationOrder.XYZ, RotationConvention.VECTOR_OPERATOR, rv[1], -rv[2], rv[0]);
return new Quaternion(rotation.getQ0(), rotation.getQ1(),rotation.getQ2(),rotation.getQ3());
}
return null;
}
内容来源于网络,如有侵权,请联系作者删除!