【问题标题】:SceneKit – Get direction of cameraSceneKit - 获取相机的方向
【发布时间】:2017-12-24 10:18:58
【问题描述】:

我需要找出相机正在看的方向,例如如果它正在寻找Z+Z-X+X-

我试过使用eulerAngles,但是偏航的范围是0 -> 90 -> 0 -> -90 -> 0 这意味着我只能检测到相机是否看向ZX,而不是看向这些轴的正方向或负方向。

【问题讨论】:

    标签: swift camera scenekit direction arkit


    【解决方案1】:

    您可以创建一个 SCNNode 并将其放置在 worldFront 属性中以获取具有 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))
        }
    

    【讨论】:

    • 另外,这是假设您使用的是 ARKit,正如您的标签所暗示的那样
    • 我没看懂,计算“dir”后怎么知道方向??
    猜你喜欢
    • 2016-02-09
    • 2017-01-11
    • 2016-02-06
    • 2016-02-02
    • 1970-01-01
    • 2013-01-26
    • 2018-07-29
    • 1970-01-01
    • 2023-03-03
    相关资源
    最近更新 更多