Moving a coordinate system in an Android application

I am using a simple Android application in which I need to identify the north.

So, I implemented SensorEventListener, and I used something like this:

@Override
public void onSensorChanged(SensorEvent event) {
    if(event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR)
    {
        SensorManager.getRotationMatrixFromVector(mRotationMatrix, event.values);
        SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z, orientationVals);
        SensorManager.getOrientation(mRotationMatrix, orientationVals);

        orientationVals[0] = (float) Math.toDegrees(orientationVals[0]);
        orientationVals[1] = (float) Math.toDegrees(orientationVals[1]);
        orientationVals[2] = (float) Math.toDegrees(orientationVals[2]);

        tv.setText(" Yaw: "+ orientationVals[0] +"\n Pitch: "+ orientationVals[1]+"\n Roll: "+ orientationVals[2]);
    }

}

The problem is that the line of code

SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z, orientationVals);

doesn't seem to work, because in both cases (with or without this line of code) the Yaw value (azimuth) depends on the orientation of the phone’s head (allowing it to fit on the back side)

what I expected using my redefinition was that Yaw changed depending on the orientation of the back of the phone (rear camera).

Why is my reassignment not working?

+4
source share
2

, , :

SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z, orientationVals);

mRotationMatrix verticalVals. ( ).

:

SensorManager.getOrientation(mRotationMatrix, orientationVals);

mRotationMatrix , (, ) , Vals.

, mRotationMatrix, , , , .

- :

float[] remapCoords = new float[16];
SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Z, remapCoords);
SensorManager.getOrientation(remapCoords, orientationVals);

, - , /, .

, , , , , (, onCreate, onSurfaceChanged ..), , .

+2

:

/* Compensate device orientation */
            float[] remappedRotationMatrix = new float[9];
            switch (getWindowManager().getDefaultDisplay()
                    .getRotation()) {
            case Surface.ROTATION_0:
                SensorManager.remapCoordinateSystem(rotationMatrix,
                        SensorManager.AXIS_X, SensorManager.AXIS_Y,
                        remappedRotationMatrix);
                break;
            case Surface.ROTATION_90:
                SensorManager.remapCoordinateSystem(rotationMatrix,
                        SensorManager.AXIS_Y,
                        SensorManager.AXIS_MINUS_X,
                        remappedRotationMatrix);
                break;
            case Surface.ROTATION_180:
                SensorManager.remapCoordinateSystem(rotationMatrix,
                        SensorManager.AXIS_MINUS_X,
                        SensorManager.AXIS_MINUS_Y,
                        remappedRotationMatrix);
                break;
            case Surface.ROTATION_270:
                SensorManager.remapCoordinateSystem(rotationMatrix,
                        SensorManager.AXIS_MINUS_Y,
                        SensorManager.AXIS_X, remappedRotationMatrix);
                break;
            }

            /* Calculate Orientation */
            float results[] = new float[3];
            SensorManager.getOrientation(remappedRotationMatrix,
                    results);

, , , . . .

0

All Articles