我有一个箭头的演员列表,我想设置他们的方向指向下一个演员位置。但运行代码后的方向是不正确的。
def CalculateOrientation(vec):
#Here I use only one value of a particular vector before deviding it with its length because
#I'm trying to find the angle between the given vector and the world's axes (X - 1, 0, 0; Y - 0, 1, 0; Z - 0, 0, 1;).
#I know the formula is dot product divided by the multiplication of the lengths but since the values
#are 1 or 0 for the world axes, I don't need to include them in the code.
length = CalculateLength(vec)
angleX = np.rad2deg(np.arccos(vec[0] / length))
angleY = np.rad2deg(np.arccos(vec[1] / length))
angleZ = np.rad2deg(np.arccos(vec[2] / length))
return [angleX, angleY, angleZ]
def CalculateLength(vec):
print np.sqrt(vec[0]**2 + vec[1]**2 + vec[2]**2)
return np.sqrt(vec[0]**2 + vec[1]**2 + vec[2]**2)
def GetVectorBetweenPoints(a, b):
vec = [b[0] - a[0], b[1] - a[1], b[2] - a[2]]
return vec
for i in range(1338):
arrowsActors[i].SetOrientation(CalculateOrientation(GetVectorBetweenPoints(arrowsActors[i].GetPosition(), arrowsActors[i+1].GetPosition())))
答案 0 :(得分:1)
您可以改为使用SetUserMatrix(),并为其提供“查看”矩阵,计算gluLookAt()的计算方式。你也可以避免使用昂贵的三角函数。
我相信你的数学不起作用,因为一个轴上的旋转会影响另外两个轴的长度,请看一下glRotatef()生成的旋转矩阵。