Augmented Reality App in Landscape Mode

风流意气都作罢 提交于 2019-12-07 01:00:34

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!

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!

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!