X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?p=xscreensaver;a=blobdiff_plain;f=hacks%2Fglx%2Ftube.c;h=c11d5b30cf46249d5b8f8578212dc8ac09e30da7;hp=6632c29d6882ec641a2e565f507b195974e3b5b4;hb=a94197e76a5dea5cb60542840809d6c20d0abbf3;hpb=8eb2873d7054e705c4e83f22d18c40946a9e2529 diff --git a/hacks/glx/tube.c b/hacks/glx/tube.c index 6632c29d..c11d5b30 100644 --- a/hacks/glx/tube.c +++ b/hacks/glx/tube.c @@ -151,28 +151,25 @@ tube_1 (GLfloat x1, GLfloat y1, GLfloat z1, int faces, Bool smooth, Bool wire, Bool cone_p) { - GLfloat length, angle, a, b, c; + GLfloat length, X, Y, Z; if (diameter <= 0) abort(); - a = (x2 - x1); - b = (y2 - y1); - c = (z2 - z1); + X = (x2 - x1); + Y = (y2 - y1); + Z = (z2 - z1); - length = sqrt (a*a + b*b + c*c); - angle = acos (a / length); + if (X == 0 && Y == 0 && Z == 0) + return; - glPushMatrix(); - glTranslatef(x1, y1, z1); - glScalef (length, length, length); + length = sqrt (X*X + Y*Y + Z*Z); - if (c == 0 && b == 0) - glRotatef (angle / (M_PI / 180), 0, 1, 0); - else - glRotatef (angle / (M_PI / 180), 0, -c, b); + glPushMatrix(); - glRotatef (-90, 0, 0, 1); - glScalef (diameter/length, 1, diameter/length); + glTranslatef(x1, y1, z1); + glRotatef (-atan2 (X, Y) * (180 / M_PI), 0, 0, 1); + glRotatef ( atan2 (Z, sqrt(X*X + Y*Y)) * (180 / M_PI), 1, 0, 0); + glScalef (diameter, length, diameter); /* extend the endpoints of the tube by the cap size in both directions */ if (cap_size != 0) @@ -186,6 +183,7 @@ tube_1 (GLfloat x1, GLfloat y1, GLfloat z1, unit_cone (faces, smooth, wire); else unit_tube (faces, smooth, wire); + glPopMatrix(); }