OK here’s an easy one, but I got it wrong. What kind of rotations/translations are needed to render a glu cylinder or cone along a axis from px,py,pz to qx,qy,qz. I can figure out the y axis rotation angle and the up down rotation angle but when combining the rotations it doesn’t work right.

v=normalise(q-p)

glrotate(angle, v.x, v.y, v.z);

you need to caculate 2 angles A and B. Suppose the cylinder first lies alone Z, you rotate it angle A alone Y and then rotate it angle B alone X, that is:

glPushMatrix();

glTranslatef(point p);

glRotatef(A,0,1,0);

glRotatef(B,1,0,0);

drawit()

glPopMatrix();

you can get A B from: (where 1 is your p, 2 is your q)

void get_angle(float x1,float y1,float z1,float x2,float y2,float z2,float &len,float &A,float &B)

{

len=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2)+(z1-z2)*(z1-z2));

anglea=(atan((x2-x1)/(z2-z1)))/DTOR;

anglea+=z2>z1?0:180;

angleb=-asin((y2-y1)/len)/DTOR;

}

[This message has been edited by beginner620824 (edited 06-02-2003).]

Originally posted by beginner620824:

[b]you need to caculate 2 angles A and B. Suppose the cylinder first lies alone Z, you rotate it angle A alone Y and then rotate it angle B alone X, that is:

glPushMatrix();

glTranslatef(point p);

glRotatef(A,0,1,0);

glRotatef(B,1,0,0);

drawit()

glPopMatrix();

you can get A B from: (where 1 is your p, 2 is your q)

void get_angle(float x1,float y1,float z1,float x2,float y2,float z2,float &len,float &A,float &B)

{

len=sqrt((x1-x2)(x1-x2)+(y1-y2)(y1-y2)+(z1-z2)*(z1-z2));

A=(atan((x2-x1)/(z2-z1)))/DTOR;

A+=z2>z1?0:180;

B=-asin((y2-y1)/len)/DTOR;

}

[This message has been edited by beginner620824 (edited 06-02-2003).][/b]