1 /* -*- Mode: C; tab-width: 4 -*- */
2 /* pipes --- 3D selfbuiding pipe system */
4 #if !defined( lint ) && !defined( SABER )
5 static const char sccsid[] = "@(#)pipes.c 4.07 97/11/24 xlockmore";
10 * Permission to use, copy, modify, and distribute this software and its
11 * documentation for any purpose and without fee is hereby granted,
12 * provided that the above copyright notice appear in all copies and that
13 * both that copyright notice and this permission notice appear in
14 * supporting documentation.
16 * This file is provided AS IS with no warranties of any kind. The author
17 * shall have no liability with respect to the infringement of copyrights,
18 * trade secrets or any patents by this file or any part thereof. In no
19 * event will the author be liable for any lost revenue or profits or
20 * other special, indirect and consequential damages.
22 * This program was inspired on a WindowsNT(R)'s screen saver. It was written
23 * from scratch and it was not based on any other source code.
25 * ==========================================================================
26 * The routine myElbow is derivated from the doughnut routine from the MesaGL
27 * library (more especifically the Mesaaux library) written by Brian Paul.
28 * ==========================================================================
30 * Thanks goes to Brian Paul for making it possible and inexpensive to use
33 * Since I'm not a native English speaker, my apologies for any grammatical
36 * My e-mail address is
38 * Marcelo F. Vianna (Apr-09-1997)
41 * 29-Apr-97: Factory equipment by Ed Mackey. Productive day today, eh?
42 * 29-Apr-97: Less tight turns Jeff Epler <jepler@inetnebr.com>
43 * 29-Apr-97: Efficiency speed-ups by Marcelo F. Vianna
47 * due to a Bug/feature in VMS X11/Intrinsic.h has to be placed before xlock.
48 * otherwise caddr_t is not defined correctly
51 #include <X11/Intrinsic.h>
54 # define PROGCLASS "Pipes"
55 # define HACK_INIT init_pipes
56 # define HACK_DRAW draw_pipes
57 # define HACK_RESHAPE reshape_pipes
58 # define pipes_opts xlockmore_opts
59 # define DEFAULTS "*delay: 100 \n" \
63 "*showFPS: False \n" \
64 "*fpsSolid: True \n" \
66 "*tightturns: False \n" \
67 "*rotatepipes: True \n"
68 # include "xlockmore.h" /* from the xscreensaver distribution */
69 #else /* !STANDALONE */
70 # include "xlock.h" /* from the xlockmore distribution */
71 #endif /* !STANDALONE */
78 #define DEF_FACTORY "2"
79 #define DEF_FISHEYE "True"
80 #define DEF_TIGHTTURNS "False"
81 #define DEF_ROTATEPIPES "True"
85 static Bool fisheye, tightturns, rotatepipes;
87 static XrmOptionDescRec opts[] =
89 {"-factory", ".pipes.factory", XrmoptionSepArg, (caddr_t) NULL},
90 {"-fisheye", ".pipes.fisheye", XrmoptionNoArg, (caddr_t) "on"},
91 {"+fisheye", ".pipes.fisheye", XrmoptionNoArg, (caddr_t) "off"},
92 {"-tightturns", ".pipes.tightturns", XrmoptionNoArg, (caddr_t) "on"},
93 {"+tightturns", ".pipes.tightturns", XrmoptionNoArg, (caddr_t) "off"},
94 {"-rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, (caddr_t) "on"},
95 {"+rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, (caddr_t) "off"}
97 static argtype vars[] =
99 {(caddr_t *) & factory, "factory", "Factory", DEF_FACTORY, t_Int},
100 {(caddr_t *) & fisheye, "fisheye", "Fisheye", DEF_FISHEYE, t_Bool},
101 {(caddr_t *) & tightturns, "tightturns", "Tightturns", DEF_TIGHTTURNS, t_Bool},
102 {(caddr_t *) & rotatepipes, "rotatepipes", "Rotatepipes", DEF_ROTATEPIPES, t_Bool}
104 static OptionStruct desc[] =
106 {"-factory num", "how much extra equipment in pipes (0 for none)"},
107 {"-/+fisheye", "turn on/off zoomed-in view of pipes"},
108 {"-/+tightturns", "turn on/off tight turns"},
109 {"-/+rotatepipes", "turn on/off pipe system rotation per screenful"}
112 ModeSpecOpt pipes_opts =
113 {sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc};
116 ModStruct pipes_description =
117 {"pipes", "init_pipes", "draw_pipes", "release_pipes",
119 "change_pipes", NULL, &pipes_opts,
120 1000, 2, 5, 500, 4, 1.0, "",
121 "Shows a selfbuilding pipe system", 0, NULL};
125 #define Scale4Window 0.1
126 #define Scale4Iconic 0.07
128 #define one_third 0.3333333333333333333
140 #define DEFINEDCOLORS 7
141 #define elbowradius 0.5
143 /*************************************************************************/
149 int Cells[HCELLS][VCELLS][HCELLS];
150 int usedcolors[DEFINEDCOLORS];
157 int number_of_systems;
163 GLfloat initial_rotation;
164 GLuint valve, bolts, betweenbolts, elbowbolts, elbowcoins;
165 GLuint guagehead, guageface, guagedial, guageconnector;
166 GLXContext *glx_context;
169 extern struct lwo LWO_BigValve, LWO_PipeBetweenBolts, LWO_Bolts3D;
170 extern struct lwo LWO_GuageHead, LWO_GuageFace, LWO_GuageDial, LWO_GuageConnector;
171 extern struct lwo LWO_ElbowBolts, LWO_ElbowCoins;
173 static float front_shininess[] =
175 static float front_specular[] =
176 {0.7, 0.7, 0.7, 1.0};
177 static float ambient0[] =
178 {0.4, 0.4, 0.4, 1.0};
179 static float diffuse0[] =
180 {1.0, 1.0, 1.0, 1.0};
181 static float ambient1[] =
182 {0.2, 0.2, 0.2, 1.0};
183 static float diffuse1[] =
184 {0.5, 0.5, 0.5, 1.0};
185 static float position0[] =
186 {1.0, 1.0, 1.0, 0.0};
187 static float position1[] =
188 {-1.0, -1.0, 1.0, 0.0};
189 static float lmodel_ambient[] =
190 {0.5, 0.5, 0.5, 1.0};
191 static float lmodel_twoside[] =
194 static float MaterialRed[] =
195 {0.7, 0.0, 0.0, 1.0};
196 static float MaterialGreen[] =
197 {0.1, 0.5, 0.2, 1.0};
198 static float MaterialBlue[] =
199 {0.0, 0.0, 0.7, 1.0};
200 static float MaterialCyan[] =
201 {0.2, 0.5, 0.7, 1.0};
202 static float MaterialYellow[] =
203 {0.7, 0.7, 0.0, 1.0};
204 static float MaterialMagenta[] =
205 {0.6, 0.2, 0.5, 1.0};
206 static float MaterialWhite[] =
207 {0.7, 0.7, 0.7, 1.0};
208 static float MaterialGray[] =
209 {0.2, 0.2, 0.2, 1.0};
211 static pipesstruct *pipes = NULL;
215 MakeTube(int direction)
218 float SINan_3, COSan_3;
220 /*dirUP = 00000000 */
221 /*dirDOWN = 00000001 */
222 /*dirLEFT = 00000010 */
223 /*dirRIGHT = 00000011 */
224 /*dirNEAR = 00000100 */
225 /*dirFAR = 00000101 */
227 if (!(direction & 4)) {
228 glRotatef(90.0, (direction & 2) ? 0.0 : 1.0,
229 (direction & 2) ? 1.0 : 0.0, 0.0);
231 glBegin(GL_QUAD_STRIP);
232 for (an = 0.0; an <= 2.0 * M_PI; an += M_PI / 12.0) {
233 glNormal3f((COSan_3 = cos(an) / 3.0), (SINan_3 = sin(an) / 3.0), 0.0);
234 glVertex3f(COSan_3, SINan_3, one_third);
235 glVertex3f(COSan_3, SINan_3, -one_third);
241 mySphere(float radius)
243 GLUquadricObj *quadObj;
245 quadObj = gluNewQuadric();
246 gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
247 gluSphere(quadObj, radius, 16, 16);
248 gluDeleteQuadric(quadObj);
252 myElbow(ModeInfo * mi, int bolted)
259 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
262 GLfloat p0[3], p1[3], p2[3], p3[3];
263 GLfloat n0[3], n1[3], n2[3], n3[3];
264 GLfloat COSphi, COSphi1, COStheta, COStheta1;
265 GLfloat _SINtheta, _SINtheta1;
267 for (i = 0; i <= rings / 4; i++) {
268 GLfloat theta, theta1;
270 theta = (GLfloat) i *2.0 * M_PI / rings;
272 theta1 = (GLfloat) (i + 1) * 2.0 * M_PI / rings;
273 for (j = 0; j < nsides; j++) {
276 phi = (GLfloat) j *2.0 * M_PI / nsides;
278 phi1 = (GLfloat) (j + 1) * 2.0 * M_PI / nsides;
280 p0[0] = (COStheta = cos(theta)) * (R + r * (COSphi = cos(phi)));
281 p0[1] = (_SINtheta = -sin(theta)) * (R + r * COSphi);
283 p1[0] = (COStheta1 = cos(theta1)) * (R + r * COSphi);
284 p1[1] = (_SINtheta1 = -sin(theta1)) * (R + r * COSphi);
286 p2[0] = COStheta1 * (R + r * (COSphi1 = cos(phi1)));
287 p2[1] = _SINtheta1 * (R + r * COSphi1);
289 p3[0] = COStheta * (R + r * COSphi1);
290 p3[1] = _SINtheta * (R + r * COSphi1);
292 n0[0] = COStheta * COSphi;
293 n0[1] = _SINtheta * COSphi;
295 n1[0] = COStheta1 * COSphi;
296 n1[1] = _SINtheta1 * COSphi;
298 n2[0] = COStheta1 * COSphi1;
299 n2[1] = _SINtheta1 * COSphi1;
301 n3[0] = COStheta * COSphi1;
302 n3[1] = _SINtheta * COSphi1;
304 p0[2] = p1[2] = r * (n0[2] = n1[2] = sin(phi));
305 p2[2] = p3[2] = r * (n2[2] = n3[2] = sin(phi1));
320 if (factory > 0 && bolted) {
321 /* Bolt the elbow onto the pipe system */
324 glRotatef(90.0, 0.0, 0.0, -1.0);
325 glRotatef(90.0, 0.0, 1.0, 0.0);
326 glTranslatef(0.0, one_third, one_third);
327 glCallList(pp->elbowcoins);
328 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
329 glCallList(pp->elbowbolts);
330 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
341 FindNeighbors(ModeInfo * mi)
343 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
346 pp->directions[dirUP] = (!pp->Cells[pp->PX][pp->PY + 1][pp->PZ]) ? 1 : 0;
347 pp->ndirections += pp->directions[dirUP];
348 pp->directions[dirDOWN] = (!pp->Cells[pp->PX][pp->PY - 1][pp->PZ]) ? 1 : 0;
349 pp->ndirections += pp->directions[dirDOWN];
350 pp->directions[dirLEFT] = (!pp->Cells[pp->PX - 1][pp->PY][pp->PZ]) ? 1 : 0;
351 pp->ndirections += pp->directions[dirLEFT];
352 pp->directions[dirRIGHT] = (!pp->Cells[pp->PX + 1][pp->PY][pp->PZ]) ? 1 : 0;
353 pp->ndirections += pp->directions[dirRIGHT];
354 pp->directions[dirFAR] = (!pp->Cells[pp->PX][pp->PY][pp->PZ - 1]) ? 1 : 0;
355 pp->ndirections += pp->directions[dirFAR];
356 pp->directions[dirNEAR] = (!pp->Cells[pp->PX][pp->PY][pp->PZ + 1]) ? 1 : 0;
357 pp->ndirections += pp->directions[dirNEAR];
361 SelectNeighbor(ModeInfo * mi)
363 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
367 for (i = 0, j = 0; i < 6; i++) {
368 if (pp->directions[i]) {
374 return dirlist[NRAND(pp->ndirections)];
378 MakeValve(ModeInfo * mi, int newdir)
380 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
382 /* There is a glPopMatrix() right after this subroutine returns. */
386 glRotatef(90.0, 1.0, 0.0, 0.0);
387 glRotatef(NRAND(3) * 90.0, 0.0, 0.0, 1.0);
391 glRotatef(90.0, 0.0, -1.0, 0.0);
392 glRotatef((NRAND(3) * 90.0) - 90.0, 0.0, 0.0, 1.0);
396 glRotatef(NRAND(4) * 90.0, 0.0, 0.0, 1.0);
400 glCallList(pp->betweenbolts);
401 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
402 glCallList(pp->bolts);
403 if (!MI_IS_MONO(mi)) {
404 if (pp->system_color == MaterialRed) {
405 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialYellow : MaterialBlue);
406 } else if (pp->system_color == MaterialBlue) {
407 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialRed : MaterialYellow);
408 } else if (pp->system_color == MaterialYellow) {
409 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialBlue : MaterialRed);
411 switch ((NRAND(3))) {
413 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialRed);
416 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialBlue);
419 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialYellow);
423 glRotatef((GLfloat) (NRAND(90)), 1.0, 0.0, 0.0);
424 glCallList(pp->valve);
425 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
430 MakeGuage(ModeInfo * mi, int newdir)
432 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
434 /* Can't have a guage on a vertical pipe. */
435 if ((newdir == dirUP) || (newdir == dirDOWN))
438 /* Is there space above this pipe for a guage? */
439 if (!pp->directions[dirUP])
442 /* Yes! Mark the space as used. */
443 pp->Cells[pp->PX][pp->PY + 1][pp->PZ] = 1;
447 if ((newdir == dirLEFT) || (newdir == dirRIGHT))
448 glRotatef(90.0, 0.0, 1.0, 0.0);
449 glCallList(pp->betweenbolts);
450 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
451 glCallList(pp->bolts);
454 glCallList(pp->guageconnector);
456 glTranslatef(0.0, 1.33333, 0.0);
457 /* Do not change the above to 1 + ONE_THIRD, because */
458 /* the object really is centered on 1.3333300000. */
459 glRotatef(NRAND(270) + 45.0, 0.0, 0.0, -1.0);
460 /* Random rotation for the dial. I love it. */
461 glCallList(pp->guagedial);
464 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
465 glCallList(pp->guagehead);
467 /* GuageFace is drawn last, in case of low-res depth buffers. */
468 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialWhite);
469 glCallList(pp->guageface);
471 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
478 MakeShape(ModeInfo * mi, int newdir)
482 if (!MakeGuage(mi, newdir))
486 MakeValve(mi, newdir);
492 reshape_pipes(ModeInfo * mi, int width, int height)
494 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
496 glViewport(0, 0, pp->WindW = (GLint) width, pp->WindH = (GLint) height);
497 glMatrixMode(GL_PROJECTION);
499 /*glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 15.0); */
500 gluPerspective(65.0, (GLfloat) width / (GLfloat) height, 0.1, 20.0);
501 glMatrixMode(GL_MODELVIEW);
503 glClear(GL_COLOR_BUFFER_BIT);
507 pinit(ModeInfo * mi, int zera)
509 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
513 glClearColor(0.0, 0.0, 0.0, 1.0);
514 glColor3f(1.0, 1.0, 1.0);
516 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0);
517 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0);
518 glLightfv(GL_LIGHT0, GL_POSITION, position0);
519 glLightfv(GL_LIGHT1, GL_AMBIENT, ambient1);
520 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse1);
521 glLightfv(GL_LIGHT1, GL_POSITION, position1);
522 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
523 glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
524 glEnable(GL_LIGHTING);
527 glEnable(GL_DEPTH_TEST);
528 glEnable(GL_NORMALIZE);
529 glEnable(GL_CULL_FACE);
531 glShadeModel(GL_SMOOTH);
532 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess);
533 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular);
536 pp->system_number = 1;
537 glDrawBuffer(GL_FRONT_AND_BACK);
538 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
539 (void) memset(pp->Cells, 0, sizeof (pp->Cells));
540 for (X = 0; X < HCELLS; X++) {
541 for (Y = 0; Y < VCELLS; Y++) {
542 pp->Cells[X][Y][0] = 1;
543 pp->Cells[X][Y][HCELLS - 1] = 1;
544 pp->Cells[0][Y][X] = 1;
545 pp->Cells[HCELLS - 1][Y][X] = 1;
548 for (X = 0; X < HCELLS; X++) {
549 for (Z = 0; Z < HCELLS; Z++) {
550 pp->Cells[X][0][Z] = 1;
551 pp->Cells[X][VCELLS - 1][Z] = 1;
554 (void) memset(pp->usedcolors, 0, sizeof (pp->usedcolors));
555 if ((pp->initial_rotation += 10.0) > 45.0) {
556 pp->initial_rotation -= 90.0;
562 if (!MI_IS_MONO(mi)) {
563 int collist[DEFINEDCOLORS];
564 int i, j, lower = 1000;
566 /* Avoid repeating colors on the same screen unless necessary */
567 for (i = 0; i < DEFINEDCOLORS; i++) {
568 if (lower > pp->usedcolors[i])
569 lower = pp->usedcolors[i];
571 for (i = 0, j = 0; i < DEFINEDCOLORS; i++) {
572 if (pp->usedcolors[i] == lower) {
577 i = collist[NRAND(j)];
581 pp->system_color = MaterialRed;
584 pp->system_color = MaterialGreen;
587 pp->system_color = MaterialBlue;
590 pp->system_color = MaterialCyan;
593 pp->system_color = MaterialYellow;
596 pp->system_color = MaterialMagenta;
599 pp->system_color = MaterialWhite;
603 pp->system_color = MaterialGray;
607 pp->PX = NRAND((HCELLS - 1)) + 1;
608 pp->PY = NRAND((VCELLS - 1)) + 1;
609 pp->PZ = NRAND((HCELLS - 1)) + 1;
610 } while (pp->Cells[pp->PX][pp->PY][pp->PZ] ||
611 (pp->Cells[pp->PX + 1][pp->PY][pp->PZ] && pp->Cells[pp->PX - 1][pp->PY][pp->PZ] &&
612 pp->Cells[pp->PX][pp->PY + 1][pp->PZ] && pp->Cells[pp->PX][pp->PY - 1][pp->PZ] &&
613 pp->Cells[pp->PX][pp->PY][pp->PZ + 1] && pp->Cells[pp->PX][pp->PY][pp->PZ - 1]));
614 pp->Cells[pp->PX][pp->PY][pp->PZ] = 1;
615 pp->olddir = dirNone;
619 pp->nowdir = SelectNeighbor(mi);
623 init_pipes(ModeInfo * mi)
625 int screen = MI_SCREEN(mi);
629 if ((pipes = (pipesstruct *) calloc(MI_NUM_SCREENS(mi),
630 sizeof (pipesstruct))) == NULL)
635 pp->window = MI_WINDOW(mi);
636 if ((pp->glx_context = init_GL(mi)) != NULL) {
638 reshape_pipes(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
640 pp->initial_rotation = NRAND(180); /* jwz */
642 pp->initial_rotation = -10.0;
646 pp->valve = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_BigValve);
647 pp->bolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_Bolts3D);
648 pp->betweenbolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_PipeBetweenBolts);
650 pp->elbowbolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_ElbowBolts);
651 pp->elbowcoins = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_ElbowCoins);
653 pp->guagehead = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageHead);
654 pp->guageface = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageFace);
655 pp->guagedial = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageDial);
656 pp->guageconnector = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageConnector);
658 /* else they are all 0, thanks to calloc(). */
660 if (MI_COUNT(mi) < 1 || MI_COUNT(mi) > NofSysTypes + 1) {
661 pp->system_type = NRAND(NofSysTypes) + 1;
663 pp->system_type = MI_COUNT(mi);
666 if (MI_CYCLES(mi) > 0 && MI_CYCLES(mi) < 11) {
667 pp->number_of_systems = MI_CYCLES(mi);
669 pp->number_of_systems = 5;
672 if (MI_SIZE(mi) < 10) {
673 pp->system_length = 10;
674 } else if (MI_SIZE(mi) > 1000) {
675 pp->system_length = 1000;
677 pp->system_length = MI_SIZE(mi);
685 draw_pipes(ModeInfo * mi)
687 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
689 Display *display = MI_DISPLAY(mi);
690 Window window = MI_WINDOW(mi);
695 if (!pp->glx_context)
700 glTranslatef(0.0, 0.0, fisheye ? -3.8 : -4.8);
702 glRotatef(pp->initial_rotation, 0.0, 1.0, 0.0);
704 if (!MI_IS_ICONIC(mi)) {
705 /* Width/height ratio handled by gluPerspective() now. */
706 glScalef(Scale4Window, Scale4Window, Scale4Window);
708 glScalef(Scale4Iconic, Scale4Iconic, Scale4Iconic);
713 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
715 /* If it's the begining of a system, draw a sphere */
716 if (pp->olddir == dirNone) {
718 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
722 /* Check for stop conditions */
723 if (pp->ndirections == 0 || pp->counter > pp->system_length) {
725 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
726 /* Finish the system with another sphere */
731 /* If the maximum number of system was drawn, restart (clearing the screen), */
732 /* else start a new system. */
733 if (++pp->system_number > pp->number_of_systems) {
746 /* Do will the direction change? if so, determine the new one */
748 if (!pp->directions[newdir]) { /* cannot proceed in the current direction */
749 newdir = SelectNeighbor(mi);
752 /* random change (20% chance) */
753 if ((pp->counter > 1) && (NRAND(100) < 20)) {
754 newdir = SelectNeighbor(mi);
757 /* Chance to turn increases after each length of pipe drawn */
758 if ((pp->counter > 1) && NRAND(50) < NRAND(pp->turncounter + 1)) {
759 newdir = SelectNeighbor(mi);
765 /* Has the direction changed? */
766 if (newdir == pp->nowdir) {
767 /* If not, draw the cell's center pipe */
769 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
770 /* Chance of factory shape here, if enabled. */
771 if ((pp->counter > 1) && (NRAND(100) < factory)) {
772 MakeShape(mi, newdir);
778 /* If so, draw the cell's center elbow/sphere */
779 int sysT = pp->system_type;
781 if (sysT == NofSysTypes + 1) {
782 sysT = ((pp->system_number - 1) % NofSysTypes) + 1;
788 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
789 mySphere(elbowradius);
793 switch (pp->nowdir) {
797 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);
798 glRotatef(180.0, 1.0, 0.0, 0.0);
801 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);
802 glRotatef(180.0, 1.0, 0.0, 0.0);
803 glRotatef(180.0, 0.0, 1.0, 0.0);
806 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));
807 glRotatef(90.0, 0.0, 1.0, 0.0);
808 glRotatef(180.0, 0.0, 0.0, 1.0);
811 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));
812 glRotatef(90.0, 0.0, 1.0, 0.0);
813 glRotatef(180.0, 1.0, 0.0, 0.0);
820 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);
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);
824 glRotatef(180.0, 0.0, 1.0, 0.0);
827 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));
828 glRotatef(270.0, 0.0, 1.0, 0.0);
831 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));
832 glRotatef(90.0, 0.0, 1.0, 0.0);
839 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);
840 glRotatef(180.0, 0.0, 1.0, 0.0);
843 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);
844 glRotatef(180.0, 1.0, 0.0, 0.0);
845 glRotatef(180.0, 0.0, 1.0, 0.0);
848 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));
849 glRotatef(270.0, 1.0, 0.0, 0.0);
850 glRotatef(180.0, 0.0, 1.0, 0.0);
853 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));
854 glRotatef(270.0, 1.0, 0.0, 0.0);
855 glRotatef(180.0, 0.0, 0.0, 1.0);
862 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);
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);
866 glRotatef(180.0, 1.0, 0.0, 0.0);
869 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));
870 glRotatef(270.0, 1.0, 0.0, 0.0);
873 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));
874 glRotatef(90.0, 1.0, 0.0, 0.0);
881 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));
882 glRotatef(270.0, 1.0, 0.0, 0.0);
885 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));
886 glRotatef(270.0, 1.0, 0.0, 0.0);
887 glRotatef(180.0, 0.0, 1.0, 0.0);
890 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));
891 glRotatef(270.0, 0.0, 1.0, 0.0);
894 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));
895 glRotatef(90.0, 0.0, 1.0, 0.0);
896 glRotatef(180.0, 0.0, 0.0, 1.0);
903 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));
904 glRotatef(90.0, 0.0, 1.0, 0.0);
907 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));
908 glRotatef(90.0, 0.0, 1.0, 0.0);
909 glRotatef(180.0, 1.0, 0.0, 0.0);
912 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));
913 glRotatef(90.0, 1.0, 0.0, 0.0);
916 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));
917 glRotatef(270.0, 1.0, 0.0, 0.0);
918 glRotatef(180.0, 0.0, 0.0, 1.0);
923 myElbow(mi, (sysT == 2));
932 pp->olddir = pp->nowdir;
934 switch (pp->nowdir) {
954 pp->Cells[pp->PX][pp->PY][pp->PZ] = 1;
956 /* Cells'face pipe */
957 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);
964 glXSwapBuffers(display, window);
966 if (mi->fps_p) do_fps (mi);
970 change_pipes(ModeInfo * mi)
972 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
974 if (!pp->glx_context)
977 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(pp->glx_context));
982 release_pipes(ModeInfo * mi)
987 for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
988 pipesstruct *pp = &pipes[screen];
990 if (pp->glx_context) {
992 /* Display lists MUST be freed while their glXContext is current. */
993 glXMakeCurrent(MI_DISPLAY(mi), pp->window, *(pp->glx_context));
996 glDeleteLists(pp->valve, 1);
998 glDeleteLists(pp->bolts, 1);
999 if (pp->betweenbolts)
1000 glDeleteLists(pp->betweenbolts, 1);
1003 glDeleteLists(pp->elbowbolts, 1);
1005 glDeleteLists(pp->elbowcoins, 1);
1008 glDeleteLists(pp->guagehead, 1);
1010 glDeleteLists(pp->guageface, 1);
1012 glDeleteLists(pp->guagedial, 1);
1013 if (pp->guageconnector)
1014 glDeleteLists(pp->guageconnector, 1);
1018 (void) free((void *) pipes);