Probably these links are more than you want for such a cool project, that's for you to decide.
But you did ask about phone orientation and mention the compass.
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Probably these links are more than you want for such a cool project, that's for you to decide.
But you did ask about phone orientation and mention the compass.
http://rouel-projects.blogspot.com/p/calculations-with-iphones.html
https://www.safaribooksonline.com/library/view/basic-sensors-in/9781449309480/ch04.html
http://hackaday.com/2013/07/31/an-introduction-to-inertial-navigation-systems/