ios - 创建与相机平行的垂直 SCNPlane
<p><p>我想在用户点击相机正前方的屏幕时创建一个 SCNPlane,我可以创建平面但它不平行于相机</p>
<pre><code> 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)
</code></pre>
<p>我如何定位平行于相机的平面?
感谢您的帮助</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>只需旋转你的飞机</p>
<pre><code> 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)
</code></pre></p>
<p style="font-size: 20px;">关于ios - 创建与相机平行的垂直 SCNPlane,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/48097081/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/48097081/
</a>
</p>
页:
[1]