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 * due to a Bug/feature in VMS X11/Intrinsic.h has to be placed before xlock.
47 * otherwise caddr_t is not defined correctly
50 #include <X11/Intrinsic.h>
53 # define PROGCLASS "Pipes"
54 # define HACK_INIT init_pipes
55 # define HACK_DRAW draw_pipes
56 # define HACK_RESHAPE reshape_pipes
57 # define pipes_opts xlockmore_opts
58 # define DEFAULTS "*delay: 100 \n" \
62 "*showFPS: False \n" \
63 "*fpsSolid: True \n" \
65 "*tightturns: False \n" \
66 "*doubleBuffer: True \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"
82 #define DEF_DBUF "False"
86 static Bool fisheye, tightturns, rotatepipes;
89 static XrmOptionDescRec opts[] =
91 {"-factory", ".pipes.factory", XrmoptionSepArg, (caddr_t) NULL},
92 {"-fisheye", ".pipes.fisheye", XrmoptionNoArg, (caddr_t) "on"},
93 {"+fisheye", ".pipes.fisheye", XrmoptionNoArg, (caddr_t) "off"},
94 {"-tightturns", ".pipes.tightturns", XrmoptionNoArg, (caddr_t) "on"},
95 {"+tightturns", ".pipes.tightturns", XrmoptionNoArg, (caddr_t) "off"},
96 {"-rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, (caddr_t) "on"},
97 {"+rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, (caddr_t) "off"},
98 {"-db", ".pipes.doubleBuffer", XrmoptionNoArg, (caddr_t) "on"},
99 {"+db", ".pipes.doubleBuffer", XrmoptionNoArg, (caddr_t) "off"},
101 static argtype vars[] =
103 {&factory, "factory", "Factory", DEF_FACTORY, t_Int},
104 {&fisheye, "fisheye", "Fisheye", DEF_FISHEYE, t_Bool},
105 {&tightturns, "tightturns", "Tightturns", DEF_TIGHTTURNS, t_Bool},
106 {&rotatepipes, "rotatepipes", "Rotatepipes", DEF_ROTATEPIPES, t_Bool},
107 {&dbuf_p, "doubleBuffer", "DoubleBuffer", DEF_DBUF, t_Bool}
109 static OptionStruct desc[] =
111 {"-factory num", "how much extra equipment in pipes (0 for none)"},
112 {"-/+fisheye", "turn on/off zoomed-in view of pipes"},
113 {"-/+tightturns", "turn on/off tight turns"},
114 {"-/+rotatepipes", "turn on/off pipe system rotation per screenful"},
115 {"-/+db", "turn on/off double buffering"}
118 ModeSpecOpt pipes_opts =
119 {sizeof opts / sizeof opts[0], opts, sizeof vars / sizeof vars[0], vars, desc};
122 ModStruct pipes_description =
123 {"pipes", "init_pipes", "draw_pipes", "release_pipes",
125 "change_pipes", NULL, &pipes_opts,
126 1000, 2, 5, 500, 4, 1.0, "",
127 "Shows a selfbuilding pipe system", 0, NULL};
131 #define Scale4Window 0.1
132 #define Scale4Iconic 0.07
134 #define one_third 0.3333333333333333333
146 #define DEFINEDCOLORS 7
147 #define elbowradius 0.5
149 /*************************************************************************/
155 int Cells[HCELLS][VCELLS][HCELLS];
156 int usedcolors[DEFINEDCOLORS];
163 int number_of_systems;
169 GLfloat initial_rotation;
170 GLuint valve, bolts, betweenbolts, elbowbolts, elbowcoins;
171 GLuint guagehead, guageface, guagedial, guageconnector;
172 GLXContext *glx_context;
175 extern struct lwo LWO_BigValve, LWO_PipeBetweenBolts, LWO_Bolts3D;
176 extern struct lwo LWO_GuageHead, LWO_GuageFace, LWO_GuageDial, LWO_GuageConnector;
177 extern struct lwo LWO_ElbowBolts, LWO_ElbowCoins;
179 static float front_shininess[] =
181 static float front_specular[] =
182 {0.7, 0.7, 0.7, 1.0};
183 static float ambient0[] =
184 {0.4, 0.4, 0.4, 1.0};
185 static float diffuse0[] =
186 {1.0, 1.0, 1.0, 1.0};
187 static float ambient1[] =
188 {0.2, 0.2, 0.2, 1.0};
189 static float diffuse1[] =
190 {0.5, 0.5, 0.5, 1.0};
191 static float position0[] =
192 {1.0, 1.0, 1.0, 0.0};
193 static float position1[] =
194 {-1.0, -1.0, 1.0, 0.0};
195 static float lmodel_ambient[] =
196 {0.5, 0.5, 0.5, 1.0};
197 static float lmodel_twoside[] =
200 static float MaterialRed[] =
201 {0.7, 0.0, 0.0, 1.0};
202 static float MaterialGreen[] =
203 {0.1, 0.5, 0.2, 1.0};
204 static float MaterialBlue[] =
205 {0.0, 0.0, 0.7, 1.0};
206 static float MaterialCyan[] =
207 {0.2, 0.5, 0.7, 1.0};
208 static float MaterialYellow[] =
209 {0.7, 0.7, 0.0, 1.0};
210 static float MaterialMagenta[] =
211 {0.6, 0.2, 0.5, 1.0};
212 static float MaterialWhite[] =
213 {0.7, 0.7, 0.7, 1.0};
214 static float MaterialGray[] =
215 {0.2, 0.2, 0.2, 1.0};
217 static pipesstruct *pipes = NULL;
221 MakeTube(int direction)
224 float SINan_3, COSan_3;
226 /*dirUP = 00000000 */
227 /*dirDOWN = 00000001 */
228 /*dirLEFT = 00000010 */
229 /*dirRIGHT = 00000011 */
230 /*dirNEAR = 00000100 */
231 /*dirFAR = 00000101 */
233 if (!(direction & 4)) {
234 glRotatef(90.0, (direction & 2) ? 0.0 : 1.0,
235 (direction & 2) ? 1.0 : 0.0, 0.0);
237 glBegin(GL_QUAD_STRIP);
238 for (an = 0.0; an <= 2.0 * M_PI; an += M_PI / 12.0) {
239 glNormal3f((COSan_3 = cos(an) / 3.0), (SINan_3 = sin(an) / 3.0), 0.0);
240 glVertex3f(COSan_3, SINan_3, one_third);
241 glVertex3f(COSan_3, SINan_3, -one_third);
247 mySphere(float radius)
249 GLUquadricObj *quadObj;
251 quadObj = gluNewQuadric();
252 gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
253 gluSphere(quadObj, radius, 16, 16);
254 gluDeleteQuadric(quadObj);
258 myElbow(ModeInfo * mi, int bolted)
265 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
268 GLfloat p0[3], p1[3], p2[3], p3[3];
269 GLfloat n0[3], n1[3], n2[3], n3[3];
270 GLfloat COSphi, COSphi1, COStheta, COStheta1;
271 GLfloat _SINtheta, _SINtheta1;
273 for (i = 0; i <= rings / 4; i++) {
274 GLfloat theta, theta1;
276 theta = (GLfloat) i *2.0 * M_PI / rings;
278 theta1 = (GLfloat) (i + 1) * 2.0 * M_PI / rings;
279 for (j = 0; j < nsides; j++) {
282 phi = (GLfloat) j *2.0 * M_PI / nsides;
284 phi1 = (GLfloat) (j + 1) * 2.0 * M_PI / nsides;
286 p0[0] = (COStheta = cos(theta)) * (R + r * (COSphi = cos(phi)));
287 p0[1] = (_SINtheta = -sin(theta)) * (R + r * COSphi);
289 p1[0] = (COStheta1 = cos(theta1)) * (R + r * COSphi);
290 p1[1] = (_SINtheta1 = -sin(theta1)) * (R + r * COSphi);
292 p2[0] = COStheta1 * (R + r * (COSphi1 = cos(phi1)));
293 p2[1] = _SINtheta1 * (R + r * COSphi1);
295 p3[0] = COStheta * (R + r * COSphi1);
296 p3[1] = _SINtheta * (R + r * COSphi1);
298 n0[0] = COStheta * COSphi;
299 n0[1] = _SINtheta * COSphi;
301 n1[0] = COStheta1 * COSphi;
302 n1[1] = _SINtheta1 * COSphi;
304 n2[0] = COStheta1 * COSphi1;
305 n2[1] = _SINtheta1 * COSphi1;
307 n3[0] = COStheta * COSphi1;
308 n3[1] = _SINtheta * COSphi1;
310 p0[2] = p1[2] = r * (n0[2] = n1[2] = sin(phi));
311 p2[2] = p3[2] = r * (n2[2] = n3[2] = sin(phi1));
326 if (factory > 0 && bolted) {
327 /* Bolt the elbow onto the pipe system */
330 glRotatef(90.0, 0.0, 0.0, -1.0);
331 glRotatef(90.0, 0.0, 1.0, 0.0);
332 glTranslatef(0.0, one_third, one_third);
333 glCallList(pp->elbowcoins);
334 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
335 glCallList(pp->elbowbolts);
336 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
347 FindNeighbors(ModeInfo * mi)
349 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
352 pp->directions[dirUP] = (!pp->Cells[pp->PX][pp->PY + 1][pp->PZ]) ? 1 : 0;
353 pp->ndirections += pp->directions[dirUP];
354 pp->directions[dirDOWN] = (!pp->Cells[pp->PX][pp->PY - 1][pp->PZ]) ? 1 : 0;
355 pp->ndirections += pp->directions[dirDOWN];
356 pp->directions[dirLEFT] = (!pp->Cells[pp->PX - 1][pp->PY][pp->PZ]) ? 1 : 0;
357 pp->ndirections += pp->directions[dirLEFT];
358 pp->directions[dirRIGHT] = (!pp->Cells[pp->PX + 1][pp->PY][pp->PZ]) ? 1 : 0;
359 pp->ndirections += pp->directions[dirRIGHT];
360 pp->directions[dirFAR] = (!pp->Cells[pp->PX][pp->PY][pp->PZ - 1]) ? 1 : 0;
361 pp->ndirections += pp->directions[dirFAR];
362 pp->directions[dirNEAR] = (!pp->Cells[pp->PX][pp->PY][pp->PZ + 1]) ? 1 : 0;
363 pp->ndirections += pp->directions[dirNEAR];
367 SelectNeighbor(ModeInfo * mi)
369 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
373 for (i = 0, j = 0; i < 6; i++) {
374 if (pp->directions[i]) {
380 return dirlist[NRAND(pp->ndirections)];
384 MakeValve(ModeInfo * mi, int newdir)
386 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
388 /* There is a glPopMatrix() right after this subroutine returns. */
392 glRotatef(90.0, 1.0, 0.0, 0.0);
393 glRotatef(NRAND(3) * 90.0, 0.0, 0.0, 1.0);
397 glRotatef(90.0, 0.0, -1.0, 0.0);
398 glRotatef((NRAND(3) * 90.0) - 90.0, 0.0, 0.0, 1.0);
402 glRotatef(NRAND(4) * 90.0, 0.0, 0.0, 1.0);
406 glCallList(pp->betweenbolts);
407 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
408 glCallList(pp->bolts);
409 if (!MI_IS_MONO(mi)) {
410 if (pp->system_color == MaterialRed) {
411 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialYellow : MaterialBlue);
412 } else if (pp->system_color == MaterialBlue) {
413 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialRed : MaterialYellow);
414 } else if (pp->system_color == MaterialYellow) {
415 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialBlue : MaterialRed);
417 switch ((NRAND(3))) {
419 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialRed);
422 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialBlue);
425 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialYellow);
429 glRotatef((GLfloat) (NRAND(90)), 1.0, 0.0, 0.0);
430 glCallList(pp->valve);
431 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
436 MakeGuage(ModeInfo * mi, int newdir)
438 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
440 /* Can't have a guage on a vertical pipe. */
441 if ((newdir == dirUP) || (newdir == dirDOWN))
444 /* Is there space above this pipe for a guage? */
445 if (!pp->directions[dirUP])
448 /* Yes! Mark the space as used. */
449 pp->Cells[pp->PX][pp->PY + 1][pp->PZ] = 1;
453 if ((newdir == dirLEFT) || (newdir == dirRIGHT))
454 glRotatef(90.0, 0.0, 1.0, 0.0);
455 glCallList(pp->betweenbolts);
456 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
457 glCallList(pp->bolts);
460 glCallList(pp->guageconnector);
462 glTranslatef(0.0, 1.33333, 0.0);
463 /* Do not change the above to 1 + ONE_THIRD, because */
464 /* the object really is centered on 1.3333300000. */
465 glRotatef(NRAND(270) + 45.0, 0.0, 0.0, -1.0);
466 /* Random rotation for the dial. I love it. */
467 glCallList(pp->guagedial);
470 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
471 glCallList(pp->guagehead);
473 /* GuageFace is drawn last, in case of low-res depth buffers. */
474 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialWhite);
475 glCallList(pp->guageface);
477 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
484 MakeShape(ModeInfo * mi, int newdir)
488 if (!MakeGuage(mi, newdir))
492 MakeValve(mi, newdir);
498 reshape_pipes(ModeInfo * mi, int width, int height)
500 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
502 glViewport(0, 0, pp->WindW = (GLint) width, pp->WindH = (GLint) height);
503 glMatrixMode(GL_PROJECTION);
505 /*glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 15.0); */
506 gluPerspective(65.0, (GLfloat) width / (GLfloat) height, 0.1, 20.0);
507 glMatrixMode(GL_MODELVIEW);
509 glClear(GL_COLOR_BUFFER_BIT);
513 pinit(ModeInfo * mi, int zera)
515 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
519 glClearColor(0.0, 0.0, 0.0, 1.0);
520 glColor3f(1.0, 1.0, 1.0);
522 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0);
523 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0);
524 glLightfv(GL_LIGHT0, GL_POSITION, position0);
525 glLightfv(GL_LIGHT1, GL_AMBIENT, ambient1);
526 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse1);
527 glLightfv(GL_LIGHT1, GL_POSITION, position1);
528 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
529 glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
530 glEnable(GL_LIGHTING);
533 glEnable(GL_DEPTH_TEST);
534 glEnable(GL_NORMALIZE);
535 glEnable(GL_CULL_FACE);
537 glShadeModel(GL_SMOOTH);
538 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess);
539 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular);
542 pp->system_number = 1;
543 glDrawBuffer(dbuf_p ? GL_BACK : GL_FRONT);
544 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
545 (void) memset(pp->Cells, 0, sizeof (pp->Cells));
546 for (X = 0; X < HCELLS; X++) {
547 for (Y = 0; Y < VCELLS; Y++) {
548 pp->Cells[X][Y][0] = 1;
549 pp->Cells[X][Y][HCELLS - 1] = 1;
550 pp->Cells[0][Y][X] = 1;
551 pp->Cells[HCELLS - 1][Y][X] = 1;
554 for (X = 0; X < HCELLS; X++) {
555 for (Z = 0; Z < HCELLS; Z++) {
556 pp->Cells[X][0][Z] = 1;
557 pp->Cells[X][VCELLS - 1][Z] = 1;
560 (void) memset(pp->usedcolors, 0, sizeof (pp->usedcolors));
561 if ((pp->initial_rotation += 10.0) > 45.0) {
562 pp->initial_rotation -= 90.0;
568 if (!MI_IS_MONO(mi)) {
569 int collist[DEFINEDCOLORS];
570 int i, j, lower = 1000;
572 /* Avoid repeating colors on the same screen unless necessary */
573 for (i = 0; i < DEFINEDCOLORS; i++) {
574 if (lower > pp->usedcolors[i])
575 lower = pp->usedcolors[i];
577 for (i = 0, j = 0; i < DEFINEDCOLORS; i++) {
578 if (pp->usedcolors[i] == lower) {
583 i = collist[NRAND(j)];
587 pp->system_color = MaterialRed;
590 pp->system_color = MaterialGreen;
593 pp->system_color = MaterialBlue;
596 pp->system_color = MaterialCyan;
599 pp->system_color = MaterialYellow;
602 pp->system_color = MaterialMagenta;
605 pp->system_color = MaterialWhite;
609 pp->system_color = MaterialGray;
613 pp->PX = NRAND((HCELLS - 1)) + 1;
614 pp->PY = NRAND((VCELLS - 1)) + 1;
615 pp->PZ = NRAND((HCELLS - 1)) + 1;
616 } while (pp->Cells[pp->PX][pp->PY][pp->PZ] ||
617 (pp->Cells[pp->PX + 1][pp->PY][pp->PZ] && pp->Cells[pp->PX - 1][pp->PY][pp->PZ] &&
618 pp->Cells[pp->PX][pp->PY + 1][pp->PZ] && pp->Cells[pp->PX][pp->PY - 1][pp->PZ] &&
619 pp->Cells[pp->PX][pp->PY][pp->PZ + 1] && pp->Cells[pp->PX][pp->PY][pp->PZ - 1]));
620 pp->Cells[pp->PX][pp->PY][pp->PZ] = 1;
621 pp->olddir = dirNone;
625 pp->nowdir = SelectNeighbor(mi);
629 init_pipes(ModeInfo * mi)
631 int screen = MI_SCREEN(mi);
635 if ((pipes = (pipesstruct *) calloc(MI_NUM_SCREENS(mi),
636 sizeof (pipesstruct))) == NULL)
641 pp->window = MI_WINDOW(mi);
642 if ((pp->glx_context = init_GL(mi)) != NULL) {
644 reshape_pipes(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
646 pp->initial_rotation = NRAND(180); /* jwz */
648 pp->initial_rotation = -10.0;
652 pp->valve = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_BigValve);
653 pp->bolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_Bolts3D);
654 pp->betweenbolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_PipeBetweenBolts);
656 pp->elbowbolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_ElbowBolts);
657 pp->elbowcoins = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_ElbowCoins);
659 pp->guagehead = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageHead);
660 pp->guageface = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageFace);
661 pp->guagedial = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageDial);
662 pp->guageconnector = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageConnector);
664 /* else they are all 0, thanks to calloc(). */
666 if (MI_COUNT(mi) < 1 || MI_COUNT(mi) > NofSysTypes + 1) {
667 pp->system_type = NRAND(NofSysTypes) + 1;
669 pp->system_type = MI_COUNT(mi);
672 if (MI_CYCLES(mi) > 0 && MI_CYCLES(mi) < 11) {
673 pp->number_of_systems = MI_CYCLES(mi);
675 pp->number_of_systems = 5;
678 if (MI_SIZE(mi) < 10) {
679 pp->system_length = 10;
680 } else if (MI_SIZE(mi) > 1000) {
681 pp->system_length = 1000;
683 pp->system_length = MI_SIZE(mi);
691 draw_pipes(ModeInfo * mi)
693 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
695 Display *display = MI_DISPLAY(mi);
696 Window window = MI_WINDOW(mi);
701 if (!pp->glx_context)
706 glTranslatef(0.0, 0.0, fisheye ? -3.8 : -4.8);
708 glRotatef(pp->initial_rotation, 0.0, 1.0, 0.0);
710 if (!MI_IS_ICONIC(mi)) {
711 /* Width/height ratio handled by gluPerspective() now. */
712 glScalef(Scale4Window, Scale4Window, Scale4Window);
714 glScalef(Scale4Iconic, Scale4Iconic, Scale4Iconic);
719 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
721 /* If it's the begining of a system, draw a sphere */
722 if (pp->olddir == dirNone) {
724 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
728 /* Check for stop conditions */
729 if (pp->ndirections == 0 || pp->counter > pp->system_length) {
731 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
732 /* Finish the system with another sphere */
737 /* If the maximum number of system was drawn, restart (clearing the screen), */
738 /* else start a new system. */
739 if (++pp->system_number > pp->number_of_systems) {
753 /* Do will the direction change? if so, determine the new one */
755 if (!pp->directions[newdir]) { /* cannot proceed in the current direction */
756 newdir = SelectNeighbor(mi);
759 /* random change (20% chance) */
760 if ((pp->counter > 1) && (NRAND(100) < 20)) {
761 newdir = SelectNeighbor(mi);
764 /* Chance to turn increases after each length of pipe drawn */
765 if ((pp->counter > 1) && NRAND(50) < NRAND(pp->turncounter + 1)) {
766 newdir = SelectNeighbor(mi);
772 /* Has the direction changed? */
773 if (newdir == pp->nowdir) {
774 /* If not, draw the cell's center pipe */
776 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
777 /* Chance of factory shape here, if enabled. */
778 if ((pp->counter > 1) && (NRAND(100) < factory)) {
779 MakeShape(mi, newdir);
785 /* If so, draw the cell's center elbow/sphere */
786 int sysT = pp->system_type;
788 if (sysT == NofSysTypes + 1) {
789 sysT = ((pp->system_number - 1) % NofSysTypes) + 1;
795 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
796 mySphere(elbowradius);
800 switch (pp->nowdir) {
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);
808 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);
809 glRotatef(180.0, 1.0, 0.0, 0.0);
810 glRotatef(180.0, 0.0, 1.0, 0.0);
813 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));
814 glRotatef(90.0, 0.0, 1.0, 0.0);
815 glRotatef(180.0, 0.0, 0.0, 1.0);
818 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));
819 glRotatef(90.0, 0.0, 1.0, 0.0);
820 glRotatef(180.0, 1.0, 0.0, 0.0);
827 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);
830 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 glRotatef(180.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(270.0, 0.0, 1.0, 0.0);
838 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));
839 glRotatef(90.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, 0.0, 1.0, 0.0);
850 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);
851 glRotatef(180.0, 1.0, 0.0, 0.0);
852 glRotatef(180.0, 0.0, 1.0, 0.0);
855 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));
856 glRotatef(270.0, 1.0, 0.0, 0.0);
857 glRotatef(180.0, 0.0, 1.0, 0.0);
860 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));
861 glRotatef(270.0, 1.0, 0.0, 0.0);
862 glRotatef(180.0, 0.0, 0.0, 1.0);
869 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);
872 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 glRotatef(180.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(270.0, 1.0, 0.0, 0.0);
880 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));
881 glRotatef(90.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);
892 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));
893 glRotatef(270.0, 1.0, 0.0, 0.0);
894 glRotatef(180.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(270.0, 0.0, 1.0, 0.0);
901 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));
902 glRotatef(90.0, 0.0, 1.0, 0.0);
903 glRotatef(180.0, 0.0, 0.0, 1.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);
914 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));
915 glRotatef(90.0, 0.0, 1.0, 0.0);
916 glRotatef(180.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(90.0, 1.0, 0.0, 0.0);
923 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));
924 glRotatef(270.0, 1.0, 0.0, 0.0);
925 glRotatef(180.0, 0.0, 0.0, 1.0);
930 myElbow(mi, (sysT == 2));
939 pp->olddir = pp->nowdir;
941 switch (pp->nowdir) {
961 pp->Cells[pp->PX][pp->PY][pp->PZ] = 1;
963 /* Cells'face pipe */
964 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);
972 glXSwapBuffers(display, window);
974 if (mi->fps_p) do_fps (mi);
978 change_pipes(ModeInfo * mi)
980 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
982 if (!pp->glx_context)
985 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(pp->glx_context));
990 release_pipes(ModeInfo * mi)
995 for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
996 pipesstruct *pp = &pipes[screen];
998 if (pp->glx_context) {
1000 /* Display lists MUST be freed while their glXContext is current. */
1001 glXMakeCurrent(MI_DISPLAY(mi), pp->window, *(pp->glx_context));
1004 glDeleteLists(pp->valve, 1);
1006 glDeleteLists(pp->bolts, 1);
1007 if (pp->betweenbolts)
1008 glDeleteLists(pp->betweenbolts, 1);
1011 glDeleteLists(pp->elbowbolts, 1);
1013 glDeleteLists(pp->elbowcoins, 1);
1016 glDeleteLists(pp->guagehead, 1);
1018 glDeleteLists(pp->guageface, 1);
1020 glDeleteLists(pp->guagedial, 1);
1021 if (pp->guageconnector)
1022 glDeleteLists(pp->guageconnector, 1);
1026 (void) free((void *) pipes);