gpt4 book ai didi

ios - 在 iOS 中以度数或弧度在 Y 轴上旋转

转载 作者:行者123 更新时间:2023-11-29 02:14:57 28 4
gpt4 key购买 nike

我需要在纵向模式下为 iDevice 获取旋转,围绕加速度计的 Y 轴,如图所示,(引用:https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/motion_event_basics/motion_event_basics.html)enter image description here

如何绕 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));

任何帮助将不胜感激。

最佳答案

#import "ViewController.h"
#import <CoreMotion/CoreMotion.h>

@interface ViewController ()
@property (strong, nonatomic) CMMotionManager *motionManager;

@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
self.motionManager = [[CMMotionManager alloc] init];
self.motionManager.accelerometerUpdateInterval = .2;
self.motionManager.gyroUpdateInterval = .2;

[self.motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue currentQueue]
withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
[self outputAccelertionData:accelerometerData.acceleration];
if(error){
NSLog(@"%@", error);
}
}];

[self.motionManager startGyroUpdatesToQueue:[NSOperationQueue currentQueue]
withHandler:^(CMGyroData *gyroData, NSError *error) {
[self outputRotationData:gyroData.rotationRate];
}];
}

-(void)outputAccelertionData:(CMAcceleration)acceleration
{

}
-(void)outputRotationData:(CMRotationRate)rotation
{
NSLog(@"(%f)",rotation.y);
}

@end

玩得开心。

关于ios - 在 iOS 中以度数或弧度在 Y 轴上旋转,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28857165/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com