The x, y and z parameters to glRotate
can specify any arbitrary axis, not just the x, y and z axes. To find an axis passing through your line, just subtract the end-points of the line to get an axis vector: if the two points are (x1, y1, z1)
and (x2, y2, z2)
, the axis you need is (x2-x1, y2-y1, z2-z1)
.
Edit: As @chris_l pointed out, this works only if the line passes through the origin. If not, first apply a translation of (-x1, -y1, -z1)
so that the line passes through the origin, then apply the above rotation, and translate it back by (x1, y1, z1)
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…