Got it!添加容器節點非常簡單。以下似乎適用於任何象限中的任何位置。
// pointAt_c is a container node located at, and child of, the originNode
// pointAtNode is its child, position coincident with pointAt_c (and originNode)
// get deltas (positions of target relative to origin)
let dx = targetNode.position.x - originNode.position.x
let dy = targetNode.position.y - originNode.position.y
let dz = targetNode.position.z - originNode.position.z
// rotate container node about y-axis (pointAtNode rotated with it)
let y_angle = atan2(dx, dz)
pointAt_c.rotation = SCNVector4(0.0, 1.0, 0.0, y_angle)
// now rotate the pointAtNode about its z-axis
let dz_dx = sqrt((dz * dz) + (dx * dx))
// (due to rotation the adjacent side of this angle is now a hypotenuse)
let x_angle = atan2(dz_dx, dy)
pointAtNode.rotation = SCNVector4(1.0, 0.0, 0.0, x_angle)
我需要這個替換lookAt約束,不管怎麼說,這個約束都不能輕易歸檔到節點樹中。我指的是Y軸,因爲這就是SCN圓柱體和膠囊的導向。
如果有人知道如何避免容器節點請告訴。每次我嘗試將順序旋轉應用於單個節點時,最後一次會覆蓋前一個節點。我不知道如何制定一個旋轉表達式來一次完成它。
好吧,我很困惑。 3D點不具有旋轉,它們具有沿給定軸的x/y/z點。你正在繪製'r',就好像它是一個矢量。你是否在'y'軸上尋找原點和目標之間的梯度? – Michael
對不起。這些意味着是向量表示。我試圖定位的是SCNNode。我不知道術語梯度如何應用於此。謝謝,Byrne – bpedit