iOS - gyroscope sample
I am lo开发者_如何学Coking 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
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.
精彩评论