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 "*doubleBuffer: True \n" \
68 "*rotatepipes: True \n"
69 # include "xlockmore.h" /* from the xscreensaver distribution */
70 #else /* !STANDALONE */
71 # include "xlock.h" /* from the xlockmore distribution */
72 #endif /* !STANDALONE */
79 #define DEF_FACTORY "2"
80 #define DEF_FISHEYE "True"
81 #define DEF_TIGHTTURNS "False"
82 #define DEF_ROTATEPIPES "True"
83 #define DEF_DBUF "False"
87 static Bool fisheye, tightturns, rotatepipes;
90 static XrmOptionDescRec opts[] =
92 {"-factory", ".pipes.factory", XrmoptionSepArg, (caddr_t) NULL},
93 {"-fisheye", ".pipes.fisheye", XrmoptionNoArg, (caddr_t) "on"},
94 {"+fisheye", ".pipes.fisheye", XrmoptionNoArg, (caddr_t) "off"},
95 {"-tightturns", ".pipes.tightturns", XrmoptionNoArg, (caddr_t) "on"},
96 {"+tightturns", ".pipes.tightturns", XrmoptionNoArg, (caddr_t) "off"},
97 {"-rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, (caddr_t) "on"},
98 {"+rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, (caddr_t) "off"},
99 {"-db", ".pipes.doubleBuffer", XrmoptionNoArg, (caddr_t) "on"},
100 {"+db", ".pipes.doubleBuffer", XrmoptionNoArg, (caddr_t) "off"},
102 static argtype vars[] =
104 {(caddr_t *) & factory, "factory", "Factory", DEF_FACTORY, t_Int},
105 {(caddr_t *) & fisheye, "fisheye", "Fisheye", DEF_FISHEYE, t_Bool},
106 {(caddr_t *) & tightturns, "tightturns", "Tightturns", DEF_TIGHTTURNS, t_Bool},
107 {(caddr_t *) & rotatepipes, "rotatepipes", "Rotatepipes", DEF_ROTATEPIPES, t_Bool},
108 {(caddr_t *) & dbuf_p, "doubleBuffer", "DoubleBuffer", DEF_DBUF, t_Bool}
110 static OptionStruct desc[] =
112 {"-factory num", "how much extra equipment in pipes (0 for none)"},
113 {"-/+fisheye", "turn on/off zoomed-in view of pipes"},
114 {"-/+tightturns", "turn on/off tight turns"},
115 {"-/+rotatepipes", "turn on/off pipe system rotation per screenful"},
116 {"-/+db", "turn on/off double buffering"}
119 ModeSpecOpt pipes_opts =
120 {sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc};
123 ModStruct pipes_description =
124 {"pipes", "init_pipes", "draw_pipes", "release_pipes",
126 "change_pipes", NULL, &pipes_opts,
127 1000, 2, 5, 500, 4, 1.0, "",
128 "Shows a selfbuilding pipe system", 0, NULL};
132 #define Scale4Window 0.1
133 #define Scale4Iconic 0.07
135 #define one_third 0.3333333333333333333
147 #define DEFINEDCOLORS 7
148 #define elbowradius 0.5
150 /*************************************************************************/
156 int Cells[HCELLS][VCELLS][HCELLS];
157 int usedcolors[DEFINEDCOLORS];
164 int number_of_systems;
170 GLfloat initial_rotation;
171 GLuint valve, bolts, betweenbolts, elbowbolts, elbowcoins;
172 GLuint guagehead, guageface, guagedial, guageconnector;
173 GLXContext *glx_context;
176 extern struct lwo LWO_BigValve, LWO_PipeBetweenBolts, LWO_Bolts3D;
177 extern struct lwo LWO_GuageHead, LWO_GuageFace, LWO_GuageDial, LWO_GuageConnector;
178 extern struct lwo LWO_ElbowBolts, LWO_ElbowCoins;
180 static float front_shininess[] =
182 static float front_specular[] =
183 {0.7, 0.7, 0.7, 1.0};
184 static float ambient0[] =
185 {0.4, 0.4, 0.4, 1.0};
186 static float diffuse0[] =
187 {1.0, 1.0, 1.0, 1.0};
188 static float ambient1[] =
189 {0.2, 0.2, 0.2, 1.0};
190 static float diffuse1[] =
191 {0.5, 0.5, 0.5, 1.0};
192 static float position0[] =
193 {1.0, 1.0, 1.0, 0.0};
194 static float position1[] =
195 {-1.0, -1.0, 1.0, 0.0};
196 static float lmodel_ambient[] =
197 {0.5, 0.5, 0.5, 1.0};
198 static float lmodel_twoside[] =
201 static float MaterialRed[] =
202 {0.7, 0.0, 0.0, 1.0};
203 static float MaterialGreen[] =
204 {0.1, 0.5, 0.2, 1.0};
205 static float MaterialBlue[] =
206 {0.0, 0.0, 0.7, 1.0};
207 static float MaterialCyan[] =
208 {0.2, 0.5, 0.7, 1.0};
209 static float MaterialYellow[] =
210 {0.7, 0.7, 0.0, 1.0};
211 static float MaterialMagenta[] =
212 {0.6, 0.2, 0.5, 1.0};
213 static float MaterialWhite[] =
214 {0.7, 0.7, 0.7, 1.0};
215 static float MaterialGray[] =
216 {0.2, 0.2, 0.2, 1.0};
218 static pipesstruct *pipes = NULL;
222 MakeTube(int direction)
225 float SINan_3, COSan_3;
227 /*dirUP = 00000000 */
228 /*dirDOWN = 00000001 */
229 /*dirLEFT = 00000010 */
230 /*dirRIGHT = 00000011 */
231 /*dirNEAR = 00000100 */
232 /*dirFAR = 00000101 */
234 if (!(direction & 4)) {
235 glRotatef(90.0, (direction & 2) ? 0.0 : 1.0,
236 (direction & 2) ? 1.0 : 0.0, 0.0);
238 glBegin(GL_QUAD_STRIP);
239 for (an = 0.0; an <= 2.0 * M_PI; an += M_PI / 12.0) {
240 glNormal3f((COSan_3 = cos(an) / 3.0), (SINan_3 = sin(an) / 3.0), 0.0);
241 glVertex3f(COSan_3, SINan_3, one_third);
242 glVertex3f(COSan_3, SINan_3, -one_third);
248 mySphere(float radius)
250 GLUquadricObj *quadObj;
252 quadObj = gluNewQuadric();
253 gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
254 gluSphere(quadObj, radius, 16, 16);
255 gluDeleteQuadric(quadObj);
259 myElbow(ModeInfo * mi, int bolted)
266 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
269 GLfloat p0[3], p1[3], p2[3], p3[3];
270 GLfloat n0[3], n1[3], n2[3], n3[3];
271 GLfloat COSphi, COSphi1, COStheta, COStheta1;
272 GLfloat _SINtheta, _SINtheta1;
274 for (i = 0; i <= rings / 4; i++) {
275 GLfloat theta, theta1;
277 theta = (GLfloat) i *2.0 * M_PI / rings;
279 theta1 = (GLfloat) (i + 1) * 2.0 * M_PI / rings;
280 for (j = 0; j < nsides; j++) {
283 phi = (GLfloat) j *2.0 * M_PI / nsides;
285 phi1 = (GLfloat) (j + 1) * 2.0 * M_PI / nsides;
287 p0[0] = (COStheta = cos(theta)) * (R + r * (COSphi = cos(phi)));
288 p0[1] = (_SINtheta = -sin(theta)) * (R + r * COSphi);
290 p1[0] = (COStheta1 = cos(theta1)) * (R + r * COSphi);
291 p1[1] = (_SINtheta1 = -sin(theta1)) * (R + r * COSphi);
293 p2[0] = COStheta1 * (R + r * (COSphi1 = cos(phi1)));
294 p2[1] = _SINtheta1 * (R + r * COSphi1);
296 p3[0] = COStheta * (R + r * COSphi1);
297 p3[1] = _SINtheta * (R + r * COSphi1);
299 n0[0] = COStheta * COSphi;
300 n0[1] = _SINtheta * COSphi;
302 n1[0] = COStheta1 * COSphi;
303 n1[1] = _SINtheta1 * COSphi;
305 n2[0] = COStheta1 * COSphi1;
306 n2[1] = _SINtheta1 * COSphi1;
308 n3[0] = COStheta * COSphi1;
309 n3[1] = _SINtheta * COSphi1;
311 p0[2] = p1[2] = r * (n0[2] = n1[2] = sin(phi));
312 p2[2] = p3[2] = r * (n2[2] = n3[2] = sin(phi1));
327 if (factory > 0 && bolted) {
328 /* Bolt the elbow onto the pipe system */
331 glRotatef(90.0, 0.0, 0.0, -1.0);
332 glRotatef(90.0, 0.0, 1.0, 0.0);
333 glTranslatef(0.0, one_third, one_third);
334 glCallList(pp->elbowcoins);
335 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
336 glCallList(pp->elbowbolts);
337 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
348 FindNeighbors(ModeInfo * mi)
350 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
353 pp->directions[dirUP] = (!pp->Cells[pp->PX][pp->PY + 1][pp->PZ]) ? 1 : 0;
354 pp->ndirections += pp->directions[dirUP];
355 pp->directions[dirDOWN] = (!pp->Cells[pp->PX][pp->PY - 1][pp->PZ]) ? 1 : 0;
356 pp->ndirections += pp->directions[dirDOWN];
357 pp->directions[dirLEFT] = (!pp->Cells[pp->PX - 1][pp->PY][pp->PZ]) ? 1 : 0;
358 pp->ndirections += pp->directions[dirLEFT];
359 pp->directions[dirRIGHT] = (!pp->Cells[pp->PX + 1][pp->PY][pp->PZ]) ? 1 : 0;
360 pp->ndirections += pp->directions[dirRIGHT];
361 pp->directions[dirFAR] = (!pp->Cells[pp->PX][pp->PY][pp->PZ - 1]) ? 1 : 0;
362 pp->ndirections += pp->directions[dirFAR];
363 pp->directions[dirNEAR] = (!pp->Cells[pp->PX][pp->PY][pp->PZ + 1]) ? 1 : 0;
364 pp->ndirections += pp->directions[dirNEAR];
368 SelectNeighbor(ModeInfo * mi)
370 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
374 for (i = 0, j = 0; i < 6; i++) {
375 if (pp->directions[i]) {
381 return dirlist[NRAND(pp->ndirections)];
385 MakeValve(ModeInfo * mi, int newdir)
387 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
389 /* There is a glPopMatrix() right after this subroutine returns. */
393 glRotatef(90.0, 1.0, 0.0, 0.0);
394 glRotatef(NRAND(3) * 90.0, 0.0, 0.0, 1.0);
398 glRotatef(90.0, 0.0, -1.0, 0.0);
399 glRotatef((NRAND(3) * 90.0) - 90.0, 0.0, 0.0, 1.0);
403 glRotatef(NRAND(4) * 90.0, 0.0, 0.0, 1.0);
407 glCallList(pp->betweenbolts);
408 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
409 glCallList(pp->bolts);
410 if (!MI_IS_MONO(mi)) {
411 if (pp->system_color == MaterialRed) {
412 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialYellow : MaterialBlue);
413 } else if (pp->system_color == MaterialBlue) {
414 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialRed : MaterialYellow);
415 } else if (pp->system_color == MaterialYellow) {
416 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialBlue : MaterialRed);
418 switch ((NRAND(3))) {
420 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialRed);
423 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialBlue);
426 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialYellow);
430 glRotatef((GLfloat) (NRAND(90)), 1.0, 0.0, 0.0);
431 glCallList(pp->valve);
432 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
437 MakeGuage(ModeInfo * mi, int newdir)
439 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
441 /* Can't have a guage on a vertical pipe. */
442 if ((newdir == dirUP) || (newdir == dirDOWN))
445 /* Is there space above this pipe for a guage? */
446 if (!pp->directions[dirUP])
449 /* Yes! Mark the space as used. */
450 pp->Cells[pp->PX][pp->PY + 1][pp->PZ] = 1;
454 if ((newdir == dirLEFT) || (newdir == dirRIGHT))
455 glRotatef(90.0, 0.0, 1.0, 0.0);
456 glCallList(pp->betweenbolts);
457 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
458 glCallList(pp->bolts);
461 glCallList(pp->guageconnector);
463 glTranslatef(0.0, 1.33333, 0.0);
464 /* Do not change the above to 1 + ONE_THIRD, because */
465 /* the object really is centered on 1.3333300000. */
466 glRotatef(NRAND(270) + 45.0, 0.0, 0.0, -1.0);
467 /* Random rotation for the dial. I love it. */
468 glCallList(pp->guagedial);
471 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
472 glCallList(pp->guagehead);
474 /* GuageFace is drawn last, in case of low-res depth buffers. */
475 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialWhite);
476 glCallList(pp->guageface);
478 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
485 MakeShape(ModeInfo * mi, int newdir)
489 if (!MakeGuage(mi, newdir))
493 MakeValve(mi, newdir);
499 reshape_pipes(ModeInfo * mi, int width, int height)
501 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
503 glViewport(0, 0, pp->WindW = (GLint) width, pp->WindH = (GLint) height);
504 glMatrixMode(GL_PROJECTION);
506 /*glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 15.0); */
507 gluPerspective(65.0, (GLfloat) width / (GLfloat) height, 0.1, 20.0);
508 glMatrixMode(GL_MODELVIEW);
510 glClear(GL_COLOR_BUFFER_BIT);
514 pinit(ModeInfo * mi, int zera)
516 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
520 glClearColor(0.0, 0.0, 0.0, 1.0);
521 glColor3f(1.0, 1.0, 1.0);
523 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0);
524 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0);
525 glLightfv(GL_LIGHT0, GL_POSITION, position0);
526 glLightfv(GL_LIGHT1, GL_AMBIENT, ambient1);
527 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse1);
528 glLightfv(GL_LIGHT1, GL_POSITION, position1);
529 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
530 glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
531 glEnable(GL_LIGHTING);
534 glEnable(GL_DEPTH_TEST);
535 glEnable(GL_NORMALIZE);
536 glEnable(GL_CULL_FACE);
538 glShadeModel(GL_SMOOTH);
539 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess);
540 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular);
543 pp->system_number = 1;
544 glDrawBuffer(dbuf_p ? GL_BACK : GL_FRONT);
545 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
546 (void) memset(pp->Cells, 0, sizeof (pp->Cells));
547 for (X = 0; X < HCELLS; X++) {
548 for (Y = 0; Y < VCELLS; Y++) {
549 pp->Cells[X][Y][0] = 1;
550 pp->Cells[X][Y][HCELLS - 1] = 1;
551 pp->Cells[0][Y][X] = 1;
552 pp->Cells[HCELLS - 1][Y][X] = 1;
555 for (X = 0; X < HCELLS; X++) {
556 for (Z = 0; Z < HCELLS; Z++) {
557 pp->Cells[X][0][Z] = 1;
558 pp->Cells[X][VCELLS - 1][Z] = 1;
561 (void) memset(pp->usedcolors, 0, sizeof (pp->usedcolors));
562 if ((pp->initial_rotation += 10.0) > 45.0) {
563 pp->initial_rotation -= 90.0;
569 if (!MI_IS_MONO(mi)) {
570 int collist[DEFINEDCOLORS];
571 int i, j, lower = 1000;
573 /* Avoid repeating colors on the same screen unless necessary */
574 for (i = 0; i < DEFINEDCOLORS; i++) {
575 if (lower > pp->usedcolors[i])
576 lower = pp->usedcolors[i];
578 for (i = 0, j = 0; i < DEFINEDCOLORS; i++) {
579 if (pp->usedcolors[i] == lower) {
584 i = collist[NRAND(j)];
588 pp->system_color = MaterialRed;
591 pp->system_color = MaterialGreen;
594 pp->system_color = MaterialBlue;
597 pp->system_color = MaterialCyan;
600 pp->system_color = MaterialYellow;
603 pp->system_color = MaterialMagenta;
606 pp->system_color = MaterialWhite;
610 pp->system_color = MaterialGray;
614 pp->PX = NRAND((HCELLS - 1)) + 1;
615 pp->PY = NRAND((VCELLS - 1)) + 1;
616 pp->PZ = NRAND((HCELLS - 1)) + 1;
617 } while (pp->Cells[pp->PX][pp->PY][pp->PZ] ||
618 (pp->Cells[pp->PX + 1][pp->PY][pp->PZ] && pp->Cells[pp->PX - 1][pp->PY][pp->PZ] &&
619 pp->Cells[pp->PX][pp->PY + 1][pp->PZ] && pp->Cells[pp->PX][pp->PY - 1][pp->PZ] &&
620 pp->Cells[pp->PX][pp->PY][pp->PZ + 1] && pp->Cells[pp->PX][pp->PY][pp->PZ - 1]));
621 pp->Cells[pp->PX][pp->PY][pp->PZ] = 1;
622 pp->olddir = dirNone;
626 pp->nowdir = SelectNeighbor(mi);
630 init_pipes(ModeInfo * mi)
632 int screen = MI_SCREEN(mi);
636 if ((pipes = (pipesstruct *) calloc(MI_NUM_SCREENS(mi),
637 sizeof (pipesstruct))) == NULL)
642 pp->window = MI_WINDOW(mi);
643 if ((pp->glx_context = init_GL(mi)) != NULL) {
645 reshape_pipes(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
647 pp->initial_rotation = NRAND(180); /* jwz */
649 pp->initial_rotation = -10.0;
653 pp->valve = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_BigValve);
654 pp->bolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_Bolts3D);
655 pp->betweenbolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_PipeBetweenBolts);
657 pp->elbowbolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_ElbowBolts);
658 pp->elbowcoins = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_ElbowCoins);
660 pp->guagehead = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageHead);
661 pp->guageface = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageFace);
662 pp->guagedial = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageDial);
663 pp->guageconnector = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageConnector);
665 /* else they are all 0, thanks to calloc(). */
667 if (MI_COUNT(mi) < 1 || MI_COUNT(mi) > NofSysTypes + 1) {
668 pp->system_type = NRAND(NofSysTypes) + 1;
670 pp->system_type = MI_COUNT(mi);
673 if (MI_CYCLES(mi) > 0 && MI_CYCLES(mi) < 11) {
674 pp->number_of_systems = MI_CYCLES(mi);
676 pp->number_of_systems = 5;
679 if (MI_SIZE(mi) < 10) {
680 pp->system_length = 10;
681 } else if (MI_SIZE(mi) > 1000) {
682 pp->system_length = 1000;
684 pp->system_length = MI_SIZE(mi);
692 draw_pipes(ModeInfo * mi)
694 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
696 Display *display = MI_DISPLAY(mi);
697 Window window = MI_WINDOW(mi);
702 if (!pp->glx_context)
707 glTranslatef(0.0, 0.0, fisheye ? -3.8 : -4.8);
709 glRotatef(pp->initial_rotation, 0.0, 1.0, 0.0);
711 if (!MI_IS_ICONIC(mi)) {
712 /* Width/height ratio handled by gluPerspective() now. */
713 glScalef(Scale4Window, Scale4Window, Scale4Window);
715 glScalef(Scale4Iconic, Scale4Iconic, Scale4Iconic);
720 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
722 /* If it's the begining of a system, draw a sphere */
723 if (pp->olddir == dirNone) {
725 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
729 /* Check for stop conditions */
730 if (pp->ndirections == 0 || pp->counter > pp->system_length) {
732 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
733 /* Finish the system with another sphere */
738 /* If the maximum number of system was drawn, restart (clearing the screen), */
739 /* else start a new system. */
740 if (++pp->system_number > pp->number_of_systems) {
754 /* Do will the direction change? if so, determine the new one */
756 if (!pp->directions[newdir]) { /* cannot proceed in the current direction */
757 newdir = SelectNeighbor(mi);
760 /* random change (20% chance) */
761 if ((pp->counter > 1) && (NRAND(100) < 20)) {
762 newdir = SelectNeighbor(mi);
765 /* Chance to turn increases after each length of pipe drawn */
766 if ((pp->counter > 1) && NRAND(50) < NRAND(pp->turncounter + 1)) {
767 newdir = SelectNeighbor(mi);
773 /* Has the direction changed? */
774 if (newdir == pp->nowdir) {
775 /* If not, draw the cell's center pipe */
777 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
778 /* Chance of factory shape here, if enabled. */
779 if ((pp->counter > 1) && (NRAND(100) < factory)) {
780 MakeShape(mi, newdir);
786 /* If so, draw the cell's center elbow/sphere */
787 int sysT = pp->system_type;
789 if (sysT == NofSysTypes + 1) {
790 sysT = ((pp->system_number - 1) % NofSysTypes) + 1;
796 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
797 mySphere(elbowradius);
801 switch (pp->nowdir) {
805 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);
806 glRotatef(180.0, 1.0, 0.0, 0.0);
809 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);
810 glRotatef(180.0, 1.0, 0.0, 0.0);
811 glRotatef(180.0, 0.0, 1.0, 0.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, 0.0, 0.0, 1.0);
819 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));
820 glRotatef(90.0, 0.0, 1.0, 0.0);
821 glRotatef(180.0, 1.0, 0.0, 0.0);
828 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);
831 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);
832 glRotatef(180.0, 0.0, 1.0, 0.0);
835 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));
836 glRotatef(270.0, 0.0, 1.0, 0.0);
839 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));
840 glRotatef(90.0, 0.0, 1.0, 0.0);
847 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);
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 - (one_third), (pp->PZ - 16) / 3.0 * 4.0);
852 glRotatef(180.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, 1.0, 0.0);
861 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));
862 glRotatef(270.0, 1.0, 0.0, 0.0);
863 glRotatef(180.0, 0.0, 0.0, 1.0);
870 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);
873 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);
874 glRotatef(180.0, 1.0, 0.0, 0.0);
877 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));
878 glRotatef(270.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(90.0, 1.0, 0.0, 0.0);
889 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));
890 glRotatef(270.0, 1.0, 0.0, 0.0);
893 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));
894 glRotatef(270.0, 1.0, 0.0, 0.0);
895 glRotatef(180.0, 0.0, 1.0, 0.0);
898 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));
899 glRotatef(270.0, 0.0, 1.0, 0.0);
902 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));
903 glRotatef(90.0, 0.0, 1.0, 0.0);
904 glRotatef(180.0, 0.0, 0.0, 1.0);
911 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));
912 glRotatef(90.0, 0.0, 1.0, 0.0);
915 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));
916 glRotatef(90.0, 0.0, 1.0, 0.0);
917 glRotatef(180.0, 1.0, 0.0, 0.0);
920 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));
921 glRotatef(90.0, 1.0, 0.0, 0.0);
924 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));
925 glRotatef(270.0, 1.0, 0.0, 0.0);
926 glRotatef(180.0, 0.0, 0.0, 1.0);
931 myElbow(mi, (sysT == 2));
940 pp->olddir = pp->nowdir;
942 switch (pp->nowdir) {
962 pp->Cells[pp->PX][pp->PY][pp->PZ] = 1;
964 /* Cells'face pipe */
965 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);
973 glXSwapBuffers(display, window);
975 if (mi->fps_p) do_fps (mi);
979 change_pipes(ModeInfo * mi)
981 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
983 if (!pp->glx_context)
986 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(pp->glx_context));
991 release_pipes(ModeInfo * mi)
996 for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
997 pipesstruct *pp = &pipes[screen];
999 if (pp->glx_context) {
1001 /* Display lists MUST be freed while their glXContext is current. */
1002 glXMakeCurrent(MI_DISPLAY(mi), pp->window, *(pp->glx_context));
1005 glDeleteLists(pp->valve, 1);
1007 glDeleteLists(pp->bolts, 1);
1008 if (pp->betweenbolts)
1009 glDeleteLists(pp->betweenbolts, 1);
1012 glDeleteLists(pp->elbowbolts, 1);
1014 glDeleteLists(pp->elbowcoins, 1);
1017 glDeleteLists(pp->guagehead, 1);
1019 glDeleteLists(pp->guageface, 1);
1021 glDeleteLists(pp->guagedial, 1);
1022 if (pp->guageconnector)
1023 glDeleteLists(pp->guageconnector, 1);
1027 (void) free((void *) pipes);