finding orientation using getRotationMatrix() and getOrientation()

后端 未结 5 826
天命终不由人
天命终不由人 2020-12-31 14:13

Im trying to get the direction of the vector pointing out of the camera, with respect to magnetic north. I\'m under the impression that I need to use the values returned fro

相关标签:
5条回答
  • 2020-12-31 15:03

    You need to get the orientation of your device (Landscape/Portrait) and make some compensation.

    SensorManager.getOrientation(R, values);  
    mHeading = (int) Math.toDegrees(values[0]); 
    Display display = 
    ((WindowManager)getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
    int compensation = display.getRotation() * 90;                          
    mHeading = mHeading+compensation;
    
    0 讨论(0)
  • 2020-12-31 15:05

    Because I was new to android I was using toast to display the information on the screen. I changed it to just update text on a view and that seemed to fix it. I also figured out that what I assumed the orientVals actually were is correct. For what I need the roll is not used. Also didnt realize there was a way to convert from rad to deg built in so I just used that.

    0 讨论(0)
  • 2020-12-31 15:06

    I think you should have to use getInclination to get the direction instead of get orientation. as getRotationMatrix is calculating based on both gravity and geomagnetic feild and you will get the inlination from the magnetic field directly.

    0 讨论(0)
  • you can check out the logger application that displays raw values on the screen. In its description you'll find a link to the source code so that you can learn how it accesses the sensors.

    HTH, Daniele

    0 讨论(0)
  • 2020-12-31 15:20

    I Think you should change outR to inR in line getOrientation

    boolean success = SensorManager.getRotationMatrix(inR, I, gravity, geomag);
    if (success){
     // Re-map coordinates so y-axis comes out of camera
     SensorManager.remapCoordinateSystem(inR, SensorManager.AXIS_X, 
       SensorManager.AXIS_Z, outR);
    
     // Finds the Azimuth and Pitch angles of the y-axis with 
     // magnetic north and the horizon respectively
     **SensorManager.getOrientation(inR, orientVals);**
    
    0 讨论(0)
提交回复
热议问题