HomeiOS Developmentios - Swift modify node rotation based mostly on globe coordinates

ios – Swift modify node rotation based mostly on globe coordinates


I’ve a 3d globe constructed with swift and SceneKit and to signify the customers present location I exploit a torus (donut formed object). The customers location might be wherever on the planet and easily including the node to the globe doesn’t make it flush (aligned with globe). I’ve to change the nodes eulerAngles so as to make it flat with the earth. My operate does not work to correctly align the form with the earth given any distinctive location. I would like the operate to place the torus flush based mostly on any set of latitude and longitude.

    let dotNode = SCNNode(geometry: lowerCircle)
 
    dotNode.eulerAngles = getRotation(lat: viewModel.currentLocation?.lat ?? 0.0, lengthy: viewModel.currentLocation?.lengthy ?? 0.0)

    func getRotation(lat: Double, lengthy: Double) -> SCNVector3 {
        let latRad = lat * .pi / 180.0
        let lonRad = lengthy * .pi / 180.0

        let rotationX = Float(-latRad)
        let rotationY = Float(lonRad)
        let rotationZ = Float(lonRad)

        return SCNVector3Make(rotationX, rotationY, rotationZ)
        
        //instance
        //barely right rotation for Saudi Arabia
        //SCNVector3Make(.pi / 3.75, 0, -.pi / 4)
    }

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments