假设在三维空间中有两个点。调用第一个o作为原点,调用另一个t作为目标。每个旋转轴都与世界/父坐标系(以及彼此)对齐。放置与原点、相同位置和旋转一致的第三个点。
怎样,在斯威夫特,你能旋转r它的y轴点在r?如果指向Z轴更容易,我会接受。其他两个轴的最终方向对于我的需要来说是无关紧要的。
swift -  swift :将y轴指向3-d空间中的另一个点-LMLPHP
我已经经历了许多与此有关的讨论,但没有一个令人满意。我从阅读和经验中了解到,欧拉角可能不是一条路。我们没有在微积分课上讨论这个,那是50年前的事了。

最佳答案

知道了!添加容器节点时非常简单。以下内容似乎适用于任何象限中的任何位置。

// 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气缸和胶囊的指示。
如果有人知道如何排除容器节点,请务必告知。每次尝试对单个节点应用顺序旋转时,最后一个节点将覆盖前一个节点。我不知道如何构造一个旋转表达式来一次性完成它。

07-25 23:02
查看更多