开发者

Using the gyroscope with Monotouch?

开发者 https://www.devze.com 2023-03-22 01:28 出处:网络
Can anybo开发者_JAVA百科dy provide me with an example on how to use the gyroscope with Monotouch?I can\'t figure out how to respond to gyro update events.

Can anybo开发者_JAVA百科dy provide me with an example on how to use the gyroscope with Monotouch? I can't figure out how to respond to gyro update events.

Thanks!


Here is a simple example:

using MonoTouch.CoreMotion;
//..

CMMotionManager motionManager;
private void StartGyro()
{
    motionManager = new CMMotionManager();
    motionManager.GyroUpdateInterval = 1/10;
    if (motionManager.GyroAvailable)
    {
        motionManager.StartGyroUpdates(NSOperationQueue.MainQueue, GyroData_Received);
    }
}

private void GyroData_Received(CMGyroData gyroData, NSError error)
{
    Console.WriteLine("rotation rate x: {0}, y: {1}, z: {2}", 
    gyroData.RotationRate.x, gyroData.RotationRate.y, gyroData.RotationRate.z);
}

Each of the three values of the RotationRate property of the CMGyroData instance is the amount of rotation angle per second on each axis, in radians.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号