景观模式中的增强现实应用

时间:2020-12-11 20:12:15

I am trying to build an augmented reality app using the CoreMotion framework. I have tried to go off of Apple's pARk sample code project, but it only works in portrait mode. I need it to work in landscape. When switched to landscape mode the subviews in the overlay view move in the opposite directions and at the wrong rate (they either move too fast or too slow across screen)

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

I have read other postings that provide two solutions:

我已阅读其他提供两种解决方案的帖子:

  • Create a reference attitude and apply the inverse of that attitude to the current attitude, as suggested in the CoreMotion Tea Pot Example.

    根据CoreMotion Tea Pot示例中的建议,创建参考态度并将该态度的反转应用于当前态度。

  • Rotate the quaternion representation of the attitude 90 degrees

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

I do not think that the first will work because my augmented reality app requires that it be referenced to true north.

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

I also do not understand the math required to do the second.

我也不明白做第二个所需的数学。

Any suggestions on how to accomplish this complex problem I welcome.

关于如何完成这个复杂问题的任何建议我都欢迎。

2 个解决方案

#1


0  

How far are you now in your augmented reality app? I think beginning by taking a look at PARk from Apple is harsh. You need to have some advanced mathematical understanding. But if you do, why not!

你现在在增强现实应用程序中有多远?我想从Apple开始看看PARK是非常严厉的。你需要有一些高级的数学理解。但如果你这样做,为什么不呢!

you can take a look at this repository, this an augmented reality project working on Portrait and Landscape mode. Here is how the rotation is handled:

您可以查看此存储库,这是一个处理纵向和横向模式的增强现实项目。以下是旋转的处理方式:

- (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;

}
}

You have to rotate all your annotations and then your overlay view after the device rotation!

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

#2


0  

If you're really stuck, and are willing to use another toolkit, try iPhone-AR-Toolkit. It works in both portrait and landscape.

如果您真的卡住了,并且愿意使用其他工具包,请尝试使用iPhone-AR-Toolkit。它适用于纵向和横向。

#1


0  

How far are you now in your augmented reality app? I think beginning by taking a look at PARk from Apple is harsh. You need to have some advanced mathematical understanding. But if you do, why not!

你现在在增强现实应用程序中有多远?我想从Apple开始看看PARK是非常严厉的。你需要有一些高级的数学理解。但如果你这样做,为什么不呢!

you can take a look at this repository, this an augmented reality project working on Portrait and Landscape mode. Here is how the rotation is handled:

您可以查看此存储库,这是一个处理纵向和横向模式的增强现实项目。以下是旋转的处理方式:

- (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;

}
}

You have to rotate all your annotations and then your overlay view after the device rotation!

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

#2


0  

If you're really stuck, and are willing to use another toolkit, try iPhone-AR-Toolkit. It works in both portrait and landscape.

如果您真的卡住了,并且愿意使用其他工具包,请尝试使用iPhone-AR-Toolkit。它适用于纵向和横向。

相关文章