在 SceneKit 中使用 Vuforia 提供的投影矩阵和标记姿势 [英] Using Vuforia provided Projection Matrix and Marker Pose in SceneKit

查看:71
本文介绍了在 SceneKit 中使用 Vuforia 提供的投影矩阵和标记姿势的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在尝试解决在 SceneKit 中渲染时使用投影矩阵和帧标记姿势的问题.场景中的模型和相机图像背景出现没有问题.但是,一旦我更改了投影矩阵和帧标记姿势矩阵以匹配 Vuforia,一切都会被推到屏幕外.

Currently I'm trying to troubleshoot the use of the projection matrix and framemarker pose when rendering in SceneKit. The model in the scene and the camera image background appear without problems. However, once I change the projection matrix and framemarker pose matrix to match Vuforia everything is pushed offscreen.

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

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

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

这是设置 SCNCamera 和对象节点的正确方法吗?设置 Vuforia 帧标记以使用 SceneKit 还需要其他什么吗?

Is this a correct way to setup the SCNCamera and object node and is there anything else required to setup Vuforia framemarkers to work with SceneKit?

推荐答案

效果很好!

困难的部分是确定需要哪些 SceneKit 来完成这项工作.最初我阅读了文章 使用 Scenekit + Vuforia 轻松制作增强现实应用,其中概述了如何重新调整示例用于用户定义目标的应用程序.该文章的缺点包括作者更改的内容并不总是很清楚,没有提供示例项目,并且它基于旧版本的 Vuforia.最终,我发现没有必要反转姿势矩阵.

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.

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
    }
}

这篇关于在 SceneKit 中使用 Vuforia 提供的投影矩阵和标记姿势的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆