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" \
53 # define refresh_pipes 0
54 # define pipes_handle_event 0
55 # include "xlockmore.h" /* from the xscreensaver distribution */
56 #else /* !STANDALONE */
57 # include "xlock.h" /* from the xlockmore distribution */
58 #endif /* !STANDALONE */
65 # include <X11/Xlib.h>
72 #endif /* HAVE_JWZGLES */
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, 0},
92 {"-fisheye", ".pipes.fisheye", XrmoptionNoArg, "on"},
93 {"+fisheye", ".pipes.fisheye", XrmoptionNoArg, "off"},
94 {"-tightturns", ".pipes.tightturns", XrmoptionNoArg, "on"},
95 {"+tightturns", ".pipes.tightturns", XrmoptionNoArg, "off"},
96 {"-rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, "on"},
97 {"+rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, "off"},
98 {"-db", ".pipes.doubleBuffer", XrmoptionNoArg, "on"},
99 {"+db", ".pipes.doubleBuffer", XrmoptionNoArg, "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 ENTRYPOINT 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;
168 const float *system_color;
169 GLfloat initial_rotation;
170 GLuint valve, bolts, betweenbolts, elbowbolts, elbowcoins;
171 GLuint guagehead, guageface, guagedial, guageconnector, teapot;
174 GLXContext *glx_context;
177 extern struct lwo LWO_BigValve, LWO_PipeBetweenBolts, LWO_Bolts3D;
178 extern struct lwo LWO_GuageHead, LWO_GuageFace, LWO_GuageDial, LWO_GuageConnector;
179 extern struct lwo LWO_ElbowBolts, LWO_ElbowCoins;
181 static const float front_shininess[] = {60.0};
182 static const float front_specular[] = {0.7, 0.7, 0.7, 1.0};
183 static const float ambient0[] = {0.4, 0.4, 0.4, 1.0};
184 static const float diffuse0[] = {1.0, 1.0, 1.0, 1.0};
185 static const float ambient1[] = {0.2, 0.2, 0.2, 1.0};
186 static const float diffuse1[] = {0.5, 0.5, 0.5, 1.0};
187 static const float position0[] = {1.0, 1.0, 1.0, 0.0};
188 static const float position1[] = {-1.0, -1.0, 1.0, 0.0};
189 static const float lmodel_ambient[] = {0.5, 0.5, 0.5, 1.0};
190 static const float lmodel_twoside[] = {GL_TRUE};
192 static const float MaterialRed[] = {0.7, 0.0, 0.0, 1.0};
193 static const float MaterialGreen[] = {0.1, 0.5, 0.2, 1.0};
194 static const float MaterialBlue[] = {0.0, 0.0, 0.7, 1.0};
195 static const float MaterialCyan[] = {0.2, 0.5, 0.7, 1.0};
196 static const float MaterialYellow[] = {0.7, 0.7, 0.0, 1.0};
197 static const float MaterialMagenta[] = {0.6, 0.2, 0.5, 1.0};
198 static const float MaterialWhite[] = {0.7, 0.7, 0.7, 1.0};
199 static const float MaterialGray[] = {0.2, 0.2, 0.2, 1.0};
201 static pipesstruct *pipes = NULL;
205 MakeTube(ModeInfo *mi, int direction)
208 float SINan_3, COSan_3;
210 /*dirUP = 00000000 */
211 /*dirDOWN = 00000001 */
212 /*dirLEFT = 00000010 */
213 /*dirRIGHT = 00000011 */
214 /*dirNEAR = 00000100 */
215 /*dirFAR = 00000101 */
217 if (!(direction & 4)) {
218 glRotatef(90.0, (direction & 2) ? 0.0 : 1.0,
219 (direction & 2) ? 1.0 : 0.0, 0.0);
221 glBegin(GL_QUAD_STRIP);
222 for (an = 0.0; an <= 2.0 * M_PI; an += M_PI / 12.0) {
223 glNormal3f((COSan_3 = cos(an) / 3.0), (SINan_3 = sin(an) / 3.0), 0.0);
224 glVertex3f(COSan_3, SINan_3, one_third);
225 glVertex3f(COSan_3, SINan_3, -one_third);
232 mySphere(float radius, Bool wire)
235 GLUquadricObj *quadObj;
237 quadObj = gluNewQuadric();
238 gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
239 gluSphere(quadObj, radius, 16, 16);
240 gluDeleteQuadric(quadObj);
243 glScalef (radius, radius, radius);
244 glRotatef (90, 1, 0, 0);
245 unit_sphere (16, 16, wire);
251 myElbow(ModeInfo * mi, int bolted)
258 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
261 GLfloat p0[3], p1[3], p2[3], p3[3];
262 GLfloat n0[3], n1[3], n2[3], n3[3];
263 GLfloat COSphi, COSphi1, COStheta, COStheta1;
264 GLfloat _SINtheta, _SINtheta1;
266 for (i = 0; i <= rings / 4; i++) {
267 GLfloat theta, theta1;
269 theta = (GLfloat) i *2.0 * M_PI / rings;
271 theta1 = (GLfloat) (i + 1) * 2.0 * M_PI / rings;
272 for (j = 0; j < nsides; j++) {
275 phi = (GLfloat) j *2.0 * M_PI / nsides;
277 phi1 = (GLfloat) (j + 1) * 2.0 * M_PI / nsides;
279 p0[0] = (COStheta = cos(theta)) * (R + r * (COSphi = cos(phi)));
280 p0[1] = (_SINtheta = -sin(theta)) * (R + r * COSphi);
282 p1[0] = (COStheta1 = cos(theta1)) * (R + r * COSphi);
283 p1[1] = (_SINtheta1 = -sin(theta1)) * (R + r * COSphi);
285 p2[0] = COStheta1 * (R + r * (COSphi1 = cos(phi1)));
286 p2[1] = _SINtheta1 * (R + r * COSphi1);
288 p3[0] = COStheta * (R + r * COSphi1);
289 p3[1] = _SINtheta * (R + r * COSphi1);
291 n0[0] = COStheta * COSphi;
292 n0[1] = _SINtheta * COSphi;
294 n1[0] = COStheta1 * COSphi;
295 n1[1] = _SINtheta1 * COSphi;
297 n2[0] = COStheta1 * COSphi1;
298 n2[1] = _SINtheta1 * COSphi1;
300 n3[0] = COStheta * COSphi1;
301 n3[1] = _SINtheta * COSphi1;
303 p0[2] = p1[2] = r * (n0[2] = n1[2] = sin(phi));
304 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 mi->polygon_count += LWO_ElbowCoins.num_pnts/3;
329 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
330 glCallList(pp->elbowbolts);
331 mi->polygon_count += LWO_ElbowBolts.num_pnts/3;
332 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
343 FindNeighbors(ModeInfo * mi)
345 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
348 pp->directions[dirUP] = (!pp->Cells[pp->PX][pp->PY + 1][pp->PZ]) ? 1 : 0;
349 pp->ndirections += pp->directions[dirUP];
350 pp->directions[dirDOWN] = (!pp->Cells[pp->PX][pp->PY - 1][pp->PZ]) ? 1 : 0;
351 pp->ndirections += pp->directions[dirDOWN];
352 pp->directions[dirLEFT] = (!pp->Cells[pp->PX - 1][pp->PY][pp->PZ]) ? 1 : 0;
353 pp->ndirections += pp->directions[dirLEFT];
354 pp->directions[dirRIGHT] = (!pp->Cells[pp->PX + 1][pp->PY][pp->PZ]) ? 1 : 0;
355 pp->ndirections += pp->directions[dirRIGHT];
356 pp->directions[dirFAR] = (!pp->Cells[pp->PX][pp->PY][pp->PZ - 1]) ? 1 : 0;
357 pp->ndirections += pp->directions[dirFAR];
358 pp->directions[dirNEAR] = (!pp->Cells[pp->PX][pp->PY][pp->PZ + 1]) ? 1 : 0;
359 pp->ndirections += pp->directions[dirNEAR];
363 SelectNeighbor(ModeInfo * mi)
365 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
369 for (i = 0, j = 0; i < 6; i++) {
370 if (pp->directions[i]) {
376 return dirlist[NRAND(pp->ndirections)];
380 MakeValve(ModeInfo * mi, int newdir)
382 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
384 /* There is a glPopMatrix() right after this subroutine returns. */
388 glRotatef(90.0, 1.0, 0.0, 0.0);
389 glRotatef(NRAND(3) * 90.0, 0.0, 0.0, 1.0);
393 glRotatef(90.0, 0.0, -1.0, 0.0);
394 glRotatef((NRAND(3) * 90.0) - 90.0, 0.0, 0.0, 1.0);
398 glRotatef(NRAND(4) * 90.0, 0.0, 0.0, 1.0);
402 glCallList(pp->betweenbolts);
403 mi->polygon_count += LWO_PipeBetweenBolts.num_pnts/3;
404 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
405 glCallList(pp->bolts);
406 mi->polygon_count += LWO_Bolts3D.num_pnts/3;
407 if (!MI_IS_MONO(mi)) {
408 if (pp->system_color == MaterialRed) {
409 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialYellow : MaterialBlue);
410 } else if (pp->system_color == MaterialBlue) {
411 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialRed : MaterialYellow);
412 } else if (pp->system_color == MaterialYellow) {
413 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialBlue : MaterialRed);
415 switch ((NRAND(3))) {
417 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialRed);
420 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialBlue);
423 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialYellow);
427 glRotatef((GLfloat) (NRAND(90)), 1.0, 0.0, 0.0);
428 glCallList(pp->valve);
429 mi->polygon_count += LWO_BigValve.num_pnts/3;
430 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
435 MakeGuage(ModeInfo * mi, int newdir)
437 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
439 /* Can't have a guage on a vertical pipe. */
440 if ((newdir == dirUP) || (newdir == dirDOWN))
443 /* Is there space above this pipe for a guage? */
444 if (!pp->directions[dirUP])
447 /* Yes! Mark the space as used. */
448 pp->Cells[pp->PX][pp->PY + 1][pp->PZ] = 1;
452 if ((newdir == dirLEFT) || (newdir == dirRIGHT))
453 glRotatef(90.0, 0.0, 1.0, 0.0);
454 glCallList(pp->betweenbolts);
455 mi->polygon_count += LWO_PipeBetweenBolts.num_pnts/3;
456 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
457 glCallList(pp->bolts);
458 mi->polygon_count += LWO_Bolts3D.num_pnts/3;
461 glCallList(pp->guageconnector);
462 mi->polygon_count += LWO_GuageConnector.num_pnts/3;
464 glTranslatef(0.0, 1.33333, 0.0);
465 /* Do not change the above to 1 + ONE_THIRD, because */
466 /* the object really is centered on 1.3333300000. */
467 glRotatef(NRAND(270) + 45.0, 0.0, 0.0, -1.0);
468 /* Random rotation for the dial. I love it. */
469 glCallList(pp->guagedial);
470 mi->polygon_count += LWO_GuageDial.num_pnts/3;
473 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
474 glCallList(pp->guagehead);
475 mi->polygon_count += LWO_GuageHead.num_pnts/3;
477 /* GuageFace is drawn last, in case of low-res depth buffers. */
478 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialWhite);
479 glCallList(pp->guageface);
480 mi->polygon_count += LWO_GuageFace.num_pnts/3;
482 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
490 build_teapot(ModeInfo *mi)
492 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
493 GLuint list = glGenLists(1);
495 glNewList(list, GL_COMPILE);
496 pp->teapot_polys = unit_teapot (12, MI_IS_WIREFRAME(mi));
503 MakeTeapot(ModeInfo * mi, int newdir)
505 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
510 glRotatef(90.0, 1.0, 0.0, 0.0);
511 glRotatef(NRAND(3) * 90.0, 0.0, 0.0, 1.0);
515 glRotatef(90.0, 0.0, -1.0, 0.0);
516 glRotatef((NRAND(3) * 90.0) - 90.0, 0.0, 0.0, 1.0);
520 glRotatef(NRAND(4) * 90.0, 0.0, 0.0, 1.0);
524 glCallList(pp->teapot);
525 mi->polygon_count += pp->teapot_polys;
531 MakeShape(ModeInfo * mi, int newdir)
535 if (!MakeGuage(mi, newdir))
536 MakeTube(mi, newdir);
538 MakeValve(mi, newdir);
540 MakeTeapot(mi,newdir);
545 pinit(ModeInfo * mi, int zera)
547 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
551 mi->polygon_count = 0;
554 glColor3f(1.0, 1.0, 1.0);
556 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0);
557 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0);
558 glLightfv(GL_LIGHT0, GL_POSITION, position0);
559 glLightfv(GL_LIGHT1, GL_AMBIENT, ambient1);
560 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse1);
561 glLightfv(GL_LIGHT1, GL_POSITION, position1);
562 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
563 glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
564 glEnable(GL_LIGHTING);
567 glEnable(GL_DEPTH_TEST);
568 glEnable(GL_NORMALIZE);
569 glEnable(GL_CULL_FACE);
571 glShadeModel(GL_SMOOTH);
572 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess);
573 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular);
576 pp->system_number = 1;
577 glDrawBuffer(dbuf_p ? GL_BACK : GL_FRONT);
578 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
579 (void) memset(pp->Cells, 0, sizeof (pp->Cells));
580 for (X = 0; X < HCELLS; X++) {
581 for (Y = 0; Y < VCELLS; Y++) {
582 pp->Cells[X][Y][0] = 1;
583 pp->Cells[X][Y][HCELLS - 1] = 1;
584 pp->Cells[0][Y][X] = 1;
585 pp->Cells[HCELLS - 1][Y][X] = 1;
588 for (X = 0; X < HCELLS; X++) {
589 for (Z = 0; Z < HCELLS; Z++) {
590 pp->Cells[X][0][Z] = 1;
591 pp->Cells[X][VCELLS - 1][Z] = 1;
594 (void) memset(pp->usedcolors, 0, sizeof (pp->usedcolors));
595 if ((pp->initial_rotation += 10.0) > 45.0) {
596 pp->initial_rotation -= 90.0;
602 if (!MI_IS_MONO(mi)) {
603 int collist[DEFINEDCOLORS];
604 int i, j, lower = 1000;
606 /* Avoid repeating colors on the same screen unless necessary */
607 for (i = 0; i < DEFINEDCOLORS; i++) {
608 if (lower > pp->usedcolors[i])
609 lower = pp->usedcolors[i];
611 for (i = 0, j = 0; i < DEFINEDCOLORS; i++) {
612 if (pp->usedcolors[i] == lower) {
617 i = collist[NRAND(j)];
621 pp->system_color = MaterialRed;
624 pp->system_color = MaterialGreen;
627 pp->system_color = MaterialBlue;
630 pp->system_color = MaterialCyan;
633 pp->system_color = MaterialYellow;
636 pp->system_color = MaterialMagenta;
639 pp->system_color = MaterialWhite;
643 pp->system_color = MaterialGray;
647 pp->PX = NRAND((HCELLS - 1)) + 1;
648 pp->PY = NRAND((VCELLS - 1)) + 1;
649 pp->PZ = NRAND((HCELLS - 1)) + 1;
650 } while (pp->Cells[pp->PX][pp->PY][pp->PZ] ||
651 (pp->Cells[pp->PX + 1][pp->PY][pp->PZ] && pp->Cells[pp->PX - 1][pp->PY][pp->PZ] &&
652 pp->Cells[pp->PX][pp->PY + 1][pp->PZ] && pp->Cells[pp->PX][pp->PY - 1][pp->PZ] &&
653 pp->Cells[pp->PX][pp->PY][pp->PZ + 1] && pp->Cells[pp->PX][pp->PY][pp->PZ - 1]));
654 pp->Cells[pp->PX][pp->PY][pp->PZ] = 1;
655 pp->olddir = dirNone;
659 pp->nowdir = SelectNeighbor(mi);
663 reshape_pipes(ModeInfo * mi, int width, int height)
665 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
668 glViewport(0, 0, pp->WindW = (GLint) width, pp->WindH = (GLint) height);
669 glMatrixMode(GL_PROJECTION);
671 /*glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 15.0); */
672 gluPerspective(65.0, (GLfloat) width / (GLfloat) height, 0.1, 20.0);
673 glMatrixMode(GL_MODELVIEW);
675 glClear(GL_COLOR_BUFFER_BIT);
679 init_pipes (ModeInfo * mi)
681 int screen = MI_SCREEN(mi);
685 if ((pipes = (pipesstruct *) calloc(MI_NUM_SCREENS(mi),
686 sizeof (pipesstruct))) == NULL)
692 /* Single-buffering on iOS is so confusing! */
696 pp->window = MI_WINDOW(mi);
697 if ((pp->glx_context = init_GL(mi)) != NULL) {
699 reshape_pipes(mi, MI_WIDTH(mi), MI_HEIGHT(mi));
701 pp->initial_rotation = NRAND(180); /* jwz */
703 pp->initial_rotation = -10.0;
707 pp->valve = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_BigValve);
708 pp->bolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_Bolts3D);
709 pp->betweenbolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_PipeBetweenBolts);
711 pp->elbowbolts = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_ElbowBolts);
712 pp->elbowcoins = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_ElbowCoins);
714 pp->guagehead = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageHead);
715 pp->guageface = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageFace);
716 pp->guagedial = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageDial);
717 pp->guageconnector = BuildLWO(MI_IS_WIREFRAME(mi), &LWO_GuageConnector);
718 pp->teapot = build_teapot(mi);
720 /* else they are all 0, thanks to calloc(). */
722 if (MI_COUNT(mi) < 1 || MI_COUNT(mi) > NofSysTypes + 1) {
723 pp->system_type = NRAND(NofSysTypes) + 1;
725 pp->system_type = MI_COUNT(mi);
728 if (MI_CYCLES(mi) > 0 && MI_CYCLES(mi) < 11) {
729 pp->number_of_systems = MI_CYCLES(mi);
731 pp->number_of_systems = 5;
734 if (MI_SIZE(mi) < 10) {
735 pp->system_length = 10;
736 } else if (MI_SIZE(mi) > 1000) {
737 pp->system_length = 1000;
739 pp->system_length = MI_SIZE(mi);
747 draw_pipes (ModeInfo * mi)
749 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
751 Display *display = MI_DISPLAY(mi);
752 Window window = MI_WINDOW(mi);
753 Bool wire = MI_IS_WIREFRAME(mi);
758 if (!pp->glx_context)
761 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(pp->glx_context));
765 /* Would be nice to fade to black here, by drawing successive quads
766 over the whole scene with gamma. */
774 glTranslatef(0.0, 0.0, fisheye ? -3.8 : -4.8);
776 glRotatef(pp->initial_rotation, 0.0, 1.0, 0.0);
778 if (!MI_IS_ICONIC(mi)) {
779 /* Width/height ratio handled by gluPerspective() now. */
780 glScalef(Scale4Window, Scale4Window, Scale4Window);
782 glScalef(Scale4Iconic, Scale4Iconic, Scale4Iconic);
787 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
789 /* If it's the begining of a system, draw a sphere */
790 if (pp->olddir == dirNone) {
792 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
796 /* Check for stop conditions */
797 if (pp->ndirections == 0 || pp->counter > pp->system_length) {
799 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
800 /* Finish the system with another sphere */
805 /* If the maximum number of system was drawn, restart (clearing the screen), */
806 /* else start a new system. */
807 if (++pp->system_number > pp->number_of_systems) {
808 /* pause doing nothing for N seconds before clearing the screen. */
810 pp->reset = secs * 1000000 / (MI_PAUSE(mi) ? MI_PAUSE(mi) : 100);
821 /* Do will the direction change? if so, determine the new one */
823 if (!pp->directions[newdir]) { /* cannot proceed in the current direction */
824 newdir = SelectNeighbor(mi);
827 /* random change (20% chance) */
828 if ((pp->counter > 1) && (NRAND(100) < 20)) {
829 newdir = SelectNeighbor(mi);
832 /* Chance to turn increases after each length of pipe drawn */
833 if ((pp->counter > 1) && NRAND(50) < NRAND(pp->turncounter + 1)) {
834 newdir = SelectNeighbor(mi);
840 /* Has the direction changed? */
841 if (newdir == pp->nowdir) {
842 /* If not, draw the cell's center pipe */
844 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
845 /* Chance of factory shape here, if enabled. */
846 if ((pp->counter > 1) && (NRAND(100) < factory)) {
847 MakeShape(mi, newdir);
849 MakeTube(mi, newdir);
853 /* If so, draw the cell's center elbow/sphere */
854 int sysT = pp->system_type;
856 if (sysT == NofSysTypes + 1) {
857 sysT = ((pp->system_number - 1) % NofSysTypes) + 1;
863 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
864 mySphere(elbowradius, wire);
868 switch (pp->nowdir) {
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 - (one_third), (pp->PZ - 16) / 3.0 * 4.0);
877 glRotatef(180.0, 1.0, 0.0, 0.0);
878 glRotatef(180.0, 0.0, 1.0, 0.0);
881 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));
882 glRotatef(90.0, 0.0, 1.0, 0.0);
883 glRotatef(180.0, 0.0, 0.0, 1.0);
886 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));
887 glRotatef(90.0, 0.0, 1.0, 0.0);
888 glRotatef(180.0, 1.0, 0.0, 0.0);
895 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);
898 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);
899 glRotatef(180.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(270.0, 0.0, 1.0, 0.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);
914 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);
915 glRotatef(180.0, 0.0, 1.0, 0.0);
918 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);
919 glRotatef(180.0, 1.0, 0.0, 0.0);
920 glRotatef(180.0, 0.0, 1.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, 1.0, 0.0);
928 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));
929 glRotatef(270.0, 1.0, 0.0, 0.0);
930 glRotatef(180.0, 0.0, 0.0, 1.0);
937 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);
940 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);
941 glRotatef(180.0, 1.0, 0.0, 0.0);
944 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));
945 glRotatef(270.0, 1.0, 0.0, 0.0);
948 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));
949 glRotatef(90.0, 1.0, 0.0, 0.0);
956 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));
957 glRotatef(270.0, 1.0, 0.0, 0.0);
960 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));
961 glRotatef(270.0, 1.0, 0.0, 0.0);
962 glRotatef(180.0, 0.0, 1.0, 0.0);
965 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));
966 glRotatef(270.0, 0.0, 1.0, 0.0);
969 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));
970 glRotatef(90.0, 0.0, 1.0, 0.0);
971 glRotatef(180.0, 0.0, 0.0, 1.0);
978 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));
979 glRotatef(90.0, 0.0, 1.0, 0.0);
982 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));
983 glRotatef(90.0, 0.0, 1.0, 0.0);
984 glRotatef(180.0, 1.0, 0.0, 0.0);
987 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));
988 glRotatef(90.0, 1.0, 0.0, 0.0);
991 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));
992 glRotatef(270.0, 1.0, 0.0, 0.0);
993 glRotatef(180.0, 0.0, 0.0, 1.0);
998 myElbow(mi, (sysT == 2));
1007 pp->olddir = pp->nowdir;
1008 pp->nowdir = newdir;
1009 switch (pp->nowdir) {
1029 pp->Cells[pp->PX][pp->PY][pp->PZ] = 1;
1031 /* Cells'face pipe */
1032 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);
1033 MakeTube(mi, newdir);
1039 if (mi->fps_p) do_fps (mi);
1042 glXSwapBuffers(display, window);
1047 change_pipes (ModeInfo * mi)
1049 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
1051 if (!pp->glx_context)
1054 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), *(pp->glx_context));
1057 #endif /* !STANDALONE */
1061 release_pipes (ModeInfo * mi)
1063 if (pipes != NULL) {
1066 for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
1067 pipesstruct *pp = &pipes[screen];
1069 if (pp->glx_context) {
1071 /* Display lists MUST be freed while their glXContext is current. */
1072 glXMakeCurrent(MI_DISPLAY(mi), pp->window, *(pp->glx_context));
1075 glDeleteLists(pp->valve, 1);
1077 glDeleteLists(pp->bolts, 1);
1078 if (pp->betweenbolts)
1079 glDeleteLists(pp->betweenbolts, 1);
1082 glDeleteLists(pp->elbowbolts, 1);
1084 glDeleteLists(pp->elbowcoins, 1);
1087 glDeleteLists(pp->guagehead, 1);
1089 glDeleteLists(pp->guageface, 1);
1091 glDeleteLists(pp->guagedial, 1);
1092 if (pp->guageconnector)
1093 glDeleteLists(pp->guageconnector, 1);
1095 glDeleteLists(pp->teapot, 1);
1099 (void) free((void *) pipes);
1105 XSCREENSAVER_MODULE ("Pipes", pipes)