开发者

Android: understanding the function remapCoordinateSystem

开发者 https://www.devze.com 2023-02-13 17:40 出处:网络
I have been trying to understand these 2 lines of code SensorManager.getRotationMatrix(RTmp, I, grav, mag);

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 e开发者_如何学编程xactly getRotationMatrix and remapCoordinateSystem do? Specially the SensorManager.AXIS_X, SensorManager.AXIS_MINUS_Z?


I believe getRotationMatrix() returns a rotation matrix that converts device coordinate to world coordinate, as mentioned in android documentation, not "world" to "device".

Computes the inclination matrix I as well as the rotation matrix R transforming a vector from the device coordinate system to the world's coordinate system which is defined as a direct orthonormal basis, where


I think the function of getRotationMatrix() was clearly explained by @Noname. I am trying to answer your second and third questions considering remapCoordinateSystem() and SensorManager.AXIS_X, SensorManager.AXIS_MINUS_Z.

What remapCoordinateSystem() does is actually changing the CoordinateSystem, setting the new X, Y, Z-AXIS where SensorManager.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 to SensorManager.AXIS_MINUS_Z FYI. If you want to do the same thing in landscape orientation, you will set the coordinate system as follow:

SensorManager.remapCoordinateSystem(RTmp, SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, Rot);

I hope this helps.


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

SensorManager.getRotationMatrix(RTmp, I, grav, mag);
SensorManager.remapCoordinateSystem(RTmp, SensorManager.AXIS_X,SensorManager.AXIS_MINUS_Z, Rot);

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消