Cylinder Orientation between two points on a sphere, Scenekit, Quaternions IOS

后端 未结 6 882
南笙
南笙 2020-12-17 00:04

I\'ve been trying to draw a cylinder between two points on the outer edge of a sphere using SceneKit. I have already produced a line between these two points using primitive

6条回答
  •  伪装坚强ぢ
    2020-12-17 00:20

    i use SCNVector3 extensions with:

     func cylVector(from : SCNVector3, to : SCNVector3) -> SCNNode {
        let vector = to - from,
            length = vector.length()
    
        let cylinder = SCNCylinder(radius: cylsRadius, height: CGFloat(length))
        cylinder.radialSegmentCount = 6
        cylinder.firstMaterial = material
    
        let node = SCNNode(geometry: cylinder)
    
        node.position = (to + from) / 2
        node.eulerAngles = SCNVector3Make(CGFloat(Double.pi/2), acos((to.z-from.z)/length), atan2((to.y-from.y), (to.x-from.x) ))
    
        return node
    }
    

提交回复
热议问题