2

ジャイロセンサーの能力で「たい」X、Y、Z位置の正確な位置を取得したい

ジャイロスコープ センサーから 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);

結果の例は次のとおりです。

x=0、y=0、z=-1の例

x=0、y=1、z=0の例

x=1、y=0、z=1の例

4

1 に答える 1

1

私は質問を終えました。これが私の解決策です

まず、x、y、z 位置の結果を取得するために、この 3 つの行列を作成する必要があります

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

次に、 onSensorChanged(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];
于 2012-08-10T18:27:01.110 に答える