创建与摄像机平行的垂直SCNPlane

时间:2018-01-04 14:12:32

标签: ios swift3 arkit

我想在用户点击相机前面的屏幕时创建一个SCNPlane,我可以创建该平面,但它与摄像机不平行

    guard let sceneView = sender.view as? ARSCNView else {return}
    guard let currentFrame = sceneView.session.currentFrame else {return}
    let camera = currentFrame.camera
    let transform = camera.transform
    var translationMatrix = matrix_identity_float4x4
    translationMatrix.columns.3.z = -0.1
    var modifiedMatrix = simd_mul(transform, translationMatrix)
    let plane = SCNNode(geometry: SCNPlane(width: 0.42, height: 0.63))
    plane.geometry?.firstMaterial?.diffuse.contents = UIColor.yellow
    plane.simdTransform = modifiedMatrix
    self.sceneView.scene.rootNode.addChildNode(sphere)

如何定位平行于相机的平面? 谢谢你的帮助

2 个答案:

答案 0 :(得分:2)

只需旋转你的飞机

    guard let sceneView = sender.view as? ARSCNView else {return}
    guard let currentFrame = sceneView.session.currentFrame else {return}
    let camera = currentFrame.camera
    let transform = SCNMatrix4(camera.transform)
    let translationMatrix = SCNMatrix4Rotate(
        SCNMatrix4MakeTranslation(0, 0, -0.1),
        Float.pi / 2,
        1, 0, 0)
    let modifiedMatrix = SCNMatrix4Mult(transform, translationMatrix)
    let plane = SCNNode(geometry: SCNPlane(width: 0.42, height: 0.63))
    plane.geometry?.firstMaterial?.diffuse.contents = UIColor.yellow
    plane.transform = modifiedMatrix
    self.sceneView.scene.rootNode.addChildNode(plane)

答案 1 :(得分:1)

使用

旋转
node.eulerAngles.x = -.pi / 2

对我来说很棒。最初,我有一个与相机平行的平面节点,但现在它位于地面上。