增强现实应用程序在景观模式

我正在尝试使用CoreMotion框架构build增强现实应用程序。 我试图从苹果的pARk示例代码项目,但它只能在肖像模式下工作。 我需要它在景观工作。 当切换到横向模式时,叠加视图中的子视图以相反的方向移动并以错误的速率移动(它们在屏幕上移动得太快或太慢)

我已阅读其他post ,提供了两个解决scheme:

  • 如CoreMotion茶壶示例中所build议的那样,创build参考姿态并将该姿态的反转应用于当前姿态。

  • 旋转姿态90度的四元数表示

我不认为第一个会工作,因为我的增强现实应用程序要求它被引用到真正的北方。

我也不明白做第二个练习所需的math。

如何完成这个复杂的问题,我欢迎任何build议。

你现在在你的增强现实应用程序中有多远? 我觉得从苹果开始看PARK是苛刻的。 你需要有一些先进的math理解。 但是,如果你这样做,为什么不呢!

你可以看看这个仓库 ,这是一个在肖像和风景模式下工作的增强现实项目。 这是如何处理旋转:

- (void)deviceOrientationDidChange:(NSNotification *)notification { prevHeading = HEADING_NOT_SET; [self currentDeviceOrientation]; UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; // Later we may handle the Orientation of Faceup to show a Map. For now let's ignore it. if (orientation != UIDeviceOrientationUnknown && orientation != UIDeviceOrientationFaceUp && orientation != UIDeviceOrientationFaceDown) { CGAffineTransform transform = CGAffineTransformMakeRotation(degreesToRadian(0)); CGRect bounds = [[UIScreen mainScreen] bounds]; switch (orientation) { case UIDeviceOrientationLandscapeLeft: transform = CGAffineTransformMakeRotation(degreesToRadian(90)); bounds.size.width = [[UIScreen mainScreen] bounds].size.height; bounds.size.height = [[UIScreen mainScreen] bounds].size.width; break; case UIDeviceOrientationLandscapeRight: transform = CGAffineTransformMakeRotation(degreesToRadian(-90)); bounds.size.width = [[UIScreen mainScreen] bounds].size.height; bounds.size.height = [[UIScreen mainScreen] bounds].size.width; break; case UIDeviceOrientationPortraitUpsideDown: transform = CGAffineTransformMakeRotation(degreesToRadian(180)); break; default: break; } [displayView setTransform:CGAffineTransformIdentity]; [displayView setTransform: transform]; [displayView setBounds:bounds]; degreeRange = [self displayView].bounds.size.width / ADJUST_BY; } } 

设备旋转后,您必须旋转所有注释,然后旋转覆盖视图!

如果你真的陷入困境,并愿意使用其他工具包,请尝试iPhone-AR-Toolkit 。 它适用于肖像和风景。

Interesting Posts