iOS 4核心运动态度在横向定位 [英] iOS 4 core motion attitude in landscape orientation

查看:131
本文介绍了iOS 4核心运动态度在横向定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在尝试根据CMMotionManager返回的CMAttitude旋转我的视图,特别是pitch = x和roll = y。我正在用一种参考态度来设定我的视野。
这对于肖像模式非常有用,但是当我尝试为横向视图进行操作时它出错了。
由于手机现在旋转90 ccw,我希望coremotion知道景观已经到位,并保持音高和滚动有用。相反,我仍然有轴指向他们原来的方式。
要尝试补偿,我只需更改roll = x和切换音高= y的符号。
这似乎有效,直到我把设备放在我面前并转过180度。视图颠倒并倒置。

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.

推荐答案

你是对的,改变音高和滚动会导致严重的麻烦。最简单的方法似乎与CoreMotionTeapot示例中的新参考态度一起使用。正好在检测到方向变化时,您必须先抓住当前姿态,然后再将其与之前的参考姿态相乘,并将其设置为新的参考姿态。

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.

这篇关于iOS 4核心运动态度在横向定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆