我在 3D 环境中有一艘宇宙飞船。我使用控制点绘制了一条 B 样条曲线(转换为贝塞尔曲线以便能够绘制它)。每次调用 draw 事件时,船都在点 (0,0,0) 并被平移到曲线上的下一个坐标。现在,在进行此平移之前,我需要进行旋转,以使船的方向在该点沿曲线的切线。
通过这样做,我可以通过在曲线上找到靠近当前点的点来近似切线。我在 C++ 中使用 OpenGL
float mDifference[1][3] = {nearPoint[0][0] - currentPosition[0][0],
nearPoint[0][1] - currentPosition[0][1],
nearPoint[0][2] - currentPosition[0][2]};
float norm = sqrt(mDifference[0][0] * mDifference[0][0]
+ mDifference[0][1] * mDifference[0][1]
+ mDifference[0][2] * mDifference[0][2]);
float tangent[1][3] = { mDifference[0][0] / norm,
mDifference[0][1] / norm,
mDifference[0][2] / norm};
//tangent = rotationVector?
spacecraftTransformGroup->setRotationVector(tangent[0][0],tangent[0][1],tangent[0][2]);
我认为旋转矢量是切线,但找不到旋转船所需的角度。如何旋转船以使其与切线对齐?