Hello,

I tried this but it did not work. Here is the code that I used. I have pos1 and pos2 which are structures with x, y, and z members. dx, dy, and dz are the deltas between pos1.y and pos2.x, and .z. dxSquared is dx*dx, etc.

glPushMatrix ();

glTranslatef (pos1->x, pos1->y, pos1->z);

```
// rotate about x axis
opp = pos2->y - pos1->y;
adj = pos2->z - pos1->z;
theta = atan (opp/adj);
theta = 360 * (theta / (2*3.1415926));
glRotatef (-theta, 1.0, 0.0, 0.0);
// rotate about y axis
opp = pos2->x - pos1->x;
adj = pos2->z - pos1->z;
theta = atan (opp/adj);
theta = 360 * (theta / (2*3.1415926));
glRotatef (90-(-theta), 0.0, 1.0, 0.0);
gluCylinder (q, radius, radius, height, 20, 20);
```

glPopMatrix ();

Can someone tell me what I am doing wrong? I think it has something to do with the non-communicative nature of rotational transformations (i.e., the order of the rotation matters – the first rotation changes the angle required by the second).

Somewhere, someone must have actual working code that draws a cylindar (including the end disks!) when given two points in cartesian coordinate space. Help!

Originally posted by Fastian:

[b]You can first translate to the first point then

let the second vector be

v2 = (30,30,30)

calculate the angle on the x and y plane using

v2 = (30, 30, 0) and unit along x axis = 1,0,0

i.e. theta1 = angle bw v2 and unitX;

similarly find angle on x and z plane as theta2 with v2 = (30,0,30) then

glRotatef(theta1,1,0,0);

glrotatef(90-theta2,0,1,0);

drawcylinder().

[This message has been edited by Fastian (edited 03-29-2001).][/b]