0
ARKitアプリケーションで最も近い平面の位置を見つけようとしていました。私はそれを見つけるのに役立ついくつかのコードを書いたが、何らかの理由で、私は私のアプリケーションを実行するとき、私は飛行機にARオブジェクトを追加しようとするとクラッシュし続けます。私のコードに何か問題がありますか?ARKitの平面位置を見つける
struct myPlaneCoords {
var x = Float()
var y = Float()
var z = Float();
}
func getPlaneCoordinates(sceneView: ARSCNView) -> myPlaneCoords{//coordinates where an AR node will be added
let cameraTransform = sceneView.session.currentFrame?.camera.transform
let cameraCoordinates = MDLTransform(matrix: cameraTransform!)
let camX = CGFloat(cameraCoordinates.translation.x)
let camY = CGFloat(cameraCoordinates.translation.y)
let cameraPosition = CGPoint(x: camX, y: camY)
let anchors = sceneView.hitTest(cameraPosition, types: ARHitTestResult.ResultType.existingPlane)
let spefAnchor = MDLTransform(matrix: anchors[0].localTransform)//finds closest plane
var cc = myPlaneCoords()
cc.x = spefAnchor.translation.x
cc.y = spefAnchor.translation.y
cc.z = spefAnchor.translation.z
return cc
}
クラッシュはどこですか?正確なエラーメッセージは何ですか? –