2017-07-19 4 views
3

カメラがどの方向を向いているかを調べる必要があります。それがZ +、Z-、X +、またはX-の方を見ているならば。スウィフトシーンキット - カメラの方向を取得

私はオイラーアングルを使ってみましたが、ヨーの範囲は0 - > 90 - > 0 - > 90 - > 0です。それらの軸の正または負の方向に向かって見ている。

答えて

5

worldFrontプロパティに配置するSCNNodeを作成すると、x、y、z方向のベクトルを取得できます。あなたがそれを行うことができ

もう一つの方法は、このプロジェクトはそれをやったかのようである:あなたのタグが示唆するよう

// Credit to https://github.com/farice/ARShooter 

func getUserVector() -> (SCNVector3, SCNVector3) { // (direction, position) 
     if let frame = self.sceneView.session.currentFrame { 
      let mat = SCNMatrix4(frame.camera.transform) // 4x4 transform matrix describing camera in world space 
      let dir = SCNVector3(-1 * mat.m31, -1 * mat.m32, -1 * mat.m33) // orientation of camera in world space 
      let pos = SCNVector3(mat.m41, mat.m42, mat.m43) // location of camera in world space 

      return (dir, pos) 
     } 
     return (SCNVector3(0, 0, -1), SCNVector3(0, 0, -0.2)) 
    } 
+0

また、これは、あなたがARKitを使用していることを想定しています – wriuhasdfhvhasdv

関連する問題