我用前置摄像头和min3d库开发了一个增强现实应用程序。此应用程序在运行Android 4.0.4的三星Galaxy Tab 10、1(第一代)上运行良好。
但是,在带有Android4.1.1的ASUS变压器TF700T上测试同样的应用程序(仅限于景观模式),返回错误的方向,并且增强的世界不再与摄像机视图相匹配。
下面的代码用于获取target_axis和up_axis所需的定向向量min3D:
SensorManager.getRotationMatrix(mR, null, mLastAccelerometer, mLastMagnetometer);
SensorManager.getOrientation(mR, mOrientation);
Number3d target_axis = new Number3d( -mR[2], -mR[5], -mR[8] );
Number3d up_axis = new Number3d( mR[1], mR[4], mR[7] );
mLastAccelerometer和mLastMagnetometer是从onSensorChanged(SensorEvent事件)接收的。
有人能告诉我上面的代码是否仍然太依赖于设备吗?我希望使用SensorManager的gerOrientation调用这个解决方案应该可以在不同的设备上工作?
发布于 2013-09-26 13:40:21
最后,TF700的硬件出现了一些问题。在其他设备上,应用程序按预期工作。
发布于 2013-05-14 10:22:12
我的猜测是,这与设备的方向有关,即纵向、横向、reversePortrait、reverseLandscape等。您发布的代码肯定太幼稚了,因为它没有考虑设备相对于其默认方向的旋转。使用下面这样的方法来计算方位调整
int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
float screen_adjustment = 0;
switch(rotation) {
case Surface.ROTATION_0: screen_adjustment = 0; break;
case Surface.ROTATION_90: screen_adjustment = (float)Math.PI/2; break;
case Surface.ROTATION_180: screen_adjustment = (float)Math.PI; break;
case Surface.ROTATION_270: screen_adjustment = 3*(float)Math.PI/2; break;
}
这就是我在回答可补偿倾斜和音高的Android指南针时用到的。其他人建议使用[SensorManager.remapCoordinateSystem(float[],int,int,float[])](http://developer.android.com/reference/android/hardware/SensorManager.html#remapCoordinateSystem(float%5B%5D,%20int,%20int,%20float%5B%5D%29),这取决于旋转数是什么。
https://stackoverflow.com/questions/16539189
复制相似问题