How to get a phone header for augmented reality?

Possible duplicate: Android getOrientation Azimuth gets dirty when tilting the phone


I am new to Android development and I am trying to get the user's attention.

After searching the Internet, I'm sure I need to use remapCoordinateSystem, the Android documentation says that this is useful for an augmented reality application.

I am trying to use some existing code to make sure this is a good way.

(Finally, I want to create an augmented reality application)

The following code should return a user standing in degrees:

The code:

        Sensor sensor = event.sensor;
        if (sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
            gravity = event.values.clone();
        }else if (sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
            geomagnetic = event.values.clone();
        }

        if (gravity != null && geomagnetic != null){
            _rM = SensorManager.getRotationMatrix (R, null, gravity, geomagnetic);  
                if(_rM){

                    int mScreenRotation = activity.getWindowManager().getDefaultDisplay().getRotation(); // get user orientation mode
                    switch (mScreenRotation) { // Handle device rotation (landscape, portrait)
                        case Surface.ROTATION_0:
                            axisX = SensorManager.AXIS_X;
                            axisY = SensorManager.AXIS_Y;
                            break;

                        case Surface.ROTATION_90:
                            axisX = SensorManager.AXIS_Y;
                            axisY = SensorManager.AXIS_MINUS_X;
                            break;

                        case Surface.ROTATION_180: // not handled by my phone so I can't test
                            axisX = SensorManager.AXIS_MINUS_X;
                            axisY = SensorManager.AXIS_MINUS_Y;
                            break;

                        case Surface.ROTATION_270:
                            axisX = SensorManager.AXIS_MINUS_Y;
                            axisY = SensorManager.AXIS_X;
                            break;

                        default:
                            break;
                    }
                    SensorManager.remapCoordinateSystem (R, axisX, axisY, outR);
                    SensorManager.getOrientation (outR, gO);
            }
        }


        userFacing = (float) Math.toDegrees(gO[0]); // Radian to degree
        if(userFacing<0) { userFacing+=360; } // -180;180 to 0;360
        return userFacing;

, , ( ), : , 40 °...

: qaru.site/questions/57183/...

, ( , !) , ...

, TYPE_GYROSCOPE, , !

, ! ( )


, , iOS, , , . , . remapCoordinateSystem: AXIS_X AXIS_Y, , . @HoanNguyen, AXIS_X AXIS_Z, - .

, . :

    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        gravity = lowPass(event.values.clone(), gravity);
    }
    else if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        geomagnetic = lowPass(event.values.clone(), geomagnetic);
    }

    if (geomagnetic != null && gravity != null) {
        if (SensorManager.getRotationMatrix (R_in, null, gravity, geomagnetic)) {               
            SensorManager.remapCoordinateSystem (R_in, SensorManager.AXIS_X, SensorManager.AXIS_Z, R_out);
            SensorManager.getOrientation (R_out, gO);
        }
    }

, gO[0] heading = gO[0]; (, )

, -!

+2
1

, " " z- .

remapCoordinateSystem(inR, AXIS_X, AXIS_Z, outR);

. getOrientation() , .

2 z- XY , .

+3

All Articles