【发布时间】:2015-03-04 14:37:04
【问题描述】:
我需要在纵向模式下围绕加速度计的 Y 轴获取 iDevice 的旋转,如图所示,(参考:https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/motion_event_basics/motion_event_basics.html)
我怎样才能围绕 Y 轴进行旋转,无论是正数还是负数。我已经从 stackoverflow/Apple 代码中实现了一些代码,当我在 Y 轴上旋转时,滚动、俯仰和偏航没有任何区别。
[self.motionManager setGyroUpdateInterval:0.1f];
[self.motionManager startGyroUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMGyroData *gyroData, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
NSString *strYaw = [NSString stringWithFormat:@"Yaw: %.02f",gyroData.rotationRate.z];
[self.lblYaw setText:strYaw];
NSString *strPitch = [NSString stringWithFormat:@"Pitch: %.02f",gyroData.rotationRate.x];
[self.lblPitch setText:strPitch];
NSString *strRoll = [NSString stringWithFormat:@"Roll: %.02f",gyroData.rotationRate.y];
[self.lblRoll setText:strRoll];
});
}];
还有这个,
roll = atan2(2*y*w - 2*x*z, 1 - 2*y*y - 2*z*z);
pitch = atan2(2*x*w - 2*y*z, 1 - 2*x*x - 2*z*z);
yaw = asin(2*x*y + 2*z*w);
myRoll = (atan2(2*(quat.y*quat.w - quat.x*quat.z), 1 - 2*quat.y*quat.y - 2*quat.z*quat.z));
myPitch = (atan2(2*(quat.x*quat.w + quat.y*quat.z), 1 - 2*quat.x*quat.x - 2*quat.z*quat.z));
myYaw = (asin(2*quat.x*quat.y + 2*quat.w*quat.z));
任何帮助将不胜感激。
【问题讨论】:
标签: ios rotation accelerometer gyroscope core-motion