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.
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];
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With