当前位置: 首页>>代码示例>>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;未经允许,请勿转载。