我在初始化时这样声明我的相机:
defaultCameraNode.camera = SCNCamera()
defaultCameraNode.position = SCNVector3Make(0, 200, 500)
defaultCameraNode.camera?.zFar = 1000.0
defaultCameraNode.camera?.zNear = 10.0
defaultCameraNode.camera?.xFov = 30.0
defaultCameraNode.camera?.yFov = 30.0
scene.rootNode.addChildNode(defaultCameraNode)
sceneView.pointOfView = defaultCameraNode
defaultCameraNode.constraints = [SCNLookAtConstraint(target: rootNode)]
在此之后,在 tapGesture 块中,我进行了命中测试:
let hitResults = sceneView.hitTest(sender.locationInView(sceneView), options: nil)
这返回了我想要的,得到了节点。在我添加一个新相机并改变场景的视角之后
var cameraNode = SCNNode()
cameraNode.name = "cameraNode"
cameraNode.position = SCNVector3Make(position.x, position.y + 50.0, position.z + Float(radius * 3))
cameraNode.rotation = SCNVector4Make(1, 0, 0, -atan2f(20.0, 40.0))
var camera = SCNCamera()
camera.zNear = 0.0
camera.zFar = 1000.0
camera.xFov = 40.0
camera.yFov = 40.0
cameraNode.camera = camera
node.addChildNode(cameraNode)
SCNTransaction.begin()
SCNTransaction.setAnimationDuration(animationDuration)
sceneView.pointOfView = cameraNode
SCNTransaction.commit()
当相机位置改变时,我之前使用的相同命中测试返回一个长度为 0 的数组并在控制台上出现此错误:
SceneKit: error, error in _C3DUnProjectPoints
任何人都可以帮我解决这个问题吗?谢谢