doc
doc

Reputation: 266

iOS gyroscope to make virtual horizon

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.

Upvotes: 6

Views: 1313

Answers (1)

doc
doc

Reputation: 266

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];
                                               }];

Upvotes: 7

Related Questions