Using Vuforia provided Projection Matrix and Marker Pose in SceneKit

会有一股神秘感。 提交于 2019-12-04 12:25:10

It just works!

The hard part is determining what pieces of SceneKit are necessary to make this work. Originally I read the article Making Augmented Reality app easily with Scenekit + Vuforia which outlined how to rejigger the sample app for user-defined targets. The downsides to that article include that it isn't always clear what the author changed, no sample project is provided, and it is based upon an older version of Vuforia. Ultimately, I found it unnecessary to invert the pose matrix.

Draw camera image and set projection matrix and update marker pose

override func viewDidLoad() 
{
    super.viewDidLoad()

    let scene = SmartScanScene()

    let camera = SCNCamera()
    let cameraNode = SCNNode()
    cameraNode.camera = camera
    scene.rootNode.addChildNode(cameraNode)
    _cameraNode = cameraNode

    let view = self.view as! SCNView
    view.backgroundColor = UIColor.blackColor()
    view.showsStatistics = true
    // view.debugOptions = SCNDebugOptions.ShowBoundingBoxes.union(.ShowWireframe)
    view.autoenablesDefaultLighting = true
    view.allowsCameraControl = false
}

func didUpdateProjectionMatrix(projectionMatrix: matrix_float4x4)
{
    let extrinsic = SCNMatrix4FromMat4(projectionMatrix)
    _cameraNode?.camera?.setProjectionTransform(extrinsic)
}

func didUpdateFramemarkers(framemarkers: [Framemarker]?)
{
    guard let framemarkers = framemarkers else {
        return
    }

    for framemarker in framemarkers {
        let pose = SCNMatrix4FromMat4(framemarker.pose)
        self.objectNode?.transform = pose
    }
}

func didUpdateCameraImage(image: UIImage?)
{
    if let image = image {
        _scene?.background.contents = image
    }
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!