Hi,

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.

glPushMatrix();

glTranslated(1., 1., 1.);

glRotate(?, ?, ?);

gluCylinder(pQuarObj, .0, 1., 1., 100, 100);

glPopMatrix();

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

arcCos(dot(a1, a2)/(|a1|*|a2|).

Then just use glRotatef(angle, axis[0], axis[1], axis[2]). Use at own risk.

-Ilkka