1 /* -*- Mode: C; tab-width: 4 -*-
2 * pipes.c - Shows 3D selfbuiding pipe system (xlock Version)
4 #if !defined( lint ) && !defined( SABER )
5 static const char sccsid[] = "@(#)pipes.c 4.04 97/07/28 xlockmore";
7 /* Permission to use, copy, modify, and distribute this software and its
8 * documentation for any purpose and without fee is hereby granted,
9 * provided that the above copyright notice appear in all copies and that
10 * both that copyright notice and this permission notice appear in
11 * supporting documentation.
13 * This file is provided AS IS with no warranties of any kind. The author
14 * shall have no liability with respect to the infringement of copyrights,
15 * trade secrets or any patents by this file or any part thereof. In no
16 * event will the author be liable for any lost revenue or profits or
17 * other special, indirect and consequential damages.
19 * This program was inspired on a WindowsNT(R)'s screen saver. It was written
20 * from scratch and it was not based on any other source code.
22 * ==========================================================================
23 * The routine myElbow is derivated from the doughnut routine from the MesaGL
24 * library (more especifically the Mesaaux library) written by Brian Paul.
25 * ==========================================================================
27 * Thanks goes to Brian Paul for making it possible and inexpensive to use
30 * Since I'm not a native english speaker, my apologies for any gramatical
33 * My e-mail addresses are
37 * marcelo@venus.rdc.puc-rio.br
39 * Marcelo F. Vianna (Apr-09-1997)
42 * 29-Apr-97: Factory equipment by Ed Mackey. Productive day today, eh?
43 * 29-Apr-97: Less tight turns Jeff Epler <jepler@inetnebr.com>
44 * 29-Apr-97: Efficiency speed-ups by Marcelo F. Vianna
48 * due to a Bug/feature in VMS X11/Intrinsic.h has to be placed before xlock.
49 * otherwise caddr_t is not defined correctly
52 #include <X11/Intrinsic.h>
55 # define PROGCLASS "Pipes"
56 # define HACK_INIT init_pipes
57 # define HACK_DRAW draw_pipes
58 # define pipes_opts xlockmore_opts
59 # define DEFAULTS "*count: 2 \n" \
64 "*tightturns: False \n" \
65 "*rotatepipes: True \n" \
67 # include "xlockmore.h" /* from the xscreensaver distribution */
68 #else /* !STANDALONE */
69 # include "xlock.h" /* from the xlockmore distribution */
70 #endif /* !STANDALONE */
77 #define DEF_FACTORY "2"
78 #define DEF_FISHEYE "True"
79 #define DEF_TIGHTTURNS "False"
80 #define DEF_ROTATEPIPES "True"
84 static Bool fisheye, tightturns, rotatepipes;
86 static XrmOptionDescRec opts[] =
88 {"-factory", ".pipes.factory", XrmoptionSepArg, (caddr_t) NULL},
89 {"-fisheye", ".pipes.fisheye", XrmoptionNoArg, (caddr_t) "on"},
90 {"+fisheye", ".pipes.fisheye", XrmoptionNoArg, (caddr_t) "off"},
91 {"-tightturns", ".pipes.tightturns", XrmoptionNoArg, (caddr_t) "on"},
92 {"+tightturns", ".pipes.tightturns", XrmoptionNoArg, (caddr_t) "off"},
93 {"-rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, (caddr_t) "on"},
94 {"+rotatepipes", ".pipes.rotatepipes", XrmoptionNoArg, (caddr_t) "off"}
96 static argtype vars[] =
98 {(caddr_t *) & factory, "factory", "Factory", DEF_FACTORY, t_Int},
99 {(caddr_t *) & fisheye, "fisheye", "Fisheye", DEF_FISHEYE, t_Bool},
100 {(caddr_t *) & tightturns, "tightturns", "Tightturns", DEF_TIGHTTURNS, t_Bool},
101 {(caddr_t *) & rotatepipes, "rotatepipes", "Rotatepipes", DEF_ROTATEPIPES, t_Bool}
103 static OptionStruct desc[] =
105 {"-factory num", "how much extra equipment in pipes (0 for none)"},
106 {"-/+fisheye", "turn on/off zoomed-in view of pipes"},
107 {"-/+tightturns", "turn on/off tight turns"},
108 {"-/+rotatepipes", "turn on/off pipe system rotation per screenful"}
111 ModeSpecOpt pipes_opts =
112 {7, opts, 4, vars, desc};
114 #define Scale4Window 0.1
115 #define Scale4Iconic 0.07
117 #define one_third 0.3333333333333333333
129 #define DEFINEDCOLORS 7
130 #define elbowradius 0.5
132 /*************************************************************************/
135 #if defined( MESA ) && defined( SLOW )
139 int Cells[HCELLS][VCELLS][HCELLS];
140 int usedcolors[DEFINEDCOLORS];
147 int number_of_systems;
152 GLfloat initial_rotation;
153 GLuint valve, bolts, betweenbolts, elbowbolts, elbowcoins;
154 GLuint guagehead, guageface, guagedial, guageconnector;
155 GLXContext glx_context;
158 extern struct lwo LWO_BigValve, LWO_PipeBetweenBolts, LWO_Bolts3D;
159 extern struct lwo LWO_GuageHead, LWO_GuageFace, LWO_GuageDial, LWO_GuageConnector;
160 extern struct lwo LWO_ElbowBolts, LWO_ElbowCoins;
162 static float front_shininess[] =
164 static float front_specular[] =
165 {0.7, 0.7, 0.7, 1.0};
166 static float ambient0[] =
167 {0.4, 0.4, 0.4, 1.0};
168 static float diffuse0[] =
169 {1.0, 1.0, 1.0, 1.0};
170 static float ambient1[] =
171 {0.2, 0.2, 0.2, 1.0};
172 static float diffuse1[] =
173 {0.5, 0.5, 0.5, 1.0};
174 static float position0[] =
175 {1.0, 1.0, 1.0, 0.0};
176 static float position1[] =
177 {-1.0, -1.0, 1.0, 0.0};
178 static float lmodel_ambient[] =
179 {0.5, 0.5, 0.5, 1.0};
180 static float lmodel_twoside[] =
183 static float MaterialRed[] =
184 {0.7, 0.0, 0.0, 1.0};
185 static float MaterialGreen[] =
186 {0.1, 0.5, 0.2, 1.0};
187 static float MaterialBlue[] =
188 {0.0, 0.0, 0.7, 1.0};
189 static float MaterialCyan[] =
190 {0.2, 0.5, 0.7, 1.0};
191 static float MaterialYellow[] =
192 {0.7, 0.7, 0.0, 1.0};
193 static float MaterialMagenta[] =
194 {0.6, 0.2, 0.5, 1.0};
195 static float MaterialWhite[] =
196 {0.7, 0.7, 0.7, 1.0};
197 static float MaterialGray[] =
198 {0.2, 0.2, 0.2, 1.0};
200 static pipesstruct *pipes = NULL;
204 MakeTube(int direction)
207 float SINan_3, COSan_3;
209 /*dirUP = 00000000 */
210 /*dirDOWN = 00000001 */
211 /*dirLEFT = 00000010 */
212 /*dirRIGHT = 00000011 */
213 /*dirNEAR = 00000100 */
214 /*dirFAR = 00000101 */
216 glRotatef(90.0, (direction & 6) ? 0.0 : 1.0, (direction & 2) ? 1.0 : 0.0, 0.0);
218 glBegin(GL_QUAD_STRIP);
219 for (an = 0.0; an <= 2.0 * M_PI; an += M_PI / 12.0) {
220 glNormal3f((COSan_3 = cos(an) / 3.0), (SINan_3 = sin(an) / 3.0), 0.0);
221 glVertex3f(COSan_3, SINan_3, one_third);
222 glVertex3f(COSan_3, SINan_3, -one_third);
228 mySphere(float radius)
230 GLUquadricObj *quadObj;
232 quadObj = gluNewQuadric();
233 gluQuadricDrawStyle(quadObj, (GLenum) GLU_FILL);
234 gluSphere(quadObj, radius, 16, 16);
235 gluDeleteQuadric(quadObj);
239 myElbow(ModeInfo * mi, int bolted)
246 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
249 GLfloat p0[3], p1[3], p2[3], p3[3];
250 GLfloat n0[3], n1[3], n2[3], n3[3];
251 GLfloat COSphi, COSphi1, COStheta, COStheta1;
252 GLfloat _SINtheta, _SINtheta1;
254 for (i = 0; i <= rings / 4; i++) {
255 GLfloat theta, theta1;
257 theta = (GLfloat) i *2.0 * M_PI / rings;
259 theta1 = (GLfloat) (i + 1) * 2.0 * M_PI / rings;
260 for (j = 0; j < nsides; j++) {
263 phi = (GLfloat) j *2.0 * M_PI / nsides;
265 phi1 = (GLfloat) (j + 1) * 2.0 * M_PI / nsides;
267 p0[0] = (COStheta = cos(theta)) * (R + r * (COSphi = cos(phi)));
268 p0[1] = (_SINtheta = -sin(theta)) * (R + r * COSphi);
270 p1[0] = (COStheta1 = cos(theta1)) * (R + r * COSphi);
271 p1[1] = (_SINtheta1 = -sin(theta1)) * (R + r * COSphi);
273 p2[0] = COStheta1 * (R + r * (COSphi1 = cos(phi1)));
274 p2[1] = _SINtheta1 * (R + r * COSphi1);
276 p3[0] = COStheta * (R + r * COSphi1);
277 p3[1] = _SINtheta * (R + r * COSphi1);
279 n0[0] = COStheta * COSphi;
280 n0[1] = _SINtheta * COSphi;
282 n1[0] = COStheta1 * COSphi;
283 n1[1] = _SINtheta1 * COSphi;
285 n2[0] = COStheta1 * COSphi1;
286 n2[1] = _SINtheta1 * COSphi1;
288 n3[0] = COStheta * COSphi1;
289 n3[1] = _SINtheta * COSphi1;
291 p0[2] = p1[2] = r * (n0[2] = n1[2] = sin(phi));
292 p2[2] = p3[2] = r * (n2[2] = n3[2] = sin(phi1));
307 if (factory > 0 && bolted) {
308 /* Bolt the elbow onto the pipe system */
311 glRotatef(90.0, 0.0, 0.0, -1.0);
312 glRotatef(90.0, 0.0, 1.0, 0.0);
313 glTranslatef(0.0, one_third, one_third);
314 glCallList(pp->elbowcoins);
315 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
316 glCallList(pp->elbowbolts);
317 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
328 FindNeighbors(ModeInfo * mi)
330 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
333 pp->directions[dirUP] = (!pp->Cells[pp->PX][pp->PY + 1][pp->PZ]) ? 1 : 0;
334 pp->ndirections += pp->directions[dirUP];
335 pp->directions[dirDOWN] = (!pp->Cells[pp->PX][pp->PY - 1][pp->PZ]) ? 1 : 0;
336 pp->ndirections += pp->directions[dirDOWN];
337 pp->directions[dirLEFT] = (!pp->Cells[pp->PX - 1][pp->PY][pp->PZ]) ? 1 : 0;
338 pp->ndirections += pp->directions[dirLEFT];
339 pp->directions[dirRIGHT] = (!pp->Cells[pp->PX + 1][pp->PY][pp->PZ]) ? 1 : 0;
340 pp->ndirections += pp->directions[dirRIGHT];
341 pp->directions[dirFAR] = (!pp->Cells[pp->PX][pp->PY][pp->PZ - 1]) ? 1 : 0;
342 pp->ndirections += pp->directions[dirFAR];
343 pp->directions[dirNEAR] = (!pp->Cells[pp->PX][pp->PY][pp->PZ + 1]) ? 1 : 0;
344 pp->ndirections += pp->directions[dirNEAR];
348 SelectNeighbor(ModeInfo * mi)
350 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
354 for (i = 0, j = 0; i < 6; i++) {
355 if (pp->directions[i]) {
361 return dirlist[NRAND(pp->ndirections)];
365 MakeValve(ModeInfo * mi, int newdir)
367 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
369 /* There is a glPopMatrix() right after this subroutine returns. */
373 glRotatef(90.0, 1.0, 0.0, 0.0);
374 glRotatef(NRAND(3) * 90.0, 0.0, 0.0, 1.0);
378 glRotatef(90.0, 0.0, -1.0, 0.0);
379 glRotatef((NRAND(3) * 90.0) - 90.0, 0.0, 0.0, 1.0);
383 glRotatef(NRAND(4) * 90.0, 0.0, 0.0, 1.0);
387 glCallList(pp->betweenbolts);
388 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
389 glCallList(pp->bolts);
390 if (!MI_WIN_IS_MONO(mi)) {
391 if (pp->system_color == MaterialRed) {
392 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialYellow : MaterialBlue);
393 } else if (pp->system_color == MaterialBlue) {
394 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialRed : MaterialYellow);
395 } else if (pp->system_color == MaterialYellow) {
396 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, NRAND(2) ? MaterialBlue : MaterialRed);
398 switch ((NRAND(3))) {
400 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialRed);
403 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialBlue);
406 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialYellow);
410 glRotatef((GLfloat) (NRAND(90)), 1.0, 0.0, 0.0);
411 glCallList(pp->valve);
412 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
417 MakeGuage(ModeInfo * mi, int newdir)
419 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
421 /* Can't have a guage on a vertical pipe. */
422 if ((newdir == dirUP) || (newdir == dirDOWN))
425 /* Is there space above this pipe for a guage? */
426 if (!pp->directions[dirUP])
429 /* Yes! Mark the space as used. */
430 pp->Cells[pp->PX][pp->PY + 1][pp->PZ] = 1;
434 if ((newdir == dirLEFT) || (newdir == dirRIGHT))
435 glRotatef(90.0, 0.0, 1.0, 0.0);
436 glCallList(pp->betweenbolts);
437 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialGray);
438 glCallList(pp->bolts);
441 glCallList(pp->guageconnector);
443 glTranslatef(0.0, 1.33333, 0.0);
444 /* Do not change the above to 1 + ONE_THIRD, because */
445 /* the object really is centered on 1.3333300000. */
446 glRotatef(NRAND(270) + 45.0, 0.0, 0.0, -1.0);
447 /* Random rotation for the dial. I love it. */
448 glCallList(pp->guagedial);
451 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
452 glCallList(pp->guagehead);
454 /* GuageFace is drawn last, in case of low-res depth buffers. */
455 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, MaterialWhite);
456 glCallList(pp->guageface);
458 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
465 MakeShape(ModeInfo * mi, int newdir)
469 if (!MakeGuage(mi, newdir))
473 MakeValve(mi, newdir);
478 static void pinit(ModeInfo * mi, int zera);
481 draw_pipes(ModeInfo * mi)
483 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
485 Display *display = MI_DISPLAY(mi);
486 Window window = MI_WINDOW(mi);
491 glXMakeCurrent(display, window, pp->glx_context);
493 #if defined( MESA ) && defined( SLOW )
494 glDrawBuffer(GL_BACK);
496 glDrawBuffer(GL_FRONT);
500 glTranslatef(0.0, 0.0, fisheye ? -3.8 : -4.8);
502 glRotatef(pp->initial_rotation, 0.0, 1.0, 0.0);
504 if (!MI_WIN_IS_ICONIC(mi)) {
505 /* Width/height ratio handled by gluPerspective() now. */
506 glScalef(Scale4Window, Scale4Window, Scale4Window);
508 glScalef(Scale4Iconic, Scale4Iconic, Scale4Iconic);
513 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, pp->system_color);
515 /* If it's the begining of a system, draw a sphere */
516 if (pp->olddir == dirNone) {
518 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
522 /* Check for stop conditions */
523 if (pp->ndirections == 0 || pp->counter > pp->system_length) {
525 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
526 /* Finish the system with another sphere */
528 #if defined( MESA ) && defined( SLOW )
529 glXSwapBuffers(display, window);
533 /* If the maximum number of system was drawn, restart (clearing the screen), */
534 /* else start a new system. */
535 if (++pp->system_number > pp->number_of_systems) {
548 /* Do will the direction change? if so, determine the new one */
550 if (!pp->directions[newdir]) { /* cannot proceed in the current direction */
551 newdir = SelectNeighbor(mi);
554 /* random change (20% chance) */
555 if ((pp->counter > 1) && (NRAND(100) < 20)) {
556 newdir = SelectNeighbor(mi);
559 /* Chance to turn increases after each length of pipe drawn */
560 if ((pp->counter > 1) && NRAND(50) < NRAND(pp->turncounter + 1)) {
561 newdir = SelectNeighbor(mi);
567 /* Has the direction changed? */
568 if (newdir == pp->nowdir) {
569 /* If not, draw the cell's center pipe */
571 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
572 /* Chance of factory shape here, if enabled. */
573 if ((pp->counter > 1) && (NRAND(100) < factory)) {
574 MakeShape(mi, newdir);
580 /* If so, draw the cell's center elbow/sphere */
581 int sysT = pp->system_type;
583 if (sysT == NofSysTypes + 1) {
584 sysT = ((pp->system_number - 1) % NofSysTypes) + 1;
590 glTranslatef((pp->PX - 16) / 3.0 * 4.0, (pp->PY - 12) / 3.0 * 4.0, (pp->PZ - 16) / 3.0 * 4.0);
591 mySphere(elbowradius);
595 switch (pp->nowdir) {
599 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);
600 glRotatef(180.0, 1.0, 0.0, 0.0);
603 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);
604 glRotatef(180.0, 1.0, 0.0, 0.0);
605 glRotatef(180.0, 0.0, 1.0, 0.0);
608 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));
609 glRotatef(90.0, 0.0, 1.0, 0.0);
610 glRotatef(180.0, 0.0, 0.0, 1.0);
613 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));
614 glRotatef(90.0, 0.0, 1.0, 0.0);
615 glRotatef(180.0, 1.0, 0.0, 0.0);
622 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);
625 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);
626 glRotatef(180.0, 0.0, 1.0, 0.0);
629 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));
630 glRotatef(270.0, 0.0, 1.0, 0.0);
633 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));
634 glRotatef(90.0, 0.0, 1.0, 0.0);
641 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);
642 glRotatef(180.0, 0.0, 1.0, 0.0);
645 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);
646 glRotatef(180.0, 1.0, 0.0, 0.0);
647 glRotatef(180.0, 0.0, 1.0, 0.0);
650 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));
651 glRotatef(270.0, 1.0, 0.0, 0.0);
652 glRotatef(180.0, 0.0, 1.0, 0.0);
655 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));
656 glRotatef(270.0, 1.0, 0.0, 0.0);
657 glRotatef(180.0, 0.0, 0.0, 1.0);
664 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);
667 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);
668 glRotatef(180.0, 1.0, 0.0, 0.0);
671 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));
672 glRotatef(270.0, 1.0, 0.0, 0.0);
675 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));
676 glRotatef(90.0, 1.0, 0.0, 0.0);
683 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));
684 glRotatef(270.0, 1.0, 0.0, 0.0);
687 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));
688 glRotatef(270.0, 1.0, 0.0, 0.0);
689 glRotatef(180.0, 0.0, 1.0, 0.0);
692 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));
693 glRotatef(270.0, 0.0, 1.0, 0.0);
696 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));
697 glRotatef(90.0, 0.0, 1.0, 0.0);
698 glRotatef(180.0, 0.0, 0.0, 1.0);
705 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));
706 glRotatef(90.0, 0.0, 1.0, 0.0);
709 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));
710 glRotatef(90.0, 0.0, 1.0, 0.0);
711 glRotatef(180.0, 1.0, 0.0, 0.0);
714 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));
715 glRotatef(90.0, 1.0, 0.0, 0.0);
718 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));
719 glRotatef(270.0, 1.0, 0.0, 0.0);
720 glRotatef(180.0, 0.0, 0.0, 1.0);
725 myElbow(mi, (sysT == 2));
734 pp->olddir = pp->nowdir;
736 switch (pp->nowdir) {
756 pp->Cells[pp->PX][pp->PY][pp->PZ] = 1;
758 /* Cells'face pipe */
759 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);
766 #if defined( MESA ) && defined( SLOW )
767 pp->flip = !pp->flip;
769 glXSwapBuffers(display, window);
774 reshape(ModeInfo * mi, int width, int height)
776 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
778 glViewport(0, 0, pp->WindW = (GLint) width, pp->WindH = (GLint) height);
779 glMatrixMode(GL_PROJECTION);
781 /*glFrustum(-1.0, 1.0, -1.0, 1.0, 5.0, 15.0); */
782 gluPerspective(65.0, (GLfloat) width / (GLfloat) height, 0.1, 20.0);
783 glMatrixMode(GL_MODELVIEW);
787 pinit(ModeInfo * mi, int zera)
789 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
793 glClearColor(0.0, 0.0, 0.0, 1.0);
794 glColor3f(1.0, 1.0, 1.0);
796 glLightfv(GL_LIGHT0, GL_AMBIENT, ambient0);
797 glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse0);
798 glLightfv(GL_LIGHT0, GL_POSITION, position0);
799 glLightfv(GL_LIGHT1, GL_AMBIENT, ambient1);
800 glLightfv(GL_LIGHT1, GL_DIFFUSE, diffuse1);
801 glLightfv(GL_LIGHT1, GL_POSITION, position1);
802 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
803 glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
804 glEnable(GL_LIGHTING);
807 glEnable(GL_DEPTH_TEST);
808 glEnable(GL_NORMALIZE);
809 glEnable(GL_CULL_FACE);
811 glShadeModel(GL_SMOOTH);
812 glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, front_shininess);
813 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, front_specular);
816 pp->system_number = 1;
817 glDrawBuffer(GL_FRONT_AND_BACK);
818 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
819 (void) memset(pp->Cells, 0, sizeof (pp->Cells));
820 for (X = 0; X < HCELLS; X++) {
821 for (Y = 0; Y < VCELLS; Y++) {
822 pp->Cells[X][Y][0] = 1;
823 pp->Cells[X][Y][HCELLS - 1] = 1;
824 pp->Cells[0][Y][X] = 1;
825 pp->Cells[HCELLS - 1][Y][X] = 1;
828 for (X = 0; X < HCELLS; X++) {
829 for (Z = 0; Z < HCELLS; Z++) {
830 pp->Cells[X][0][Z] = 1;
831 pp->Cells[X][VCELLS - 1][Z] = 1;
834 (void) memset(pp->usedcolors, 0, sizeof (pp->usedcolors));
835 if ((pp->initial_rotation += 10.0) > 45.0) {
836 pp->initial_rotation -= 90.0;
842 if (!MI_WIN_IS_MONO(mi)) {
843 int collist[DEFINEDCOLORS];
844 int i, j, lower = 1000;
846 /* Avoid repeating colors on the same screen unless necessary */
847 for (i = 0; i < DEFINEDCOLORS; i++) {
848 if (lower > pp->usedcolors[i])
849 lower = pp->usedcolors[i];
851 for (i = 0, j = 0; i < DEFINEDCOLORS; i++) {
852 if (pp->usedcolors[i] == lower) {
857 i = collist[NRAND(j)];
861 pp->system_color = MaterialRed;
864 pp->system_color = MaterialGreen;
867 pp->system_color = MaterialBlue;
870 pp->system_color = MaterialCyan;
873 pp->system_color = MaterialYellow;
876 pp->system_color = MaterialMagenta;
879 pp->system_color = MaterialWhite;
883 pp->system_color = MaterialGray;
887 pp->PX = NRAND((HCELLS - 1)) + 1;
888 pp->PY = NRAND((VCELLS - 1)) + 1;
889 pp->PZ = NRAND((HCELLS - 1)) + 1;
890 } while (pp->Cells[pp->PX][pp->PY][pp->PZ] ||
891 (pp->Cells[pp->PX + 1][pp->PY][pp->PZ] && pp->Cells[pp->PX - 1][pp->PY][pp->PZ] &&
892 pp->Cells[pp->PX][pp->PY + 1][pp->PZ] && pp->Cells[pp->PX][pp->PY - 1][pp->PZ] &&
893 pp->Cells[pp->PX][pp->PY][pp->PZ + 1] && pp->Cells[pp->PX][pp->PY][pp->PZ - 1]));
894 pp->Cells[pp->PX][pp->PY][pp->PZ] = 1;
895 pp->olddir = dirNone;
899 pp->nowdir = SelectNeighbor(mi);
903 init_pipes(ModeInfo * mi)
905 int screen = MI_SCREEN(mi);
909 if ((pipes = (pipesstruct *) calloc(MI_NUM_SCREENS(mi),
910 sizeof (pipesstruct))) == NULL)
915 pp->glx_context = init_GL(mi);
917 reshape(mi, MI_WIN_WIDTH(mi), MI_WIN_HEIGHT(mi));
918 pp->initial_rotation = -10.0;
922 pp->valve = BuildLWO(MI_WIN_IS_WIREFRAME(mi), &LWO_BigValve);
923 pp->bolts = BuildLWO(MI_WIN_IS_WIREFRAME(mi), &LWO_Bolts3D);
924 pp->betweenbolts = BuildLWO(MI_WIN_IS_WIREFRAME(mi), &LWO_PipeBetweenBolts);
926 pp->elbowbolts = BuildLWO(MI_WIN_IS_WIREFRAME(mi), &LWO_ElbowBolts);
927 pp->elbowcoins = BuildLWO(MI_WIN_IS_WIREFRAME(mi), &LWO_ElbowCoins);
929 pp->guagehead = BuildLWO(MI_WIN_IS_WIREFRAME(mi), &LWO_GuageHead);
930 pp->guageface = BuildLWO(MI_WIN_IS_WIREFRAME(mi), &LWO_GuageFace);
931 pp->guagedial = BuildLWO(MI_WIN_IS_WIREFRAME(mi), &LWO_GuageDial);
932 pp->guageconnector = BuildLWO(MI_WIN_IS_WIREFRAME(mi), &LWO_GuageConnector);
934 /* else they are all 0, thanks to calloc(). */
936 if (MI_BATCHCOUNT(mi) < 1 || MI_BATCHCOUNT(mi) > NofSysTypes + 1) {
937 pp->system_type = NRAND(NofSysTypes) + 1;
939 pp->system_type = MI_BATCHCOUNT(mi);
942 if (MI_CYCLES(mi) > 0 && MI_CYCLES(mi) < 11) {
943 pp->number_of_systems = MI_CYCLES(mi);
945 pp->number_of_systems = 5;
948 if (MI_SIZE(mi) < 10) {
949 pp->system_length = 10;
950 } else if (MI_SIZE(mi) > 1000) {
951 pp->system_length = 1000;
953 pp->system_length = MI_SIZE(mi);
959 change_pipes(ModeInfo * mi)
961 pipesstruct *pp = &pipes[MI_SCREEN(mi)];
963 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), pp->glx_context);
968 release_pipes(ModeInfo * mi)
973 for (screen = 0; screen < MI_NUM_SCREENS(mi); screen++) {
974 pipesstruct *pp = &pipes[screen];
976 /* Display lists MUST be freed while their glXContext is current. */
977 glXMakeCurrent(MI_DISPLAY(mi), MI_WINDOW(mi), pp->glx_context);
980 glDeleteLists(pp->valve, 1);
982 glDeleteLists(pp->bolts, 1);
983 if (pp->betweenbolts)
984 glDeleteLists(pp->betweenbolts, 1);
987 glDeleteLists(pp->elbowbolts, 1);
989 glDeleteLists(pp->elbowcoins, 1);
992 glDeleteLists(pp->guagehead, 1);
994 glDeleteLists(pp->guageface, 1);
996 glDeleteLists(pp->guagedial, 1);
997 if (pp->guageconnector)
998 glDeleteLists(pp->guageconnector, 1);
1001 /* Don't destroy the glXContext. init_GL does that. */
1003 (void) free((void *) pipes);