问题描述
API演示 - >图像 - > Compass
它正常工作而已,直到你不改变设备的自然倾向。在大多数手机是纵向和最多10英寸的平板电脑是景观。如果比需要更改与90度旋转此。我希望看到一个3D修复该系统。
100%肯定需要使用remapCoordinateSystem()方法
我想看看它是如何(code),如果我能看到如何计算这些轴的映射(理论数学)的解释是不错的。
我已经tryed理解,但我忘记了所有线性代数。
这里该说为什么一定要使用,但不告诉如何!
浮动 - [R [] =新的浮动[9];
// X(的Y产物和Z)和大致点东
// Y:指向磁北和切向地面
// Z:指向天空,垂直于地面
浮动我[] =新的浮动[9];
布尔成功= SensorManager.getRotationMatrix(R,I,mGravity,mGeomagnetic);
看来这些坐标到这个位置: - 在设备中说的表(x和y轴是上表)
仅且仅当
getWindowManager()。getDefaultDisplay()。getRotation()== Surface.ROTATION_0
现在的问题是如何完成这个code: - 这些情况下分支
开关(mScreenRotation){
案例Surface.ROTATION_0:
Log.v(SurfaceRemap,0度);
axisX = SensorManager.AXIS_X; //这是有效的吗?
axisY = SensorManager.AXIS_Y; //这是有效的吗?
打破;
案例Surface.ROTATION_90:
Log.v(SurfaceRemap,90度);
//例子说remapCoordinateSystem(INR,AXIS_Y,AXIS_MINUS_X,OUTR);
axisX = SensorManager.AXIS_Y;
axisY = SensorManager.AXIS_MINUS_X;
打破;
案例Surface.ROTATION_180:
Log.v(SurfaceRemap,180度);
打破;
案例Surface.ROTATION_270:
Log.v(SurfaceRemap,270度);
打破;
默认:
Log.v(SurfaceRemap,不知道mScreenRotation值:+ mScreenRotation +你应该从来没有见过这个消息!);
打破;
}
布尔重映射= SensorManager.remapCoordinateSystem(R,axisX,axisY,R);
浮方位[] =新的浮动[3];
SensorManager.getOrientation(R,取向); //所有三个角以上是用弧度并在反时针方向阳性。
倾角= SensorManager.getInclination(Ⅰ);
编辑:我写了一个小测试应用程序,在屏幕上显示的屏幕旋转:0,90,270度(无法拨打180了)
看来,如果旋转0是不变的(<$ C C $> axisX = SensorManager.AXIS_X; axisY = SensorManager.AXIS_Y; ),比90度应该是:
axisX = SensorManager.AXIS_MINUS_Y;
axisY = SensorManager.AXIS_X;
比谷歌文档说某处错误的价值观!问题是在哪里?!
getRotationMatrix回到这样的:
见上面的电话!我想,以向右左,背部摄像头至地。
getOrientation回到这样的:
如何应该是手机?
最后,我想有角像飞机的价值。我的手机(我)前往北:(偏航的方位)
如果ScreenRotation = 0度
俯仰轴= -orientationAxisX = rotationAxisX
辊轴= orientationAxisY = rotationAxisY
偏航轴= orientationAxisZ = -rotationAxisZ
要完成切换分支我只是尽量想继remapCoordinateSystem方法的javadoc:
所以,把你的设备将其旋转从它的自然方位(90,180或270度),并问自己:在X正轴在原有设备的方向到轴对应于当前设备的方向?而同为Y轴。
所以,如果将设备旋转90度,你会看到原始X轴正轴对应于当前正Y轴和原来的正Y轴对应于当前定向负X轴
所以,它应该是:
开关(mScreenRotation){
案例Surface.ROTATION_0:
axisX = SensorManager.AXIS_X;
axisY = SensorManager.AXIS_Y;
打破;
案例Surface.ROTATION_90:
axisX = SensorManager.AXIS_Y;
axisY = SensorManager.AXIS_MINUS_X;
打破;
案例Surface.ROTATION_180:
axisX = SensorManager.AXIS_MINUS_X;
axisY = SensorManager.AXIS_MINUS_Y;
打破;
案例Surface.ROTATION_270:
axisX = SensorManager.AXIS_MINUS_Y;
axisY = SensorManager.AXIS_X;
打破;
默认:
打破;
}
这是为我工作,希望帮助。
API Demos -> Graphics -> Compass
It works properly only, until you don't change the device natural orientation.In most phones is the portrait and most 10 inch tablets are the landscape. If you change than need to rotate this with 90 degree. I would like to see a 3D fix for that system.
100% sure need to use remapCoordinateSystem() method.
I would like to see how ( code ) if I could see an explanation with how is calculated those axes mapping ( theoretical math ) it would be nice.
I have tryed to understand, but I forgot all linear algebra.
Here it says why must we use, but doesn't telling how!
float R[] = new float[9];
// X (product of Y and Z) and roughly points East
// Y: points to Magnetic NORTH and tangential to ground
// Z: points to SKY and perpendicular to ground
float I[] = new float[9];
boolean success = SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic);
It seems those coordinates are to this position: - the device say in a table (x, and y axes are on table)
Only and only if
getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_0
The question is how to complete this code: - those case branches
switch (mScreenRotation) {
case Surface.ROTATION_0:
Log.v("SurfaceRemap", "0 degree");
axisX = SensorManager.AXIS_X;// is this valid?
axisY = SensorManager.AXIS_Y;// is this valid?
break;
case Surface.ROTATION_90:
Log.v("SurfaceRemap", "90 degree");
// examples says remapCoordinateSystem(inR, AXIS_Y, AXIS_MINUS_X, outR);
axisX = SensorManager.AXIS_Y;
axisY = SensorManager.AXIS_MINUS_X;
break;
case Surface.ROTATION_180:
Log.v("SurfaceRemap", "180 degree");
break;
case Surface.ROTATION_270:
Log.v("SurfaceRemap", "270 degree");
break;
default:
Log.v("SurfaceRemap", "don't know the mScreenRotation value: "+mScreenRotation+" you should never seen this message!");
break;
}
boolean remapped = SensorManager.remapCoordinateSystem(R, axisX, axisY, R);
float orientation[] = new float[3];
SensorManager.getOrientation(R, orientation);// All three angles above are in radians and positive in the counter-clockwise direction.
inclination = SensorManager.getInclination(I);
Edit:I wrote a little test application, where on the screen it display the screen rotation: 0, 90, 270 degrees ( can't make 180 now)
It seems, if Rotation 0 is unchanged (axisX = SensorManager.AXIS_X;axisY = SensorManager.AXIS_Y;
) than the 90 degree should be:
axisX = SensorManager.AXIS_MINUS_Y;
axisY = SensorManager.AXIS_X;
than the Google documentation says somewhere wrong values! Question is where?!
getRotationMatrix return this:
See the phone above! I want to to to right from left, with back camera to ground.
getOrientation return this:
How should be the phone?
Finally I would like to have values of angles like aircrafts. My phone (me) heading to North: (yaw is azimuth)
if ScreenRotation = 0 degree
Pitch axis = -orientationAxisX = rotationAxisX
Roll axis = orientationAxisY = rotationAxisY
Yaw axis = orientationAxisZ = -rotationAxisZ
To complete the switch branches I just try to think following the remapCoordinateSystem method javadoc:
So take your device rotate it from its natural orientation (90, 180 or 270 degrees) and ask yourself: The X positive axis in the original device orientation to which axis corresponds in the current device orientation?. And same for the Y axis.
So in case your device is rotated 90 degrees you will see that the original X positive axis corresponds to the current positive Y axis and the original positive Y axis corresponds to the current orientation negative X axis.
So It should be:
switch (mScreenRotation) {
case Surface.ROTATION_0:
axisX = SensorManager.AXIS_X;
axisY = SensorManager.AXIS_Y;
break;
case Surface.ROTATION_90:
axisX = SensorManager.AXIS_Y;
axisY = SensorManager.AXIS_MINUS_X;
break;
case Surface.ROTATION_180:
axisX = SensorManager.AXIS_MINUS_X;
axisY = SensorManager.AXIS_MINUS_Y;
break;
case Surface.ROTATION_270:
axisX = SensorManager.AXIS_MINUS_Y;
axisY = SensorManager.AXIS_X;
break;
default:
break;
}
That worked for me, hope that helps.
这篇关于安卓的SensorManager奇怪怎么remapCoordinateSystem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!