LiDAR – ARMeshAnchor to SCNNode, get some manipulation with it

229 views Asked by At

I've run this Git. What I'm trying to do is when the node is further than the distance I set, for example 1 meter, node is removed. With in it, I've added this method (Code 1).

Code 1

func getDistanceBtw(cameraPostion: SCNVector3, nodePosition: SCNVector3) -> Float {
    let powX = (cameraPostion.x - nodePosition.x) * (cameraPostion.x - nodePosition.x)
    let powY = (cameraPostion.y - nodePosition.y) * (cameraPostion.y - nodePosition.y)
    let powZ = (cameraPostion.z - nodePosition.z) * (cameraPostion.z - nodePosition.z)
    let powXYZ = powX + powY + powZ
    let distance = sqrt(powXYZ)
    return distance
}

And in renderer didUpdate Node method, I added... (Code 2)

Code 2

let cameraPostion = sceneView.pointOfView?.position
let nodePosition = node.position

if getDistanceBtw(cameraPostion: cameraPostion!, 
                   nodePosition: nodePosition) > 1 {
    node.removeFromParentNode()
}

I thought this my solve what I want to achieve, it did something but not what I wanted.

0

There are 0 answers