Search code examples
androidopengl-esandroid-viewandroid-sensors

Android OpenGL compass


Can anyone help me with sample code for a compass needle that points in the direction where the phone is tilted? I am trying to develop an application to rotate a bitmap in OpenGL from accelerometer values.


Solution

  • Ok so thanks to the comments above we do not have to use OpenGL, and while you could, I personally believe you can make life simpler by using a custom View.

    Now in traditional standard StackOverFlow past time I am not going to give you code for this but extrmely large leg up. There is a thermometer example available here http://mindtherobot.com/blog/272/android-custom-ui-making-a-vintage-thermometer/.

    Why have I sent you here?

    It contains an example that renders a dial exceedingly close to a compass, with a few minor tweeks it could easily become a compass in terms of design. you will just need to remove the temperature related code and use the accelerometers instead.

    It is a good intro to custom views and will show you how to get started.

    I made a clock after following the tutorial just as another possibility to inspire you.