Get CMAttitude Link (aTtitude, not aLtitude) from Ground Level in CoreMotion

I would like to get a CMAttitude link based on ground level, for example to draw a horizon line.

In fact, I can turn my eyes around by getting a link at any time and using multiplyByInverseOfAttitude to get the phone rotated from the previous ratio. It's fine.

But I can’t find how to get it to start at the beginning. I am mainly in portrait mode, IOS5 and using CMAttitudeReferenceFrameXTrueNorthZVertical (since I also use CoreLocation).

I searched for samples of bubbles or samples of dummies (using an accelerator), but did not find a simple answer or sample for my problem with the device’s motion settings. I probably missed something.

Thank.

+3
source share
1 answer

My own answer.

Actually, I was wrong, given the use of the reference relation. I just need to calculate the angle of rotation from the gravity available in the deviceMotion object as follows:

    double rotation = atan2(dm.gravity.x, dm.gravity.y) - M_PI;
+3
source

All Articles