简体   繁体   English

在x轴上获取Android旋转角度

[英]Get Android rotation angle in x-axis

I'm experimenting with some Android functions. 我正在尝试一些Android功能。 Right now, I'm trying to get the rotation angle of the device, so when I show a happy face bitmap on a canvas, it always looks "straight". 现在,我正试图获得设备的旋转角度,所以当我在画布上显示一张快乐的脸部位图时,它总是看起来“笔直”。

All I would need for this, is to get the x-axis rotation angle (I guess) but I can't find how to achieve it. 所有我需要的是,获得x轴旋转角度(我猜)但我找不到如何实现它。 Hope you can help me. 希望您能够帮助我。 Thank you. 谢谢。

Found a better answer! 找到了更好的答案! (Thanks to forgivegod for helping me starting this!) (感谢forgivegod帮助我开始这个!)

ORIENTATION is now deprecated and uses to many resources. ORIENTATION现已弃用,并用于许多资源。 Plus, it works with reference to the magnetic north, which gives not the pure rotation of the device, but actually always points to the north. 此外,它适用于磁北方,它不提供设备的纯旋转,但实际上总是指向北方。

By using ACCELEROMETER, one can calculate the rotation angle of the device with values [0] and [1] this way: 通过使用ACCELEROMETER,可以用这种方式用值[0]和[1]计算设备的旋转角度:

    public void onSensorChanged(SensorEvent event) {
        // TODO Auto-generated method stub
        if (event.sensor != mSensor)
            return;

        aX= event.values[0];
        aY= event.values[1];
        //aZ= event.values[2];
        angle = Math.atan2(aX, aY)/(Math.PI/180);
    }

Maybe this can help someone else in the future. 也许这可以在将来帮助别人。 Thanks a lot! 非常感谢!

There is azimuth, pitch and roll available to you. 有方位角,俯仰和滚动可供选择。 Not sure which one relates to your "x-axis" but I think its azimuth. 不确定哪一个与你的“x轴”相关,但我认为它的方位角。

Time for helpful links: 有用链接的时间:

  1. http://www.workingfromhere.com/blog/2009/03/30/orientation-sensor-tips-in-android/ http://www.workingfromhere.com/blog/2009/03/30/orientation-sensor-tips-in-android/
  2. http://marakana.com/forums/android/examples/43.html http://marakana.com/forums/android/examples/43.html
  3. http://marakana.com/static/tutorials/SensorDemo.zip http://marakana.com/static/tutorials/SensorDemo.zip

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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