6

I'm looking to include a virtual horizon for my app using gyroscope, like this one

I found a lot of documentation on the gyro and i think i use yaw but i don't know how to calibrate with gravity.

Can someone help me please ??

thanks.

doc
  • 266
  • 2
  • 15
  • Does this SO post answer you question? http://stackoverflow.com/questions/3723985/calibrating-code-to-iphone-acellerometer-and-gyro-data – ajmccall May 09 '12 at 14:53
  • thanks ajmccall for your reply, but no. I want to make a visual horizon, like the link above, i know how to get info to rotate my layer, but it is initialized in the position i launch the app. I want to initiate my layer in the real position of horizon. thanks. – doc May 09 '12 at 16:38

1 Answers1

7

I solved my problem with this:

- (void)updateImage: (NSNumber *)rotNum
{
    self.image.transform = CGAffineTransformMakeRotation([rotNum floatValue]);
}

// call the above function to rotate the image in reference to the horizon
[motionManager startDeviceMotionUpdatesToQueue: gyroQueue
                                   withHandler: ^(CMDeviceMotion *motion, NSError *error) {
                                                       [self performSelectorOnMainThread: @selector(updateImage:)
                                                                              withObject: [NSNumber numberWithDouble: atan2(motion.gravity.x, motion.gravity.y)-M_PI]
                                                                           waitUntilDone: NO];
                                               }];
ajmccall
  • 2,024
  • 23
  • 42
doc
  • 266
  • 2
  • 15