私は球の周りを動かすときに球の表面にその底を平らに置くように円錐の向きを変えようとしています。SCNNodeを球上のある点から別の点に移動したSCNMatrix4変換を見つけるにはどうすればよいですか?
球は半径4で原点を中心にしています。
変換の四元数を推測しようとしましたが、円錐自体のピボットプロパティを使用する方が簡単です。
私はそれを既知の角度で回転させることで軸上の単純な場所で動作させることができますが、円錐の位置ベクトルから変換を推測する方法はわかりません。私は、球の表面上の点の位置ベクトルと円錐のデフォルトの向きを表すVectorを取って、必要な新しい向きにデフォルトの向きを変換するSCNMatrix4を計算する必要があると思います。次に、それを使ってSCNNodeのピボットを変換することができます。問題の一部は、デフォルトの方向ベクトルが何であるかわからないということです。
これは私が(それが動作しません)これまで持っているものです。
let distanceFromCentre = Float(4.0)
let newConeNode = SCNNode(geometry: SCNCone(topRadius: 0, bottomRadius: 0.5, height: 1.0))
let radialLocationVector = SCNVector3Make(0.0, 1.0, 1.0)
let radialLocationVectorMagnitude = pow((pow(radialLocationVector.x,2) + pow(radialLocationVector.y,2) + pow(radialLocationVector.z,2)),0.5)
let radialLocationUnitVector = SCNVector3Make(radialLocationVector.x/radialLocationVectorMagnitude, radialLocationVector.y/radialLocationVectorMagnitude, radialLocationVector.z/radialLocationVectorMagnitude)
let surfaceLocationVector = SCNVector3Make(radialLocationUnitVector.x*distanceFromCentre, radialLocationUnitVector.y*distanceFromCentre, radialLocationUnitVector.z*distanceFromCentre)
newConeNode.position = surfaceLocationVector
let nodePivotRotationMatrix = SCNMatrix4MakeRotation(0,radialLocationUnitVector.x, radialLocationUnitVector.y, radialLocationUnitVector.z) //This doesn't work
let nodePivotTranslationMatrix = SCNMatrix4MakeTranslation(0, -0.5, 0)
newConeNode.pivot = SCNMatrix4Mult(nodePivotRotationMatrix, nodePivotTranslationMatrix)
newConeNode.name = "MyCone"
newConeNode.geometry?.firstMaterial?.diffuse.contents = UIColor(red: 0.2, green: 0, blue: 0.8, alpha: 1.0)
scnView.scene?.rootNode.addChildNode(newConeNode)
すべてのヘルプは感謝して