當前位置: 首頁>>代碼示例>>Java>>正文


Java SensorManager.getAngleChange方法代碼示例

本文整理匯總了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;
}
 
開發者ID:hidetag,項目名稱:CheckIn,代碼行數:60,代碼來源:SensorTranslationUpdater.java

示例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;
}
 
開發者ID:alibaba,項目名稱:LuaViewPlayground,代碼行數:55,代碼來源:SensorInterpreter.java


注:本文中的android.hardware.SensorManager.getAngleChange方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。