PDA

View Full Version : gluCylinder



nrbrasiliense
10-22-2001, 11:08 AM
Hi! I have tried to draw cylinders using the function gluCylinder of "GL Utility library". It's pretty easy but I have gotten some problems because it draws a cylinder directly on the Z-axis, so, I must make some rotation before draw a cylinder in any axis.
I tryed to make 2 consecutive rotations, first in Y-Axis and then in the X-Axis, if I had the right angles, it should be enough to draw in any direction with the "gluCylinder" function.
The problem is that it doesn´t work when a have a cylinder, for instance, from the point P1( 0, 0, 0 ) to the point P2( 100, 100, 100 ), I have not been able to calculate the right angle to make the right rotation before call gluCylinder.
I did that : angleY = arctan[(p2.X - p1.X) / (p2.Z - p1.Z)];
angleX = arctan[(p2.Y - p1.Y) / (p2.Z - p1.Z)];

Seems that the angleY is right, but the angleX is not.
If somebody could help me, showing how to calculate these angles, would be very nice.
Thanks a lot.
[ ]'s

Rogerio Brasiliense
Florianópolis - Brazil

jide
10-26-2001, 12:53 AM
i think you don't need to make many rotations like that.
just make one rotation to the desired axis, then make a glPushMatrix();
when finishing drawing , glPopMatrix();

by doing that, you're making a new coordinate system, that is base on the rotation you have made !

Selva
10-26-2001, 11:57 AM
angleY = arctan[(p2.X - p1.X) / (p2.Z - p1.Z)];
angleX = arctan[(p2.Y - p1.Y) / (p2.Z - p1.Z)];

angleY is correct.
But angleX is not deltaY / deltaZ.
It is hypotenus in XZ triangle / deltaZ