假设你在三维空间中有两点。调用第一个o作为源,另一个t调用目标。每个坐标系的旋转轴都与世界/父坐标系(或彼此)相关联。放置第三个点r与原点,相同的位置和旋转。
在Swift中,如何旋转r,使其y轴指向t?如果指向z轴更容易,我就用它代替。另外两个轴的方向对我的需要并不重要。

我已经讨论过很多与此有关的问题,但没有一个能让我满意。我从阅读和经验中了解到,欧拉角可能不是前进的道路。我们没有用微积分来讨论这个问题,那是50年前的事了。
发布于 2016-02-14 23:04:00
明白了!添加容器节点时非常简单。以下内容似乎适用于任何象限中的任何位置。
// 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圆筒和胶囊的方向。
如果有人知道如何排除集装箱节点,请告诉。每次我尝试对单个节点应用顺序轮转时,最后一个节点会覆盖前一个节点。我不知道如何制定一个旋转表达式来一次完成它。
https://stackoverflow.com/questions/35384392
复制相似问题