gpt4 book ai didi

ios - 创建平行于相机的垂直 SCNPlane

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:53:33 24 4
gpt4 key购买 nike

我想在用户点击相机前面的屏幕时创建一个 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)

如何使平面与相机平行?谢谢你的帮助

最佳答案

只需旋转你的飞机

    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)

关于ios - 创建平行于相机的垂直 SCNPlane,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48097081/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com