I have a spaceship in a 3D environment. I drew a B-spline curve using control points (converted to a Bezier curve to be able to draw). Each time a drawing event is triggered, the vessel is at the point (0,0,0) and is transferred to the next coordinate on the curve. Now, before doing this translation, I will need to make a turn so that the orientation of the vessel is along the tangent of the curve at this point.
I can approximate the tangent by finding a point on the curve that is next to the current one by doing this. I am using OpenGL in C ++
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]);
I think that the rotation vector is tangent, but cannot find the angle needed to rotate the ship. How can I rotate a ship to align it with a tangent?