Android:理解函数remapCooperativeSystem
我一直在试图理解我读过的这两行代码
SensorManager.getRotationMatrix(RTmp, I, grav, mag);
SensorManager.remapCoordinateSystem(RTmp, SensorManager.AXIS_X,SensorManager.AXIS_MINUS_Z, Rot);
remapCooperativeSystem()
的文档,但是我迷路了。
谁能向我解释一下 getRotationMatrix
和 remapCooperativeSystem
到底做什么?特别是 SensorManager.AXIS_X
、SensorManager.AXIS_MINUS_Z
?
I have been trying to understand these 2 lines of code
SensorManager.getRotationMatrix(RTmp, I, grav, mag);
SensorManager.remapCoordinateSystem(RTmp, SensorManager.AXIS_X,SensorManager.AXIS_MINUS_Z, Rot);
I read the documentation of remapCoordinateSystem()
, however I am lost.
Can anyone explain to me what exactly getRotationMatrix
and remapCoordinateSystem
do? Specially the SensorManager.AXIS_X
, SensorManager.AXIS_MINUS_Z
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我相信
getRotationMatrix()
返回一个旋转矩阵,将设备坐标转换为世界坐标,如 android 文档,而不是“世界”到“设备”。I believe
getRotationMatrix()
returns a rotation matrix that converts device coordinate to world coordinate, as mentioned in android documentation, not "world" to "device".我认为 @Noname 已经清楚地解释了
getRotationMatrix()
的功能。我正在尝试回答您的第二个问题和第三个问题,考虑到remapCooperativeSystem()
和SensorManager.AXIS_X
、SensorManager.AXIS_MINUS_Z
。remapCooperativeSystem()
所做的实际上是更改坐标系统,设置新的 X、Y、Z 轴,其中SensorManager.AXIS_X
,SensorManager .AXIS_MINUS_Z
是手机的坐标系。从您的代码来看,我相信您正在纵向进行增强现实。这就是您将 Y 轴设置为SensorManager.AXIS_MINUS_Z
仅供参考的原因。如果您想在横向上做同样的事情,您将按如下方式设置坐标系:我希望这会有所帮助。
I think the function of
getRotationMatrix()
was clearly explained by @Noname. I am trying to answer your second and third questions consideringremapCoordinateSystem()
andSensorManager.AXIS_X
,SensorManager.AXIS_MINUS_Z
.What
remapCoordinateSystem()
does is actually changing the CoordinateSystem, setting the new X, Y, Z-AXIS whereSensorManager.AXIS_X
,SensorManager.AXIS_MINUS_Z
are the coordinate system of your phone. From your code, I believe you are doing augmented reality in portrait orientation. That's why you set Y-axis toSensorManager.AXIS_MINUS_Z
FYI. If you want to do the same thing in landscape orientation, you will set the coordinate system as follow:I hope this helps.
完全断章取义地提出这样的问题通常很难回答。此外,您还应该熟悉格式(例如:4 个空格表示代码):
但是:
我想说您使用文档的方向是正确的。如您所见, getRotationMatrix 拉取将“世界坐标系”转换为当前设备坐标系所需的当前旋转矩阵。
另外,remapcoordinateSystem 将给定的坐标系相应地转换为给定的旋转矩阵。
但如上所述 - 脱离上下文很难告诉你为什么有人这样做。
Asking such a question totally out of context is generally hard to answer. Also you should get familiar with formatting (e.g: 4 spaces indicates code):
However:
I would say that you are on the right track using the documentation. As you see getRotationMatrix pulls the current rotation matrix needed to transform the "world coordinate system" to the current device coordinate system.
Additionally remapcoordinateSystem transforms the given coordinate System accordingly to the given rotation Matrix.
But as stated above - out of context it is hard to tell you WHY somebody is doing this.