2017-07-15 69 views
2

我正在嘗試使用ARKit,我的問題很簡單。 如何獲取相機的位置?ARKit - 相機的位置?

我知道,如果我把一個SCNode放在(0,0,0)上,而我的相機正在尋找地面,我將不得不擡頭看3D對象。這意味着設備的相機的位置和方向必須可以訪問。

那麼我怎麼知道哪裏的相機是她看着

感謝提前:)

+2

的可能的複製[ARKit - 獲取場景 '相機' 的當前位置(https://stackoverflow.com/questions/45084187/arkit-get-current-position-of-camera-in-scene) – orangenkopf

+0

這部分回答了我的問題。我明白相機轉換是什麼,但我不知道如何使用它來改變我的SCNode的座標。 你能向我解釋一下嗎? :) –

回答

7

可以使用ARCamera.transform屬性,讓您的相機的當前變換。 以下代碼來自Introducing ARKit at WWDC 2017,您可能想要將其作爲介紹來觀看。 我們正在使用轉換在攝像機前放置一個10釐米的節點。

在夫特:

var translation = matrix_identity_float4x4 
translation.columns.3.z = -0.1 // Translate 10 cm in front of the camera 
node.simdTransform = matrix_multiply(currentFrame.camera.transform, translation) 

在Objective-C

matrix_float4x4 translation = matrix_identity_float4x4; 
translation.columns[3][2] = -0.1; // Translate 10 cm in front of the camera 
node.simdTransform = matrix_multiply(currentFrame.camera.transform, translation) 
+0

這就是我所說的真正的英雄!非常感謝 ! 如果我想偏移x和y座標,它也在第3列? –

+1

你應該閱讀和學習一些基本的3D圖形和[轉換矩陣](https://en.wikipedia.org/wiki/Transformation_matrix#Examples_in_3D_computer_graphics) – orangenkopf

+0

你可以在Objective c中複製嗎? –