大佬教程收集整理的这篇文章主要介绍了android – 指南针方向因手机方向而异,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
然而,我发现结果值取决于手机方向 – 旋转到右侧的景观与旋转到左侧的景观大约相差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 – 指南针方向因手机方向而异所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。