2012-08-06 31 views
2

我想要得到的X,Y,Z位置的準確位置,我想「看在」通過陀螺傳感器的能力Android的陀螺 - OpenGL的注視位置

我能得到到陀螺儀傳感器的9個數​​值,但我無法弄清楚這個陀螺儀傳感器的確切位置的公式。

我希望公式或一個例子,以獲得正確的答案

這裏是我想要的結果轉出結果的

double standX = 0.0f, standY = 0.0f, standZ = 0.0f; 
double lookX = 0.0f, lookY = 0.0f, lookZ = 1.0f; 
double headupX = 0.0f, headupY = 1.0f, headupZ = 0.0f; 
float[] deltaRotationMatrix = new float[9]; 
SensorManager.getRotationMatrixFromVector(deltaRotationMatrix, deltaRotationVector); 

// code here 

// in my onDraw 
// I'm trying to make the lookAt position proper 
Matrix.setLookAtM(mViewMatrix, 0, 
     eyeX, eyeY, eyeZ, lookX, lookY, lookZ, headupX , headupY, headupZ); 

例子的代碼如下位置:

example of x=0, y=0, z=-1

example of x=0, y=1, z=0

example of x=1, y=0, z=1

回答

1

我已經完成了我的問題 ,這是我的解決方案

首先,我需要在onSensorChanged以使這個3矩陣來獲得X,Y的結果,z位置

private float[] mRotXMatrix = new float[] { 
1, 0, 0, 0, 
0, 0, 1, 0, 
0, 1, 0, 0, 
0, 0, 0, 1 }; 
private float[] mRotYMatrix = new float[] { 
0, 0, 1, 0, 
0, 1, 0, 0, 
1, 0, 0, 0, 
0, 0, 0, 1 }; 
private float[] mRotZMatrix = new float[] { 
0, 1, 0, 0, 
1, 0, 0, 0, 
0, 0, 1, 0, 
0, 0, 0, 1 }; 

然後(SensorEvent e)的方法我旋轉所有這些3矩陣與我這樣的相機視圖

Matrix.multiplyMM(mViewMatrix, 0, deltaRotationMatrix, 0, mViewMatrix, 0); 
Matrix.multiplyMM(mRotXMatrix, 0, deltaRotationMatrix, 0, mRotXMatrix, 0); 
Matrix.multiplyMM(mRotYMatrix, 0, deltaRotationMatrix, 0, mRotYMatrix, 0); 
Matrix.multiplyMM(mRotZMatrix, 0, deltaRotationMatrix, 0, mRotZMatrix, 0); 

而要獲得X,我的相機視圖的Y,Z,只是從這些矩陣中獲得它

viewX = mRotXMatrix[2]; 
viewY = -mRotYMatrix[6]; // +/- up to your initial camera view 
viewZ = mRotZMatrix[10];