Get a reference CMAttitude (aTtitude, not aLtitude) from ground level in CoreMotion

StackOverflow https://stackoverflow.com/questions/10187120

  •  01-06-2021
  •  | 
  •  

Question

I'd like to get a reference CMAttitude based on the ground level, for instance, to draw horizon line.

Actually, I'm able to rotate my views by getting a reference attitude at any time and using multiplyByInverseOfAttitude to get handset rotation compared to previous attitude. That's fine.

But I'm unable to find how to get it for the ground at start. I'm mainly in portrait mode, IOS5, and using CMAttitudeReferenceFrameXTrueNorthZVertical (as I also make use of CoreLocation).

I've looked to bubble level or teapot samples (using accelerator) but haven't found a simple answer or sample to my problem with device motion attitudes. I'm probably missing something.

Thanks.

Était-ce utile?

La solution

My own answer.

Actually, I was in wrong way considering the use of reference attitude. I just needed to compute the rotation angle from the gravity available in deviceMotion object like this:

    double rotation = atan2(dm.gravity.x, dm.gravity.y) - M_PI;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top