2012-08-10 30 views
1

我正在嘗試使用CoreMotion框架構建增強現實應用程序。我試圖脫離Apple的pARk示例代碼項目,但它只能在縱向模式下工作。我需要它在風景中工作。當在相反方向上的重疊視圖移動和在錯誤的速度切換到橫向模式的子視圖(他們要麼移動得太快或跨屏太慢)風景模式下的增強現實應用程序

我已閱讀other postings提供兩種解決方案:

  • 如CoreMotion Tea Pot Example所示,創建一個參考姿態並將該姿態的倒數應用於當前姿態。

  • 旋轉姿態的四元數表示90度

我不認爲,首先會工作,因爲我的增強現實應用程序需要它被引用到真北。

我也不明白做第二個要求的數學。

關於如何完成這個複雜的問題,我很歡迎。

回答

0

你現在在你的增強現實應用程序中有多遠?我認爲從Apple看看PARK是非常苛刻的。你需要有一些先進的數學理解。但如果你這樣做,爲什麼不呢!

你可以看看這個repository,這是一個在肖像和風景模式下工作的增強現實項目。這裏是如何處理旋轉:

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

} 
} 

你必須旋轉所有的註釋,然後旋轉設備後的覆蓋視圖!

+0

Repository中的一個很好的例子 – 2012-10-29 06:58:34

0

如果你真的陷入困境,並願意使用其他工具包,請嘗試iPhone-AR-Toolkit。它適用於縱向和橫向。

+0

我試過你的框架,但疊加視圖的移動太過分了。蘋果pARk的運動更順暢。 – 2014-07-02 23:11:52