gluCylinder in a specific direction
I want to draw a cylinder with top pt at (1., 1., 1.) and an axis pointing to (2., 2., 2.). Could someone help me to finish the following code? Bascially I have the problem with the rotation part? The cylinder should be correctly shown even after the model is rotated. Thanks very much for your help.
glTranslated(1., 1., 1.);
glRotate(?, ?, ?);
gluCylinder(pQuarObj, .0, 1., 1., 100, 100);
Re: gluCylinder in a specific direction
Damn, I stink at this kind of math, but since nobody else is answering, I'll give it a try.
So you have to rotate cylinder's original axis (0, 0, 1) to a new one, in your case (1, 1, 1). You get the axis around which to rotate by calculating a cross product between these two. The angle is simply the angle between the two vectors, which is
Then just use glRotatef(angle, axis, axis, axis). Use at own risk.