iOS - gyroscope sample

元气小坏坏 提交于 2019-12-11 23:56:42

问题


I am looking for writing a code which makes use of Gyroscope in 'pull' fashion. I fid sample code which makes use of startGyroUpdatesToQueue:withHandler: [ "Push' approach ]. I wish to make use of startGyroUpdates instead. I want to display the gyro updates continuously on screen without using startGyroUpdatesToQueue:withHandler: Is this possible? If yes, is there any sample I can refer to.

Thanks in advance


回答1:


It's pretty straightforward. To get startet you should read the Event Handling Guide especially the section Handling Processed Device-Motion Data.

You just have to keep a reference to CMMotionManager and then read motionManager.deviceMotion.attitude for example in your drawView method - a more sophisticated approach is putting it into an own thread, but in most cases there is no need to do it that way. CMAttitude provides you with Euler angles (pitch, roll, yaw), rotation matrix or quaternion representation of the gyro updates. CMDeviceMotion contains the timestamp.

You can find sample code in the teapot demo from the WWDC 2010 session videos, look at my answer in CMMotionManager and the Gyroscope on iPhone 4. Processing is done in EAGLView and although they do more accelerometer stuff to show the difference, you will find the set up and usage of referenceAttitude.



来源:https://stackoverflow.com/questions/7237763/ios-gyroscope-sample

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!