iOS Angle Extension
This extension is provided as-is without warranty. You are free to use it to your heart's content at your own risk.
First of all, download the Zip file from here:
Once downloaded extract the zip file and follow these instructions:
1. Copy Angle.mfx into your MMF2 Program folder under Extensions
2. Copy Angle.ext to your MMF2 Program folder under Data\Runtime\iPhone
3. If you plan to create a PC version of your App copy Angle.mfx into your MMF2 Program folder under Data\Runtime.
There is a sample project called Angle Test.mfa that you can test with. The angle is returned as a value between 0 and 359 just like MMF2 likes for setting the angle of Actives.
Two very important thing:
1. On Windows and in the iOS Simulator Angle events DO NOT OCCUR so you always get 0. This will only work on a real iOS running device and is a limitation of the iOS Simulator not the coding.
2. Every iOS device has a slight imperfection around angle (+/- 4 degrees and rumor is sometimes more) so you may want to either approximate the angle to quantized values such as Int(CurrentAngle/15) * 15 or you may even want to add a simple calibration routine to your app.
The technique I use to quantize Int(CurrentAngle/15) * 15 above is also a good way to smooth out the reading. I suggest you play with this approach to get the reaction you want though you may simply just want the real deal.
If you have any questions or suggestions PM me. Hope this helps you guys out.
Final note: this was tested on an iPhone 4S, iPad 2, and iPhone 3GS and works. The angle is always relative to if the device was upright with the Home button at the bottom. If you run your app in a different orientation you'll need to adjust accordingly.
Thanks for this one too, Keith! I've got a dozen or so ideas for this so far! Have yet to test it, but I will today.
Unfortunately, this object causes a EXC_BAD_ACCESS error when it is in the frame and the app wants to leave that frame.
Tested on iPhone 4S, iOS 6.1.3. The crash does not appear in the simulator, though.
It is a nice extension, by the way! Thanks for creating it! :)