Here is a link to the 3d web compass I built and submitted to Hacker News 3 years ago [1] (direct link to a demo @ [2]).
I also released a JavaScript library based on that research that may help others use web device orientation without needing to understand all the math involved [3]. That in turn is based on a primer I made for web developers @ [4].
I hope this helps others who want to use device orientation on the web to build web-based compasses, Virtual Reality and Augmented Reality experiences!