X-Git-Url: http://git.hungrycats.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=hacks%2Fglx%2Ftube.c;h=556de1f4a60d411b14d727d2075d955358dcaca1;hb=3f9592851ce4ed76a9979bfdd6ec7dc5c457e183;hp=6632c29d6882ec641a2e565f507b195974e3b5b4;hpb=82c5080773aae5e72ec155327c075775e023d2ee;p=xscreensaver diff --git a/hacks/glx/tube.c b/hacks/glx/tube.c index 6632c29d..556de1f4 100644 --- a/hacks/glx/tube.c +++ b/hacks/glx/tube.c @@ -23,7 +23,7 @@ unit_tube (int faces, Bool smooth, Bool wire) GLfloat step = M_PI * 2 / faces; GLfloat s2 = step/2; GLfloat th; - GLfloat x, y, x0, y0; + GLfloat x, y, x0=0, y0=0; int z = 0; /* side walls @@ -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(); }