本文整理匯總了Java中android.hardware.SensorManager.getAngleChange方法的典型用法代碼示例。如果您正苦於以下問題:Java SensorManager.getAngleChange方法的具體用法?Java SensorManager.getAngleChange怎麽用?Java SensorManager.getAngleChange使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.hardware.SensorManager
的用法示例。
在下文中一共展示了SensorManager.getAngleChange方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: interpretSensorEvent
import android.hardware.SensorManager; //導入方法依賴的package包/類
@Nullable
@SuppressWarnings("SuspiciousNameCombination")
private float[] interpretSensorEvent(@NonNull Context context, @Nullable SensorEvent event) {
if (event == null) {
return null;
}
float[] rotationVector = getRotationVectorFromSensorEvent(event);
if (!mTargeted) {
setTargetVector(rotationVector);
return null;
}
SensorManager.getRotationMatrixFromVector(mRotationMatrix, rotationVector);
final int rotation =
((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay()
.getRotation();
if (rotation == Surface.ROTATION_0) {
SensorManager.getAngleChange(mTiltVector, mRotationMatrix, mTargetMatrix);
} else {
switch (rotation) {
case Surface.ROTATION_90:
SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_Y,
SensorManager.AXIS_MINUS_X, mOrientedRotationMatrix);
break;
case Surface.ROTATION_180:
SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_MINUS_X,
SensorManager.AXIS_MINUS_Y, mOrientedRotationMatrix);
break;
case Surface.ROTATION_270:
SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_MINUS_Y,
SensorManager.AXIS_X, mOrientedRotationMatrix);
break;
default:
break;
}
SensorManager.getAngleChange(mTiltVector, mOrientedRotationMatrix, mTargetMatrix);
}
for (int i = 0; i < mTiltVector.length; i++) {
mTiltVector[i] /= Math.PI;
mTiltVector[i] *= mTiltSensitivity;
if (mTiltVector[i] > 1) {
mTiltVector[i] = 1f;
} else if (mTiltVector[i] < -1) {
mTiltVector[i] = -1f;
}
}
return mTiltVector;
}
示例2: interpretSensorEvent
import android.hardware.SensorManager; //導入方法依賴的package包/類
@SuppressWarnings("SuspiciousNameCombination")
public float[] interpretSensorEvent(@NonNull Context context, @Nullable SensorEvent event) {
if (event == null) {
return null;
}
float[] rotationVector = getRotationVectorFromSensorEvent(event);
if (!mTargeted) {
setTargetVector(rotationVector);
return null;
}
SensorManager.getRotationMatrixFromVector(mRotationMatrix, rotationVector);
final int rotation = ((WindowManager) context
.getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay()
.getRotation();
if (rotation == Surface.ROTATION_0) {
SensorManager.getAngleChange(mTiltVector, mRotationMatrix, mTargetMatrix);
} else {
switch (rotation) {
case Surface.ROTATION_90:
SensorManager.remapCoordinateSystem(mRotationMatrix, AXIS_Y, AXIS_MINUS_X, mOrientedRotationMatrix);
break;
case Surface.ROTATION_180:
SensorManager.remapCoordinateSystem(mRotationMatrix, AXIS_MINUS_X, AXIS_MINUS_Y, mOrientedRotationMatrix);
break;
case Surface.ROTATION_270:
SensorManager.remapCoordinateSystem(mRotationMatrix, AXIS_MINUS_Y, AXIS_X, mOrientedRotationMatrix);
break;
}
SensorManager.getAngleChange(mTiltVector, mOrientedRotationMatrix, mTargetMatrix);
}
for (int i = 0; i < mTiltVector.length; i++) {
mTiltVector[i] /= Math.PI;
mTiltVector[i] *= mTiltSensitivity;
if (mTiltVector[i] > 1) {
mTiltVector[i] = 1f;
} else if (mTiltVector[i] < -1) {
mTiltVector[i] = -1f;
}
}
return mTiltVector;
}