gpt4 book ai didi

Android SensorManager 奇怪如何重新映射CoordinateSystem

转载 作者:IT王子 更新时间:2023-10-28 23:35:52 27 4
gpt4 key购买 nike

API 演示 -> 图形 -> Compass

它只能正常工作,直到您不更改设备的自然方向。在大多数手机中是纵向的,而大多数 10 英寸平板电脑是横向的。如果您进行更改,则需要将其旋转 90 度。我希望看到该系统的 3D 修复。

100% 肯定需要使用remapCoordinateSystem()方法。

我想看看如何(代码),如果我能看到有关如何计算这些轴映射(理论数学)的解释,那就太好了。

我试图理解,但我忘记了所有线性代数。

Here它说明了我们为什么必须使用,但没有说明如何使用!

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);

这些坐标似乎在这个位置:- 设备在 table 上(x 和 y 轴在 table 上)

device orientation

只有且仅当

getWindowManager().getDefaultDisplay().getRotation() == Surface.ROTATION_0

问题是如何完成这段代码:-那些案例分支

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);

编辑:我写了一个小测试应用程序,它在屏幕上显示屏幕旋转:0、90、270 度(现在不能变成 180 度)

看来,如果 Rotation 0 不变(axisX = SensorManager.AXIS_X;axisY = SensorManager.AXIS_Y;)比 90 度应该是:

axisX = SensorManager.AXIS_MINUS_Y;
axisY = SensorManager.AXIS_X;

比 Google 文档在某处说的值错误!问题在哪里?!

getRotationMatrix返回:

enter image description here

X is defined as the vector product Y.Z (It is tangential to the ground at the device's current location and roughly points East).

Y is tangential to the ground at the device's current location and points towards the magnetic North Pole.

Z points towards the sky and is perpendicular to the ground.

请看上面的电话!我想从左到右,后置摄像头接地。

getOrientation返回:

enter image description here

X is defined as the vector product Y.Z (It is tangential to the ground at the device's current location and roughly points West).

Y is tangential to the ground at the device's current location and points towards the magnetic North Pole.

Z points towards the center of the Earth and is perpendicular to the ground.

values[0]: azimuth, rotation around the Z axis.

values[1]: pitch, rotation around the X axis.

values[2]: roll, rotation around the Y axis.

电话应该怎么样?

最后我想要像飞机这样的角度值。我的手机(我)向北:(偏航是方位角)

enter image description here

              if ScreenRotation = 0 degree
Pitch axis = -orientationAxisX = rotationAxisX
Roll axis = orientationAxisY = rotationAxisY
Yaw axis = orientationAxisZ = -rotationAxisZ

最佳答案

为了完成切换分支,我只是尝试遵循 remapCoordinateSystem 方法 javadoc:

X defines on which world axis and direction the X axis of the device is mapped.
Y defines on which world axis and direction the Y axis of the device is mapped.

因此,将您的设备从其自然方向(90、180 或 270 度)旋转并问自己:原始设备方向中的 X 正轴与当前设备方向中的哪个轴对应? Y 轴也一样。

因此,如果您的设备旋转 90 度,您将看到原始 X 正轴对应于当前正 Y 轴,而原始正 Y 轴对应于当前方向负 X 轴。

应该是这样的:

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;
}

这对我有用,希望有帮助。

关于Android SensorManager 奇怪如何重新映射CoordinateSystem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18782829/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com