1 /* -*- Mode: C; tab-width: 4 -*- */
2 /* pipes --- 3D selfbuiding pipe system */
5 static const char sccsid[] = "@(#)pipes.c 4.07 97/11/24 xlockmore";
9 * Permission to use, copy, modify, and distribute this software and its
10 * documentation for any purpose and without fee is hereby granted,
11 * provided that the above copyright notice appear in all copies and that
12 * both that copyright notice and this permission notice appear in
13 * supporting documentation.
15 * This file is provided AS IS with no warranties of any kind. The author
16 * shall have no liability with respect to the infringement of copyrights,
17 * trade secrets or any patents by this file or any part thereof. In no
18 * event will the author be liable for any lost revenue or profits or
19 * other special, indirect and consequential damages.
21 * This program was inspired on a WindowsNT(R)'s screen saver. It was written
22 * from scratch and it was not based on any other source code.
24 * ==========================================================================
25 * The routine myElbow is derivated from the doughnut routine from the MesaGL
26 * library (more especifically the Mesaaux library) written by Brian Paul.
27 * ==========================================================================
29 * Thanks goes to Brian Paul for making it possible and inexpensive to use
32 * Since I'm not a native English speaker, my apologies for any grammatical
35 * My e-mail address is
37 * Marcelo F. Vianna (Apr-09-1997)
40 * 29-Apr-97: Factory equipment by Ed Mackey. Productive day today, eh?
41 * 29-Apr-97: Less tight turns Jeff Epler <jepler@inetnebr.com>
42 * 29-Apr-97: Efficiency speed-ups by Marcelo F. Vianna
46 # define DEFAULTS "*delay: 10000 \n" \
50 "*showFPS: False \n" \
52 # define refresh_pipes 0
53 # define pipes_handle_event 0
54 # include "xlockmore.h" /* from the xscreensaver distribution */
55 #else /* !STANDALONE */
56 # include "xlock.h" /* from the xlockmore distribution */
57 #endif /* !STANDALONE */
63 #define DEF_FACTORY "2"
64 #define DEF_FISHEYE "True"
65 #define DEF_TIGHTTURNS "False"
66 #define DEF_ROTATEPIPES "True"
67 #define DEF_DBUF "False"
71 static Bool fisheye, tightturns, rotatepipes;
74 static XrmOptionDescRec opts[] =
76 {"-factory", ".pipes.factory", XrmoptionSepArg, 0},
77 {"-fisheye", ".pipes.fisheye", XrmoptionNoArg, "on"},
78 {"+fisheye", ".pipes.fisheye", XrmoptionNoArg, "off"},
79 {"-tightturns", ".pipes.tightturns", XrmoptionNoArg, "on"},
80 {"+tightturns", ".pipes.tightturns", XrmoptionNoArg, "off"},
81 {"-rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, "on"},
82 {"+rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, "off"},
83 {"-db", ".pipes.doubleBuffer", XrmoptionNoArg, "on"},
84 {"+db", ".pipes.doubleBuffer", XrmoptionNoArg, "off"},
86 static argtype vars[] =
88 {&factory, "factory", "Factory", DEF_FACTORY, t_Int},
89 {&fisheye, "fisheye", "Fisheye", DEF_FISHEYE, t_Bool},
90 {&tightturns, "tightturns", "Tightturns", DEF_TIGHTTURNS, t_Bool},
91 {&rotatepipes, "rotatepipes", "Rotatepipes", DEF_ROTATEPIPES, t_Bool},
92 {&dbuf_p, "doubleBuffer", "DoubleBuffer", DEF_DBUF, t_Bool}
94 static OptionStruct desc[] =
96 {"-factory num", "how much extra equipment in pipes (0 for none)"},
97 {"-/+fisheye", "turn on/off zoomed-in view of pipes"},
98 {"-/+tightturns", "turn on/off tight turns"},
99 {"-/+rotatepipes", "turn on/off pipe system rotation per screenful"},
100 {"-/+db", "turn on/off double buffering"}
103 ENTRYPOINT ModeSpecOpt pipes_opts =
104 {sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc};
107 ModStruct pipes_description =
108 {"pipes", "init_pipes", "draw_pipes", "release_pipes",
110 "change_pipes", NULL, &pipes_opts,
111 1000, 2, 5, 500, 4, 1.0, "",
112 "Shows a selfbuilding pipe system", 0, NULL};
116 #define Scale4Window 0.1
117 #define Scale4Iconic 0.07
119 #define one_third 0.3333333333333333333
131 #define DEFINEDCOLORS 7
132 #define elbowradius 0.5
134 /*************************************************************************/
140 int Cells[HCELLS][VCELLS][HCELLS];
141 int usedcolors[DEFINEDCOLORS];
148 int number_of_systems;
153 const float *system_color;
154 GLfloat initial_rotation;
155 GLuint valve, bolts, betweenbolts, elbowbolts, elbowcoins;
156 GLuint guagehead, guageface, guagedial, guageconnector;
158 GLXContext *glx_context;
161 extern struct lwo LWO_BigValve, LWO_PipeBetweenBolts, LWO_Bolts3D;
162 extern struct lwo LWO_GuageHead, LWO_GuageFace, LWO_GuageDial, LWO_GuageConnector;
163 extern struct lwo LWO_ElbowBolts, LWO_ElbowCoins;
165 static const float front_shininess[] = {60.0};
166 static const float front_specular[] = {0.7, 0.7, 0.7, 1.0};
167 static const float ambient0[] = {0.4, 0.4, 0.4, 1.0};
168 static const float diffuse0[] = {1.0, 1.0, 1.0, 1.0};
169 static const float ambient1[] = {0.2, 0.2, 0.2, 1.0};
170 static const float diffuse1[] = {0.5, 0.5, 0.5, 1.0};
171 static const float position0[] = {1.0, 1.0, 1.0, 0.0};
172 static const float position1[] = {-1.0, -1.0, 1.0, 0.0};
173 static const float lmodel_ambient[] = {0.5, 0.5, 0.5, 1.0};
174 static const float lmodel_twoside[] = {GL_TRUE};
176 static const float MaterialRed[] = {0.7, 0.0, 0.0, 1.0};
177 static const float MaterialGreen[] = {0.1, 0.5, 0.2, 1.0};
178 static const float MaterialBlue[] = {0.0, 0.0, 0.7, 1.0};
179 static const float MaterialCyan[] = {0.2, 0.5, 0.7, 1.0};
180 static const float MaterialYellow[] = {0.7, 0.7, 0.0, 1.0};
181 static const float MaterialMagenta[] = {0.6, 0.2, 0.5, 1.0};
182 static const float MaterialWhite[] = {0.7, 0.7, 0.7, 1.0};
183 static const float MaterialGray[] = {0.2, 0.2, 0.2, 1.0};
185 static pipesstruct *pipes = NULL;
189 MakeTube(ModeInfo *mi, int direction)
192 float SINan_3, COSan_3;
194 /*dirUP = 00000000 */
195 /*dirDOWN = 00000001 */
196 /*dirLEFT = 00000010 */
197 /*dirRIGHT = 00000011 */
198 /*dirNEAR = 00000100 */
199 /*dirFAR = 00000101 */
201 if (!(direction & 4)) {
202 glRotatef(90.0, (direction & 2) ? 0.0 : 1.0,
203 (direction & 2) ? 1.0 : 0.0, 0.0);
205 glBegin(GL_QUAD_STRIP);
206 for (an = 0.0; an <= 2.0 * M_PI; an += M_PI / 12.0) {
207 glNormal3f((COSan_3 = cos(an) / 3.0), (SINan_3 = sin(an) / 3.0), 0.0);
208 glVertex3f(COSan_3, SINan_3, one_third);
209 glVertex3f(COSan_3, SINan_3, -one_third);
216 mySphere(float radius)
218 GLUquadricObj *quadObj;
220 quadObj = gluNewQuadric();
221 gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
222 gluSphere(quadObj, radius, 16, 16);
223 gluDeleteQuadric(quadObj);
227 myElbow(ModeInfo * mi, int bolted)
234 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
237 GLfloat p0[3], p1[3], p2[3], p3[3];
238 GLfloat n0[3], n1[3], n2[3], n3[3];
239 GLfloat COSphi, COSphi1, COStheta, COStheta1;
240 GLfloat _SINtheta, _SINtheta1;
242 for (i = 0; i <= rings / 4; i++) {
243 GLfloat theta, theta1;
245 theta = (GLfloat) i *2.0 * M_PI / rings;
247 theta1 = (GLfloat) (i + 1) * 2.0 * M_PI / rings;
248 for (j = 0; j < nsides; j++) {
251 phi = (GLfloat) j *2.0 * M_PI / nsides;
253 phi1 = (GLfloat) (j + 1) * 2.0 * M_PI / nsides;
255 p0[0] = (COStheta = cos(theta)) * (R + r * (COSphi = cos(phi)));
256 p0[1] = (_SINtheta = -sin(theta)) * (R + r * COSphi);
258 p1[0] = (COStheta1 = cos(theta1)) * (R + r * COSphi);
259 p1[1] = (_SINtheta1 = -sin(theta1)) * (R + r * COSphi);
261 p2[0] = COStheta1 * (R + r * (COSphi1 = cos(phi1)));
262 p2[1] = _SINtheta1 * (R + r * COSphi1);
264 p3[0] = COStheta * (R + r * COSphi1);
265 p3[1] = _SINtheta * (R + r * COSphi1);
267 n0[0] = COStheta * COSphi;
268 n0[1] = _SINtheta * COSphi;
270 n1[0] = COStheta1 * COSphi;
271 n1[1] = _SINtheta1 * COSphi;
273 n2[0] = COStheta1 * COSphi1;
274 n2[1] = _SINtheta1 * COSphi1;
276 n3[0] = COStheta * COSphi1;
277 n3[1] = _SINtheta * COSphi1;
279 p0[2] = p1[2] = r * (n0[2] = n1[2] = sin(phi));
280 p2[2] = p3[2] = r * (n2[2] = n3[2] = sin(phi1));
296 if (factory > 0 && bolted) {
297 /* Bolt the elbow onto the pipe system */
300 glRotatef(90.0, 0.0, 0.0, -1.0);
301 glRotatef(90.0, 0.0, 1.0, 0.0);
302 glTranslatef(0.0, one_third, one_third);
303 glCallList(pp->elbowcoins);
304 mi->polygon_count += LWO_ElbowCoins.num_pnts/3;
305 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
306 glCallList(pp->elbowbolts);
307 mi->polygon_count += LWO_ElbowBolts.num_pnts/3;
308 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
319 FindNeighbors(ModeInfo * mi)
321 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
324 pp->directions[dirUP] = (!pp->Cells[pp->PX][pp->PY + 1][pp->PZ]) ? 1 : 0;
325 pp->ndirections += pp->directions[dirUP];
326 pp->directions[dirDOWN] = (!pp->Cells[pp->PX][pp->PY - 1][pp->PZ]) ? 1 : 0;
327 pp->ndirections += pp->directions[dirDOWN];
328 pp->directions[dirLEFT] = (!pp->Cells[pp->PX - 1][pp->PY][pp->PZ]) ? 1 : 0;
329 pp->ndirections += pp->directions[dirLEFT];
330 pp->directions[dirRIGHT] = (!pp->Cells[pp->PX + 1][pp->PY][pp->PZ]) ? 1 : 0;
331 pp->ndirections += pp->directions[dirRIGHT];
332 pp->directions[dirFAR] = (!pp->Cells[pp->PX][pp->PY][pp->PZ - 1]) ? 1 : 0;
333 pp->ndirections += pp->directions[dirFAR];
334 pp->directions[dirNEAR] = (!pp->Cells[pp->PX][pp->PY][pp->PZ + 1]) ? 1 : 0;
335 pp->ndirections += pp->directions[dirNEAR];
339 SelectNeighbor(ModeInfo * mi)
341 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
345 for (i = 0, j = 0; i < 6; i++) {
346 if (pp->directions[i]) {
352 return dirlist[NRAND(pp->ndirections)];
356 MakeValve(ModeInfo * mi, int newdir)
358 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
360 /* There is a glPopMatrix() right after this subroutine returns. */
364 glRotatef(90.0, 1.0, 0.0, 0.0);
365 glRotatef(NRAND(3) * 90.0, 0.0, 0.0, 1.0);
369 glRotatef(90.0, 0.0, -1.0, 0.0);
370 glRotatef((NRAND(3) * 90.0) - 90.0, 0.0, 0.0, 1.0);
374 glRotatef(NRAND(4) * 90.0, 0.0, 0.0, 1.0);
378 glCallList(pp->betweenbolts);
379 mi->polygon_count += LWO_PipeBetweenBolts.num_pnts/3;
380 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
381 glCallList(pp->bolts);
382 mi->polygon_count += LWO_Bolts3D.num_pnts/3;
383 if (!MI_IS_MONO(mi)) {
384 if (pp->system_color == MaterialRed) {
385 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialYellow : MaterialBlue);
386 } else if (pp->system_color == MaterialBlue) {
387 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialRed : MaterialYellow);
388 } else if (pp->system_color == MaterialYellow) {
389 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialBlue : MaterialRed);
391 switch ((NRAND(3))) {
393 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialRed);
396 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialBlue);
399 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialYellow);
403 glRotatef((GLfloat) (NRAND(90)), 1.0, 0.0, 0.0);
404 glCallList(pp->valve);
405 mi->polygon_count += LWO_BigValve.num_pnts/3;
406 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
411 MakeGuage(ModeInfo * mi, int newdir)
413 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
415 /* Can't have a guage on a vertical pipe. */
416 if ((newdir == dirUP) || (newdir == dirDOWN))
419 /* Is there space above this pipe for a guage? */
420 if (!pp->directions[dirUP])
423 /* Yes! Mark the space as used. */
424 pp->Cells[pp->PX][pp->PY + 1][pp->PZ] = 1;
428 if ((newdir == dirLEFT) || (newdir == dirRIGHT))
429 glRotatef(90.0, 0.0, 1.0, 0.0);
430 glCallList(pp->betweenbolts);
431 mi->polygon_count += LWO_PipeBetweenBolts.num_pnts/3;
432 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
433 glCallList(pp->bolts);
434 mi->polygon_count += LWO_Bolts3D.num_pnts/3;
437 glCallList(pp->guageconnector);
438 mi->polygon_count += LWO_GuageConnector.num_pnts/3;
440 glTranslatef(0.0, 1.33333, 0.0);
441 /* Do not change the above to 1 + ONE_THIRD, because */
442 /* the object really is centered on 1.3333300000. */
443 glRotatef(NRAND(270) + 45.0, 0.0, 0.0, -1.0);
444 /* Random rotation for the dial. I love it. */
445 glCallList(pp->guagedial);
446 mi->polygon_count += LWO_GuageDial.num_pnts/3;
449 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
450 glCallList(pp->guagehead);
451 mi->polygon_count += LWO_GuageHead.num_pnts/3;
453 /* GuageFace is drawn last, in case of low-res depth buffers. */
454 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialWhite);
455 glCallList(pp->guageface);
456 mi->polygon_count += LWO_GuageFace.num_pnts/3;
458 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
465 MakeShape(ModeInfo * mi, int newdir)
469 if (!MakeGuage(mi, newdir))
470 MakeTube(mi, newdir);
473 MakeValve(mi, newdir);
479 pinit(ModeInfo * mi, int zera)
481 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
485 mi->polygon_count = 0;
488 glClearColor(0.0, 0.0, 0.0, 1.0);
489 glColor3f(1.0, 1.0, 1.0);
491 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0);
492 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0);
493 glLightfv(GL_LIGHT0, GL_POSITION, position0);
494 glLightfv(GL_LIGHT1, GL_AMBIENT, ambient1);
495 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse1);
496 glLightfv(GL_LIGHT1, GL_POSITION, position1);
497 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
498 glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
499 glEnable(GL_LIGHTING);
502 glEnable(GL_DEPTH_TEST);
503 glEnable(GL_NORMALIZE);
504 glEnable(GL_CULL_FACE);
506 glShadeModel(GL_SMOOTH);
507 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess);
508 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular);
511 pp->system_number = 1;
512 glDrawBuffer(dbuf_p ? GL_BACK : GL_FRONT);
513 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
514 (void) memset(pp->Cells, 0, sizeof (pp->Cells));
515 for (X = 0; X < HCELLS; X++) {
516 for (Y = 0; Y < VCELLS; Y++) {
517 pp->Cells[X][Y][0] = 1;
518 pp->Cells[X][Y][HCELLS - 1] = 1;
519 pp->Cells[0][Y][X] = 1;
520 pp->Cells[HCELLS - 1][Y][X] = 1;
523 for (X = 0; X < HCELLS; X++) {
524 for (Z = 0; Z < HCELLS; Z++) {
525 pp->Cells[X][0][Z] = 1;
526 pp->Cells[X][VCELLS - 1][Z] = 1;
529 (void) memset(pp->usedcolors, 0, sizeof (pp->usedcolors));
530 if ((pp->initial_rotation += 10.0) > 45.0) {
531 pp->initial_rotation -= 90.0;
537 if (!MI_IS_MONO(mi)) {
538 int collist[DEFINEDCOLORS];
539 int i, j, lower = 1000;
541 /* Avoid repeating colors on the same screen unless necessary */
542 for (i = 0; i < DEFINEDCOLORS; i++) {
543 if (lower > pp->usedcolors[i])
544 lower = pp->usedcolors[i];
546 for (i = 0, j = 0; i < DEFINEDCOLORS; i++) {
547 if (pp->usedcolors[i] == lower) {
552 i = collist[NRAND(j)];
556 pp->system_color = MaterialRed;
559 pp->system_color = MaterialGreen;
562 pp->system_color = MaterialBlue;
565 pp->system_color = MaterialCyan;
568 pp->system_color = MaterialYellow;
571 pp->system_color = MaterialMagenta;
574 pp->system_color = MaterialWhite;
578 pp->system_color = MaterialGray;
582 pp->PX = NRAND((HCELLS - 1)) + 1;
583 pp->PY = NRAND((VCELLS - 1)) + 1;
584 pp->PZ = NRAND((HCELLS - 1)) + 1;
585 } while (pp->Cells[pp->PX][pp->PY][pp->PZ] ||
586 (pp->Cells[pp->PX + 1][pp->PY][pp->PZ] && pp->Cells[pp->PX - 1][pp->PY][pp->PZ] &&
587 pp->Cells[pp->PX][pp->PY + 1][pp->PZ] && pp->Cells[pp->PX][pp->PY - 1][pp->PZ] &&
588 pp->Cells[pp->PX][pp->PY][pp->PZ + 1] && pp->Cells[pp->PX][pp->PY][pp->PZ - 1]));
589 pp->Cells[pp->PX][pp->PY][pp->PZ] = 1;
590 pp->olddir = dirNone;
594 pp->nowdir = SelectNeighbor(mi);
598 reshape_pipes(ModeInfo * mi, int width, int height)
600 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
603 glViewport(0, 0, pp->WindW = (GLint) width, pp->WindH = (GLint) height);
604 glMatrixMode(GL_PROJECTION);
606 /*glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 15.0); */
607 gluPerspective(65.0, (GLfloat) width / (GLfloat) height, 0.1, 20.0);
608 glMatrixMode(GL_MODELVIEW);
610 glClear(GL_COLOR_BUFFER_BIT);
614 init_pipes (ModeInfo * mi)
616 int screen = MI_SCREEN(mi);
620 if ((pipes = (pipesstruct *) calloc(MI_NUM_SCREENS(mi),
621 sizeof (pipesstruct))) == NULL)
626 pp->window = MI_WINDOW(mi);
627 if ((pp->glx_context = init_GL(mi)) != NULL) {
629 reshape_pipes(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
631 pp->initial_rotation = NRAND(180); /* jwz */
633 pp->initial_rotation = -10.0;
637 pp->valve = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_BigValve);
638 pp->bolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_Bolts3D);
639 pp->betweenbolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_PipeBetweenBolts);
641 pp->elbowbolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_ElbowBolts);
642 pp->elbowcoins = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_ElbowCoins);
644 pp->guagehead = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageHead);
645 pp->guageface = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageFace);
646 pp->guagedial = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageDial);
647 pp->guageconnector = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageConnector);
649 /* else they are all 0, thanks to calloc(). */
651 if (MI_COUNT(mi) < 1 || MI_COUNT(mi) > NofSysTypes + 1) {
652 pp->system_type = NRAND(NofSysTypes) + 1;
654 pp->system_type = MI_COUNT(mi);
657 if (MI_CYCLES(mi) > 0 && MI_CYCLES(mi) < 11) {
658 pp->number_of_systems = MI_CYCLES(mi);
660 pp->number_of_systems = 5;
663 if (MI_SIZE(mi) < 10) {
664 pp->system_length = 10;
665 } else if (MI_SIZE(mi) > 1000) {
666 pp->system_length = 1000;
668 pp->system_length = MI_SIZE(mi);
676 draw_pipes (ModeInfo * mi)
678 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
680 Display *display = MI_DISPLAY(mi);
681 Window window = MI_WINDOW(mi);
686 if (!pp->glx_context)
689 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(pp->glx_context));
693 /* Would be nice to fade to black here, by drawing successive quads
694 over the whole scene with gamma. */
702 glTranslatef(0.0, 0.0, fisheye ? -3.8 : -4.8);
704 glRotatef(pp->initial_rotation, 0.0, 1.0, 0.0);
706 if (!MI_IS_ICONIC(mi)) {
707 /* Width/height ratio handled by gluPerspective() now. */
708 glScalef(Scale4Window, Scale4Window, Scale4Window);
710 glScalef(Scale4Iconic, Scale4Iconic, Scale4Iconic);
715 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
717 /* If it's the begining of a system, draw a sphere */
718 if (pp->olddir == dirNone) {
720 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
724 /* Check for stop conditions */
725 if (pp->ndirections == 0 || pp->counter > pp->system_length) {
727 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
728 /* Finish the system with another sphere */
733 /* If the maximum number of system was drawn, restart (clearing the screen), */
734 /* else start a new system. */
735 if (++pp->system_number > pp->number_of_systems) {
736 /* pause doing nothing for N seconds before clearing the screen. */
738 pp->reset = secs * 1000000 / MI_PAUSE(mi);
749 /* Do will the direction change? if so, determine the new one */
751 if (!pp->directions[newdir]) { /* cannot proceed in the current direction */
752 newdir = SelectNeighbor(mi);
755 /* random change (20% chance) */
756 if ((pp->counter > 1) && (NRAND(100) < 20)) {
757 newdir = SelectNeighbor(mi);
760 /* Chance to turn increases after each length of pipe drawn */
761 if ((pp->counter > 1) && NRAND(50) < NRAND(pp->turncounter + 1)) {
762 newdir = SelectNeighbor(mi);
768 /* Has the direction changed? */
769 if (newdir == pp->nowdir) {
770 /* If not, draw the cell's center pipe */
772 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
773 /* Chance of factory shape here, if enabled. */
774 if ((pp->counter > 1) && (NRAND(100) < factory)) {
775 MakeShape(mi, newdir);
777 MakeTube(mi, newdir);
781 /* If so, draw the cell's center elbow/sphere */
782 int sysT = pp->system_type;
784 if (sysT == NofSysTypes + 1) {
785 sysT = ((pp->system_number - 1) % NofSysTypes) + 1;
791 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
792 mySphere(elbowradius);
796 switch (pp->nowdir) {
800 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0);
801 glRotatef(180.0, 1.0, 0.0, 0.0);
804 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0);
805 glRotatef(180.0, 1.0, 0.0, 0.0);
806 glRotatef(180.0, 0.0, 1.0, 0.0);
809 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
810 glRotatef(90.0, 0.0, 1.0, 0.0);
811 glRotatef(180.0, 0.0, 0.0, 1.0);
814 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
815 glRotatef(90.0, 0.0, 1.0, 0.0);
816 glRotatef(180.0, 1.0, 0.0, 0.0);
823 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0);
826 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0);
827 glRotatef(180.0, 0.0, 1.0, 0.0);
830 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
831 glRotatef(270.0, 0.0, 1.0, 0.0);
834 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
835 glRotatef(90.0, 0.0, 1.0, 0.0);
842 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0);
843 glRotatef(180.0, 0.0, 1.0, 0.0);
846 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0);
847 glRotatef(180.0, 1.0, 0.0, 0.0);
848 glRotatef(180.0, 0.0, 1.0, 0.0);
851 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
852 glRotatef(270.0, 1.0, 0.0, 0.0);
853 glRotatef(180.0, 0.0, 1.0, 0.0);
856 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
857 glRotatef(270.0, 1.0, 0.0, 0.0);
858 glRotatef(180.0, 0.0, 0.0, 1.0);
865 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0);
868 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0);
869 glRotatef(180.0, 1.0, 0.0, 0.0);
872 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
873 glRotatef(270.0, 1.0, 0.0, 0.0);
876 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
877 glRotatef(90.0, 1.0, 0.0, 0.0);
884 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
885 glRotatef(270.0, 1.0, 0.0, 0.0);
888 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
889 glRotatef(270.0, 1.0, 0.0, 0.0);
890 glRotatef(180.0, 0.0, 1.0, 0.0);
893 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
894 glRotatef(270.0, 0.0, 1.0, 0.0);
897 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0 - (one_third));
898 glRotatef(90.0, 0.0, 1.0, 0.0);
899 glRotatef(180.0, 0.0, 0.0, 1.0);
906 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 + (one_third), (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
907 glRotatef(90.0, 0.0, 1.0, 0.0);
910 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0 - (one_third), (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
911 glRotatef(90.0, 0.0, 1.0, 0.0);
912 glRotatef(180.0, 1.0, 0.0, 0.0);
915 glTranslatef((pp->PX - 16) / 3.0 * 4.0 - (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
916 glRotatef(90.0, 1.0, 0.0, 0.0);
919 glTranslatef((pp->PX - 16) / 3.0 * 4.0 + (one_third), (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0 + (one_third));
920 glRotatef(270.0, 1.0, 0.0, 0.0);
921 glRotatef(180.0, 0.0, 0.0, 1.0);
926 myElbow(mi, (sysT == 2));
935 pp->olddir = pp->nowdir;
937 switch (pp->nowdir) {
957 pp->Cells[pp->PX][pp->PY][pp->PZ] = 1;
959 /* Cells'face pipe */
960 glTranslatef(((pp->PX + OPX) / 2.0 - 16) / 3.0 * 4.0, ((pp->PY + OPY) / 2.0 - 12) / 3.0 * 4.0, ((pp->PZ + OPZ) / 2.0 - 16) / 3.0 * 4.0);
961 MakeTube(mi, newdir);
968 glXSwapBuffers(display, window);
970 if (mi->fps_p) do_fps (mi);
975 change_pipes (ModeInfo * mi)
977 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
979 if (!pp->glx_context)
982 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(pp->glx_context));
985 #endif /* !STANDALONE */
989 release_pipes (ModeInfo * mi)
994 for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
995 pipesstruct *pp = &pipes[screen];
997 if (pp->glx_context) {
999 /* Display lists MUST be freed while their glXContext is current. */
1000 glXMakeCurrent(MI_DISPLAY(mi), pp->window, *(pp->glx_context));
1003 glDeleteLists(pp->valve, 1);
1005 glDeleteLists(pp->bolts, 1);
1006 if (pp->betweenbolts)
1007 glDeleteLists(pp->betweenbolts, 1);
1010 glDeleteLists(pp->elbowbolts, 1);
1012 glDeleteLists(pp->elbowcoins, 1);
1015 glDeleteLists(pp->guagehead, 1);
1017 glDeleteLists(pp->guageface, 1);
1019 glDeleteLists(pp->guagedial, 1);
1020 if (pp->guageconnector)
1021 glDeleteLists(pp->guageconnector, 1);
1025 (void) free((void *) pipes);
1031 XSCREENSAVER_MODULE ("Pipes", pipes)