ios – Camera rotation to position doesn’t work correctly


I have a 3D globe represented by SCNNodes (dots). I also add a highlight on the node in the location of New York. After the view renders I try and rotate the view to show the highlighted node. My calculations to do so are wrong because the globe is rotated to the opposite side from where the point is.

func alignPointToPositiveZ(for sphereNode: SCNNode, targetPoint: SCNVector3) {
    // Compute normalized vector from Earth's center to the target point
    let targetDirection = targetPoint.normalized()
    
    // Compute quaternion rotation
    let up = SCNVector3(0, 0, 1)
    let rotationQuaternion = SCNQuaternion.fromVectorRotate(from: up, to: targetDirection)
    
    sphereNode.orientation = rotationQuaternion
}

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img