The Sensor Fusion Toolbox for Android includes a feature illustrating how an air mouse might be implemented on top of the Freescale sensor fusion library. That tool includes documentation which discusses the algorithm. That documentation is replicated on the MEMS Industry Group GitHub site. It's been pointed out that this could use a couple additional diagrams to illustrate the geometry behind the calculations. For that, please see the attached.
BTW, The preview below has been somewhat corrupted by the blogging platform. I suggest you download the powerpoint file before viewing.