本文整理汇总了Java中android.hardware.SensorManager.getRotationMatrix方法的典型用法代码示例。如果您正苦于以下问题:Java SensorManager.getRotationMatrix方法的具体用法?Java SensorManager.getRotationMatrix怎么用?Java SensorManager.getRotationMatrix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.hardware.SensorManager
的用法示例。
在下文中一共展示了SensorManager.getRotationMatrix方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onSensorChanged
import android.hardware.SensorManager; //导入方法依赖的package包/类
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);
}
}
示例2: onSensorChanged
import android.hardware.SensorManager; //导入方法依赖的package包/类
/**
* 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]);
}
}
示例3: getBaseOrientation
import android.hardware.SensorManager; //导入方法依赖的package包/类
/**
* Calculates orientation angles from accelerometer and magnetometer output.
*/
protected float[] getBaseOrientation(float[] acceleration, float[] magnetic) {
// To get the orientation vector from the acceleration and magnetic
// sensors, we let Android do the heavy lifting. This call will
// automatically compensate for the tilt of the compass and fail if the
// magnitude of the acceleration is not close to 9.82m/sec^2. You could
// perform these steps yourself, but in my opinion, this is the best way
// to do it.
float[] rotationMatrix = new float[9];
if (SensorManager.getRotationMatrix(rotationMatrix, null, acceleration, magnetic)) {
float[] baseOrientation = new float[3];
SensorManager.getOrientation(rotationMatrix, baseOrientation);
return baseOrientation;
}
return null;
}
示例4: onSensorChanged
import android.hardware.SensorManager; //导入方法依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {
synchronized (this) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
lowPass(event.values, mGravity);
}
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
lowPass(event.values, mGeomagnetic);
}
float R[] = new float[9];
float I[] = new float[9];
if (SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic)) {
float orientation[] = new float[3];
SensorManager.getOrientation(R, orientation);
mOrientation[0] = (float)Math.toDegrees(orientation[0]);
adjustArrow();
}
}
}
示例5: onSensorChanged
import android.hardware.SensorManager; //导入方法依赖的package包/类
@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);
}
}
示例6: onSensorChanged
import android.hardware.SensorManager; //导入方法依赖的package包/类
public void onSensorChanged(SensorEvent sensorEvent) {
switch (sensorEvent.sensor.getType()) {
case 1:
this.g4 = sensorEvent.values;
break;
case 2:
this.g8 = sensorEvent.values;
break;
}
if (this.g4 != null && this.g8 != null) {
float[] fArr = new float[9];
if (SensorManager.getRotationMatrix(fArr, null, this.g4, this.g8)) {
float[] fArr2 = new float[3];
SensorManager.getOrientation(fArr, fArr2);
g5 = (float) Math.toDegrees((double) fArr2[0]);
g5 = (float) Math.floor(g5 >= 0.0f ? (double) g5 : (double) (g5 + 360.0f));
}
}
}
示例7: calculateOrientationAccelMag
import android.hardware.SensorManager; //导入方法依赖的package包/类
protected void calculateOrientationAccelMag()
{
// To get the orientation vector from the acceleration and magnetic
// sensors, we let Android do the heavy lifting. This call will
// automatically compensate for the tilt of the compass and fail if the
// magnitude of the acceleration is not close to 9.82m/sec^2. You could
// perform these steps yourself, but in my opinion, this is the best way
// to do it.
if (SensorManager.getRotationMatrix(rmOrientationAccelMag, null,
vAcceleration, vMagnetic)) //rmOrientationAccelMag涓烘棆杞煩闃点��
{
SensorManager.getOrientation(rmOrientationAccelMag,
vOrientationAccelMag); //vOrientationAccelMag涓鸿绠楁墍寰楃殑璁惧鏂瑰悜銆�
isOrientationValidAccelMag = true;
}
}
示例8: onSensorChanged
import android.hardware.SensorManager; //导入方法依赖的package包/类
public void onSensorChanged(SensorEvent event) {
int type = event.sensor.getType();
float[] data;
if (type == Sensor.TYPE_ACCELEROMETER) {
data = mGData;
} else if (type == Sensor.TYPE_MAGNETIC_FIELD) {
data = mMData;
} else {
// we should not be here.
return;
}
for (int i=0 ; i<3 ; i++)
data[i] = event.values[i];
SensorManager.getRotationMatrix(mR, mI, mGData, mMData);
// some test code which will be used/cleaned up before we ship this.
// SensorManager.remapCoordinateSystem(mR,
// SensorManager.AXIS_X, SensorManager.AXIS_Z, mR);
// SensorManager.remapCoordinateSystem(mR,
// SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, mR);
SensorManager.getOrientation(mR, mOrientation);
float incl = SensorManager.getInclination(mI);
if (mCount++ > 50) {
final float rad2deg = (float)(180.0f/Math.PI);
mCount = 0;
Log.d("Compass", "yaw: " + (int)(mOrientation[0]*rad2deg) +
" pitch: " + (int)(mOrientation[1]*rad2deg) +
" roll: " + (int)(mOrientation[2]*rad2deg) +
" incl: " + (int)(incl*rad2deg)
);
}
}
示例9: calculateOrientation
import android.hardware.SensorManager; //导入方法依赖的package包/类
private void calculateOrientation() {
// If phone doesn't have Rotation Vector sensor, calculate orientation based on Accelerometer and Magnetometer
if (SensorManager.getRotationMatrix(mAccMagMatrix, null, mAccel, mMagnet) && !hasRotationSensor) {
SensorManager.getOrientation(mAccMagMatrix, mOrientation);
} else {
SensorManager.getRotationMatrixFromVector(mRotationMatrixFromVector, mRotation);
SensorManager.getOrientation(mRotationMatrixFromVector, mOrientation);
}
// Calculate azimuth to detect direction
currentAzimuth = Math.toDegrees(mOrientation[0]);
// Only notify other receivers if there is a change in orientation greater than 2.0 degrees
if(Math.abs(currentAzimuth - preAzimuth) >= 2.0) {
announceChange(ANGLE_UPDATE);
preAzimuth = currentAzimuth;
}
}
示例10: calculateOrientation
import android.hardware.SensorManager; //导入方法依赖的package包/类
/**
* 计算方向
*
* @return
*/
private void calculateOrientation(float[] accValues, float[] magValues) {
float[] R = new float[9];
float[] values = new float[3];
SensorManager.getRotationMatrix(R, null, accValues, magValues);
SensorManager.getOrientation(R, values);
// 相反方向所以为负
newRotationDegree = (float) Math.toDegrees(values[0]);
}
示例11: onSensorChanged
import android.hardware.SensorManager; //导入方法依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
mGravity = event.values;
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED)
mGeomagnetic = event.values;
if ((mGravity == null) || (mGeomagnetic == null))
return;
float[] R = new float[9];
float[] I = new float[9];
if (!SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic))
return;
float[] orientation = new float[3];
SensorManager.getOrientation(R, orientation);
if (orientation == null)
return;
double rollAngle = orientation[1] * 180 / Math.PI;
double pitchAngle = orientation[2] * 180 / Math.PI;
if(notWithinAngleTolerance((int)rollAngle, mLastRoll))
this.mRollTextView.setText(String.format("%.0f", (rollAngle)));
if(notWithinAngleTolerance((int)pitchAngle,mLastPitch))
this.mPitchTextView.setText(String.format("%.0f", (pitchAngle)));
mLastPitch = (int)pitchAngle;
mLastRoll = (int) rollAngle;
calculateAndSetSpeed(rollAngle,pitchAngle);
}
示例12: updateScreenOrientation
import android.hardware.SensorManager; //导入方法依赖的package包/类
private void updateScreenOrientation() {
float[] R = new float[9];
float[] I = new float[9];
SensorManager.getRotationMatrix(R, I, gravity, geomagnetic);
float[] orientation = new float[3];
SensorManager.getOrientation(R, orientation);
//device rotation angle = pitch (first value) [clockwise from horizontal]
double pitch = orientation[1] / 2 / Math.PI * 360.0;
double roll = orientation[2] / 2 / Math.PI * 360.0;
double azimuth = orientation[0] / 2 / Math.PI * 360.0;
//If the phone is too close to the ground, don't update
if (Math.abs(roll) <= ROLL_MINIMUM)
return;
ScreenOrientation current = screenOrientation;
if (Math.abs(pitch) <= PITCH_TOLERANCE)
if (roll > 0.0f)
current = ScreenOrientation.LANDSCAPE_REVERSE;
else
current = ScreenOrientation.LANDSCAPE;
else if (Math.abs(pitch) >= PITCH_TOLERANCE_HIGH)
if (pitch > 0.0f)
current = ScreenOrientation.PORTRAIT_REVERSE;
else
current = ScreenOrientation.PORTRAIT;
screenOrientation = current;
}
示例13: getSensorsData
import android.hardware.SensorManager; //导入方法依赖的package包/类
private void getSensorsData(){
SensorManager.getRotationMatrix(sensorInitializer.getRotationMatrix(), null,
sensorInitializer.getAccelerationValues(), sensorInitializer.getMagneticValues());
SensorManager.getOrientation(sensorInitializer.getRotationMatrix(), sensorInitializer.getOrientationValues());
xSensorAxis = sensorInitializer.getOrientationValues()[1] * 57.3f * (-1);
ySensorAxis = sensorInitializer.getOrientationValues()[2] * 57.3f + 90.0f;
}
示例14: onSensorChanged
import android.hardware.SensorManager; //导入方法依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event)
{
displayCleanValues(); // display clean value of x,y,z accelerometer
if (event.sensor == mGyroscope) // Reading Gyroscope
{
gyro = event.values[1]; // Reading Gyroscope in Y -axies
}
else if (event.sensor == mAccelerometer) // Reading Accelerometer
{
System.arraycopy(event.values, 0, mLastAccelerometer, 0, event.values.length);
mLastAccelerometerSet = true;
Accel_X = Math.abs(event.values[0]); // Reading Acceleration in X-axis
Accel_Y = Math.abs(event.values[1]); // Reading Acceleration in Y-axis
Accel_Z = Math.abs(event.values[2]); // Reading Acceleration in Z-axis
}
else if (event.sensor == mMagnetometer) // Reading Magnetometer
{
System.arraycopy(event.values, 0, mLastMagnetometer, 0, event.values.length);
mLastMagnetometerSet = true;
}
if (mLastAccelerometerSet && mLastMagnetometerSet)
{
SensorManager.getRotationMatrix(mR, null, mLastAccelerometer, mLastMagnetometer);
SensorManager.getOrientation(mR, mOrientation);
azimuthInRadians = mOrientation[0]; // Reading Azimuth in radians
float azimuthInDegress = (float)(Math.toDegrees(azimuthInRadians)+360)%360; // Converting Azimuth to degrees
azimuth = azimuthInDegress;
}
adjust_values(); // Adjusting the reading of accelerometer and produce average values
calculate_pdr(); // Calculating position by Pedestrian Dead Reckoning (PDR)
displayCurrentValues(); // Display the current x,y,z accelerometer values
zigbee_correction_total();
}
示例15: onSensorChanged
import android.hardware.SensorManager; //导入方法依赖的package包/类
@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)
{
float R[] = new float[9];
float I[] = new float[9];
boolean success = SensorManager.getRotationMatrix(R,I,mGravity,mGeomagnetic);
if(success)
{
float orientation[] = new float[3];
SensorManager.getOrientation(R, orientation);
Log.e("NEW ORIENTATION---","---------------");
Log.e("orientation azimut", String.valueOf(orientation[0]*60));
Log.e("orientation pitch", String.valueOf(orientation[1]*60));
Log.e("orientation roll", String.valueOf(orientation[2]*60));
txt.setText("orientation azimut " + String.valueOf(orientation[0]*60) + "\n" + "orientation pitch" + String.valueOf(orientation[1]*60) + "\n" + "orientation roll"+ String.valueOf(orientation[2]*60));
}
}
}