android – 指南针方向因手机方向而异

android – 指南针方向因手机方向而异,第1张

概述我的增强现实应用程序需要摄像机视图的罗盘方位,并且有很多从传感器管理器获取方向的示例. 然而,我发现结果值取决于手机方向 – 旋转到右侧的景观与旋转到左侧的景观大约相差10度(ROTATION_0和ROTATION_180之间的差异较小,但仍然不同).这种差异足以破坏任何AR效应. 它与校准有关吗? (我不相信我正在做正确的8件事 – 我尝试过在youtube上找到的各种方法). 任何想法为何有区 我的增强现实应用程序需要摄像机视图的罗盘方位,并且有很多从传感器管理器获取方向的示例.

然而,我发现结果值取决于手机方向 – 旋转到右侧的景观与旋转到左侧的景观大约相差10度(ROTATION_0和ROTATION_180之间的差异较小,但仍然不同).这种差异足以破坏任何AR效应.

它与校准有关吗? (我不相信我正在做正确的8件事 – 我尝试过在youtube上找到的各种方法).

任何想法为何有区别?我搞砸了旋转矩阵的东西吗?我可以选择将应用程序限制为单一方向,但仍然担心罗盘读数仍然不是很准确(即使过滤后它相当稳定)

public voID onSensorChanged(SensorEvent event) {        if (event.accuracy == SensorManager.SENSOR_STATUS_UNREliABLE) {            return;        }        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[] rotationMatrixA = mRotationMatrixA;            if (SensorManager.getRotationMatrix(rotationMatrixA,null,mGravity,mGeomagnetic)) {                float[] rotationMatrixB = mRotationMatrixB;                display display = getwindowManager().getDefaultdisplay();                 int deviceRot = display.getRotation();                switch (deviceRot)                {                // portrait - normal                case Surface.ROTATION_0: SensorManager.remapCoordinateSystem(rotationMatrixA,SensorManager.AXIS_X,SensorManager.AXIS_Z,rotationMatrixB);                break;                // rotated left (landscape - keys to bottom)                case Surface.ROTATION_90: SensorManager.remapCoordinateSystem(rotationMatrixA,SensorManager.AXIS_MINUS_X,rotationMatrixB);                 break;                // upsIDe down                case Surface.ROTATION_180: SensorManager.remapCoordinateSystem(rotationMatrixA,rotationMatrixB);                 break;                // rotated right                case Surface.ROTATION_270: SensorManager.remapCoordinateSystem(rotationMatrixA,SensorManager.AXIS_MINUS_Z,rotationMatrixB);                 break;                default:  break;                }                float[] dv = new float[3];                 SensorManager.getorIEntation(rotationMatrixB,dv);                // add to smoothing filter                fd.AddLatest((double)dv[0]);             }            mDraw.invalIDate();             }    }
解决方法 试试这个
public voID onSensorChanged(SensorEvent event) {    if (event.accuracy == SensorManager.SENSOR_STATUS_UNREliABLE) {        return;    }    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)  mGravity = event.values.clone ();    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) mGeomagnetic =  event.values.clone ();    if (mGravity != null && mGeomagnetic != null) {        float[] rotationMatrixA = mRotationMatrixA;        if (SensorManager.getRotationMatrix(rotationMatrixA,mGeomagnetic)) {            float[] rotationMatrixB = mRotationMatrixB;            SensorManager.remapCoordinateSystem(rotationMatrixA,rotationMatrixB);            float[] dv = new float[3];             SensorManager.getorIEntation(rotationMatrixB,dv);            // add to smoothing filter            fd.AddLatest((double)dv[0]);         }        mDraw.invalIDate();         }}

你不需要switch语句,似乎有很多关于getRotationMatrix,remapCoordinateSystem和来自stackoverflow问题的getorIEntation的混淆.我可能会在不久的将来写下这些的详细解释.

总结

以上是内存溢出为你收集整理的android – 指南针方向因手机方向而异全部内容,希望文章能够帮你解决android – 指南针方向因手机方向而异所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1145322.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存