1

スマートフォンを地平線のすぐ下に置くと、-90を超えることに気づきました。空を指すように電話を傾け始めると、-90前後、つまり-88、-90、-88が反射します。地面から空に向かって傾いているように。

誰かがこれを以前に経験したことがありますか。(remapCoordinateSystemとは関係がないようです)。(私は以前にそれをコメントアウトしました)。電話のカメラを地面に向けると、ピッチの読み取り値はゼロになります。天井に向けると、それもゼロになります。

助けてくれてありがとう。

    @Override
    public void onSensorChanged(SensorEvent event) {
        synchronized (MainActivity.this) { // TilteController
            switch (event.sensor.getType()) {
            case Sensor.TYPE_MAGNETIC_FIELD:
                mMagneticValues = event.values.clone();
                break;
            case Sensor.TYPE_ACCELEROMETER:
                mAccelerometerValues = event.values.clone();
                break;
            }

            if (mMagneticValues != null && mAccelerometerValues != null) {
                SensorManager.getRotationMatrix(R, null, mAccelerometerValues, mMagneticValues);

                Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
                int rotation = display.getRotation();

                switch (rotation)
                {
                case Configuration.ORIENTATION_LANDSCAPE:
                    SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_MINUS_Y, SensorManager.AXIS_MINUS_X, R);//shouldnt be the same R in and out
                case Configuration.ORIENTATION_PORTRAIT:
                    SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_Y, SensorManager.AXIS_X, R);//shouldnt be the same R in and out
                }


                float[] orientation = new float[3];
                SensorManager.getOrientation(R, orientation);

                mAzimuth = orientation[0];
                mPitch = orientation[1];
                mRoll = orientation[2];

                dirText.setText("Azimuth, Pitch, Roll || " + radStr(mAzimuth) +", "+ radStr(mPitch) +", "+ radStr(mRoll));

                glView.rotate((float)Math.toDegrees(mAzimuth),(float)Math.toDegrees(mPitch),(float)Math.toDegrees(mRoll));
                //glView.azimuth=(float)Math.toDegrees(smooth(mAzimuth));
                glView.pitch=(float)(Math.toDegrees(smooth(mPitch)));//-90 makes it cenetr
                //glView.roll=(float)Math.toDegrees(smooth(-mRoll));
                //Log.i("Azimuth, Pitch, Roll", mAzimuth+", "+mPitch+", "+mRoll);
            }
        }
    }

私のニーズに対する一時的な修正には、getorientationを呼び出す前にマトリックスを回転させることが含まれます。

Matrix.rotateM(R, 0, 90, 0, 1, 0);

どのように完全に反転しても、同じ問題が発生します。(これはAzimuthを追加することで解決する必要があります)しかし、それは素晴らしい解決策ではありません。

したがって、他の人がこれを読んでいて、地平線を0度にしようとしている場合。ディスプレイを回転させるのとは対照的に、前にマトリックスを回転させます(OpenGLを使用しています)

4

1 に答える 1

1

ランドスケープでアプリをロックして終了し、次を適用します

    SensorManager.getRotationMatrix(R, null, mAccelerometerValues, mMagneticValues);

    Display display = ((WindowManager) getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int rotation = display.getRotation();

    SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_X, SensorManager.AXIS_Z, R);//shouldnt be the same R in and out

    float[] orientation = new float[3];
    SensorManager.getOrientation(R, orientation);
于 2012-08-21T12:17:18.003 に答える