简体   繁体   中英

getting the orientation(Roll, Pitch, Yaw) angles of the mobilePhone using Sensor Manager?

I'm trying to get the orientation (Roll, Pitch, Yaw) angles of the mobilePhone using Sensor Manager ,and according to what is written in android developers website, the method

getInclination(float[] I) Computes the geomagnetic inclination angle in radians from the inclination matrix I >returned by getRotationMatrix(float[], float[], float[], float[]).` and getRotationMatrix(float[] R, float[] I, float[] gravity, float[] geomagnetic)

Computes the inclination matrix I as well as the rotation matrix R transforming a vector >from the device coordinate system to the world's coordinate system which is defined as a >direct orthonormal basis. ` and it returns boolean value.

My question is, How to get the orientation using the methods mentioned?

Code

@Override
public void onSensorChanged(SensorEvent event) {
    // TODO Auto-generated method stub

    float []I = new float[9];
    float []R = new float[9];

    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        float x = event.values[0];
        float y = event.values[1];
        float z = event.values[2];

        tvX.setText(Float.toString(x));
        tvY.setText(Float.toString(y));
        //tvZ.setText(Float.toString(sm.getInclination(I)));    
    }
}
Display disp = (Display)getSystemService(Context.WINDOW_SERVICE);
int orientation = disp.getOrientation();

Use the above two lines to get orientation of mobile phone

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM