Reputation: 41
I've been trying to rotate my view based on the CMAttitude returned from CMMotionManager specifically the pitch=x and roll=y. I'm using a reference attitude to set my horizon. This works great for portrait mode but the minute i try to do it for a landscape view it goes wrong. As the phone is now rotated 90 ccw I was hoping that coremotion would know landscape was in place and keep the pitch and roll useful. Instead I still have the axis pointing their original way. To try and compensate I simply changed the sign on roll=x and switched pitch=y. This appeared to work till I held the device in front of me and the turned around 180 degrees. The view spun upside down and inverted.
My spidy sense is telling me I need to apply a proper transformation on the pitch roll and yaw to reorientate the attitude
I'm hoping some geniuses or genii can help me. Maths is obviously not a strong point of mine.
Upvotes: 4
Views: 2500
Reputation: 13146
Your are right, changing pitch and roll will lead into serious trouble. The simplest way seems to work with a new reference attitude like in CoreMotionTeapot sample. Just when the orientation change is detected, you have to grab the current attitude before multiplying it with your former reference attitude and set it as new reference attitude.
Upvotes: 3