[android] remapCoordinateSystem()


광고 한번만 클릭 부탁드립니다^^


포스팅을 보시는 분들을 위해 노력 하는 블로거를 위하여! 부탁드립니다. 재미 삼아 포스팅을 정리하지만, 광고를 달아보았습니다. 얼마나 열심히 할 수 있을지...의문이지만요^^ 

Subject remapCoordinateSystem()

최종수정일 : 2011.08.02

안녕하세요~^^
Camera 와 OpenGL 을 사용하면서 Axis 가 아직도 해깔립니다.
그래서....하면서 정리중입니다.

정리가 완료된 것은 아직 미공개 상태로 둘까 중입니다. =ㅅ=!!!
어디 삽질해봐욥!! ㅎㅎㅎㅎ 이러면서 ㅎㅎㅎ....
되기나 되면 -ㅅ-/ 공개하겠죠 ㄷㄷㄷ 일단 헤메고나서 .  


by 퓨림노

글을 작성하겠습니다.

public static boolean remapCoordinateSystem (float[] inR, int X, int Y, float[] outR)


이런 녀석을 어떻게 해야할까요? 아니 사용방법입니다. 
간단하게  코드를 작성해보았습니다. 

public void onCreate(Bundle savedInstanceState) {
...
 
float[] R = new float[16];
float[] outR = new float[16];
float[] mV = new float[3];

for( int i=0; i<16; i++ )
  R[i] = 0;   	 	

R[15] = 1;
R[0] = 1;
R[5] = 1;
R[10] = 1;

SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_X, SensorManager.AXIS_Z, outR);				
SensorManager.getOrientation(outR, mV);
...
} 

디버깅을 해서 값을 볼까요?
먼저 초기 R 값 입니다.(기본으로 넣었습니다.)

1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1   

그리고 remapCoordinateSystem() 함수를 거치고 난 후에 결과 outR 입니다.

1 0 0 0 
0 0 1 0
0 -1 0 0
0 0 0 1   


아! 함수에 대한 설명이랑, 그림이 빠졌군요!? 

먼저 함수에 대한 설명


public static boolean remapCoordinateSystem (float[] inR, int X, int Y, float[] outR)

inR the rotation matrix to be transformed. Usually it is the matrix returned by getRotationMatrix(float[], float[], float[], float[]).
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.
outR the transformed rotation matrix. inR and outR can be the same array, but it is not recommended for performance reason. 
 


일단, OpenGL 의 기본 Axis 만 생각하도록 하겠습니다. 
그리고 Device가 회전을 하게됨으로써, Axis 가 변경이 됩니다.
화면 좌표계, 센서좌표계가 틀리게 됩니다. 

remapCoordinateSystem 함수를 사용하여서 Axis 를 변경 합니다. OK! 

그리고 2,3번째 파라미터는 X , Y 축으로 할 부분을 지정해 주면 됩니다. Z 축은 자동으로 계산합니다. 

그리고 결과 Matrix 는
outR 로 나오게 됩니다.  
위에서 실험한 Axis는 
다음과 같습니다. 









 

댓글

Designed by JB FACTORY