1
2 /*
3
4 ## COPYRIGHT (C) 2000 by G. Schaftenaar ##
5
6 MOLecular DENsity OpenGL Helper Program
7 By G. Schaftenaar
8 CMBI, University of Nijmegen, The Netherlands
9 (formerly CAOS/CAMM Center)
10 2000
11 */
12
13 #include <stdio.h>
14 #include <stdlib.h>
15 #include <math.h>
16
17 #ifndef WIN32
18 #include <GL/gl.h>
19 #endif
20 #ifdef DARWIN
21 /*
22 MacOS X "Panther" OpenGL implemantation -- Uses Xcode Tools
23 */
24 #include <OpenGL/glext.h>
25 #include <GLUT/glut.h>
26 #else
27 #include <GL/glut.h>
28 #endif
29
30 extern int ecol;
31 extern int bgcol;
32 extern double tr_val;
33 extern int mapped;
34 extern int hires;
35 extern int perspon;
36 extern GLfloat poszz;
37 extern int lines;
38 extern int lines;
39 extern int spacefill;
40 extern int atcol;
41 extern int width,height;
42 extern int RotType;
43 static int TRANS;
44 static int PERSP = 0;
45 static int l1on = 0;
46 static int l2on = 0;
47 static int l3on = 1;
48 static int stacks = 20;
49 static int DoLines = 0;
50 static int DoCap = 0;
51 static int DoFog = 0;
52 static GLfloat fdens = 0.03;
53 static int DoLights = 0;
54 static int ColBG = -1;
55
56 /* Some <math.h> files do not define M_PI... */
57 #ifndef M_PI
58 #define M_PI 3.141592654
59 #endif
60 #define TORAD M_PI/180.0
61
62 static GLdouble RR[4][4] = {
63 {1.0,0.0,0.0,0.0}, {0.0,1.0,0.0,0.0}, {0.0,0.0,1.0,0.0}, {0.0,0.0,0.0,1.0}
64 };
65
66 #define MAXFNAME 512
67 static int pixtyp = 0;
68 static char *pixext[] = {"rgb","ppm"};
69 #ifdef WIN32
70 static char *rgbfile = "mogl.rgb";
71 static char *ppmfile = "mogl.ppm";
72 #else
73 static char *rgbfile = "moldenogl.rgb";
74 static char *ppmfile = "moldenogl.ppm";
75 #endif
76 static char pixtmp[MAXFNAME];
77 #define PICMAX 180
78 static int picnum = 0;
79
80 static double z0[] = {0.0,0.0,0.0};
81 static double zx[] = {1.0,0.0,0.0};
82 static double zy[] = {0.0,1.0,0.0};
83
84 #define MAXSURF 500
85 extern float diffuseColor[MAXSURF][4] =
86 {
87 {0.15,0.15,1.0,0.8},
88 {1.0 ,0.1 ,0.1,0.8},
89 {1.0,1.0,0.0,0.8},
90 {1.0,0.5,0.5,0.8},
91 {1.0,0.5,0.5,0.8},
92 {1.0,0.5,0.5,0.8},
93 {1.0,0.5,0.5,0.8},
94 {1.0,0.5,0.5,0.8},
95 {1.0,0.5,0.5,0.8},
96 {1.0,0.5,0.5,0.8},
97 {1.0,0.5,0.5,0.8},
98 {1.0,0.5,0.5,0.8},
99 {1.0,0.5,0.5,0.8},
100 {1.0,0.5,0.5,0.8},
101 {1.0,0.5,0.5,0.8}
102 };
103
104 static float ambientColor[4] = {0.0,0.0,0.0,0.0};
105 static float ambientFColor[4] = {1.0,1.0,1.0,1.0};
106 static float specularColor[MAXSURF][4] =
107 { {0.8,0.8,0.8,1.0} , {0.8,0.8,0.8,1.0}, {0.9,0.8,0.8,1.0},
108 {0.8,0.8,0.8,1.0} , {0.8,0.8,0.8,1.0}, {0.9,0.8,0.8,1.0},
109 {0.8,0.8,0.8,1.0} , {0.8,0.8,0.8,1.0}
110 };
111
112 static float materialColor[8][4] =
113 {
114 {0.8, 0.8, 0.8, 1.0},
115 {0.8, 0.0, 0.0, 1.0},
116 {0.0, 0.8, 0.0, 1.0},
117 {0.0, 0.0, 0.8, 1.0},
118 {0.0, 0.8, 0.8, 1.0},
119 {0.8, 0.0, 0.8, 1.0},
120 {0.8, 0.8, 0.0, 1.0},
121 {1.0, 0.5, 0.5, 1.0},
122 };
123
124 static float clrColor[7][4] =
125 {
126 {0.0, 0.0, 0.0, 0.0},
127 {1.0, 1.0, 1.0, 1.0},
128 {1.0, 0.0, 0.0, 1.0},
129 {0.0, 1.0, 0.0, 1.0},
130 {0.0, 1.0, 1.0, 1.0},
131 {1.0, 0.5, 0.5, 0.0},
132 {0.5, 0.5, 0.5, 0.0},
133 };
134
135 static char *clrNames[7] =
136 { "Black", "White", "Red", "Green", "Blue", "Peach", "Grey"};
137
138 static Nclr = 7;
139
140 static float AmbientNul[4] = {0.0,0.0,0.0,0.0};
141
142 static float light0_position[] = {-2.0, -2.0, 0.0, 1};
143 static float light1_position[] = {4.0, 4.0, 4.0, 1};
144 static float light2_position[] = {0.0, 0.0, 4.0, 1};
145
146 #define MXEL 100
147 #define MXMOL 1000
148 static FILE *out;
149 static int dowrt = 0;
150 static int molon = 1;
151 static int AmbAndDiff = 1;
152 static int moving = 0;
153 static int startx, starty;
154 static int AutoRot = 0;
155 GLfloat ang1 = 0.0;
156 GLfloat ang2 = 0.0;
157 double angincr1 = 0.0;
158 double angincr2 = 0.0;
159 #define HISTMAX 3
160 #define MULTH 10.0
161 static double AngIncrHist1[HISTMAX];
162 static double AngIncrHist2[HISTMAX];
163 static int mmoving = 0;
164 static int mstartx, mstarty;
165 GLfloat posx = 0.0;
166 GLfloat posy = 0.0;
167 GLfloat posz = 2.0;
168 static int smoving = 0;
169 static int sstarty;
170
171 static int NSurf = -1;
172 GLuint theSurf[MAXSURF];
173 static int NMols = -1;
174 static int CMols = -1;
175 static int Anim = 1;
176 static int AnimSlow = 0;
177 static int AnimCount = 1;
178 GLuint theMol[MXMOL];
179 static GLUquadricObj *cyl;
180 static GLUquadricObj *sphere;
181
182 #define ROTINCR 5.0
183 static GLfloat xrot = -45.0;
184 static GLfloat yrot = 240.0;
185 static int Vsize = 600;
186
187 extern int AtomColors[15][3] =
188 {
189 {255,0,0},
190 {255,159,9},
191 {0,255,0},
192 {78,255,187},
193 {0,255,255},
194 {255,191,0},
195 {132,193,214},
196 {115,115,115},
197 {255,0,255},
198 {16,176,16},
199 {239,202,140},
200 {255,122,0},
201 {230,214,92},
202 {184,56,6},
203 {255,255,255},
204 };
205
206 /* How many feedback buffer GLfloats each of the three objects need. */
207 int objectComplexity = 3800000; /* Teapot requires ~1.5 megabytes for
208 its feedback results! */
209
idle(void)210 void idle(void)
211 {
212
213 if (AutoRot) {
214 ang1 = ang1 + 2.0;
215 angincr1 = 2.0;
216 glutPostRedisplay();
217 }
218
219 AnimCount--;
220 if (AnimCount < 0) AnimCount = AnimSlow;
221 if (!AnimCount) {
222 if (molon && Anim) {
223 CMols++;
224 if (CMols >= NMols) CMols = 0;
225 }
226 }
227 if (NMols > 1) glutPostRedisplay();
228
229 if (DoCap) {
230 picnum++;
231 if (picnum < PICMAX) {
232 sprintf(pixtmp, "mol%03d.%s",picnum,pixext[pixtyp]);
233 switch(pixtyp) {
234 case 0:
235 save_rgb(pixtmp);
236 break;
237 case 1:
238 save_pixmap(pixtmp);
239 break;
240 }
241
242 }
243 }
244
245 }
246
247 static void
setColor(int c)248 setColor(int c)
249 {
250 GLfloat ambientColor[4] = {0.0, 0.0, 0.0, 0.0};
251 GLfloat mat_specular[4] = {0.8, 0.8, 0.8, 1.0 };
252
253 glMaterialfv(GL_FRONT_AND_BACK,
254 GL_AMBIENT, ambientColor);
255 glMaterialfv(GL_FRONT_AND_BACK,
256 GL_DIFFUSE, &materialColor[c][0]);
257 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
258 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 130);
259 }
260
261
cross(float * a,float * b,float * c)262 void cross(float *a,float *b, float *c)
263 {
264 /*
265
266 calculates cross product: a x b = c
267 - - -
268 */
269
270 c[0] = a[1]*b[2] - a[2]*b[1];
271 c[1] = a[2]*b[0] - a[0]*b[2];
272 c[2] = a[0]*b[1] - a[1]*b[0];
273
274 }
275
veclen(float * a)276 float veclen(float *a)
277 {
278 float vl;
279 double tot;
280
281 tot = a[0]*a[0]+a[1]*a[1]+a[2]*a[2];
282
283 vl = 0.0;
284 if (tot > 0.0) vl = (float) sqrt(tot);
285
286 return(vl);
287
288 }
289
improd(float * a,float * b,double * c)290 void improd(float *a, float *b, double *c)
291 {
292 int i;
293 float rimp, al, bl;
294
295 rimp = 0.0;
296
297 for (i=0; i<3; i++) rimp = rimp + a[i]*b[i];
298
299 al = veclen(a);
300 bl = veclen(b);
301
302 if (al > 0.0 && bl > 0.0) {
303 *c = (double) rimp / (veclen(a)*veclen(b));
304 } else {
305 *c = 0.0;
306 }
307
308 }
309
310 #if defined(VMS) || defined(UNDERSC)
ognorm(double * v1,double * v2,double * v3)311 void ognorm(double *v1, double *v2, double *v3)
312 #else
313 #ifdef CRAY
314 void OGNORM(double *v1, double *v2, double *v3)
315 #else
316 void ognorm_(double *v1, double *v2, double *v3)
317 #endif
318 #endif
319 {
320 glNormal3d(*v1,*v2,*v3);
321 if (dowrt) fprintf(out,"%f %f %f\n",*v1,*v2,*v3);
322 }
323
324 #if defined(VMS) || defined(UNDERSC)
ogvert(double * v1,double * v2,double * v3)325 void ogvert(double *v1, double *v2, double *v3)
326 #else
327 #ifdef CRAY
328 void OGVERT(double *v1, double *v2, double *v3)
329 #else
330 void ogvert_(double *v1, double *v2, double *v3)
331 #endif
332 #endif
333 {
334 glVertex3d(*v1,*v2,*v3);
335 if (dowrt) fprintf(out,"%f %f %f\n",*v1,*v2,*v3);
336 }
337
338 #if defined(VMS) || defined(UNDERSC)
ogcol(double * v1,double * v2,double * v3)339 void ogcol(double *v1, double *v2, double *v3)
340 #else
341 #ifdef CRAY
342 void OGCOL(double *v1, double *v2, double *v3)
343 #else
344 void ogcol_(double *v1, double *v2, double *v3)
345 #endif
346 #endif
347 {
348 glColor4d(*v1,*v2,*v3,tr_val);
349 if (dowrt) fprintf(out,"%f %f %f\n",*v1,*v2,*v3);
350 }
351
352 extern void
setAtomColor(int c)353 setAtomColor(int c)
354 {
355 GLfloat tmp_Color[4];
356 int i;
357 GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
358
359 for (i=0; i<3; i++)
360 tmp_Color[i] = ((GLfloat) AtomColors[c][i]) / 255.0 ;
361 tmp_Color[3] = 0.5;
362
363 if (AmbAndDiff) {
364 glMaterialfv(GL_FRONT_AND_BACK,
365 GL_AMBIENT_AND_DIFFUSE, tmp_Color);
366 } else {
367 glMaterialfv(GL_FRONT_AND_BACK,
368 GL_AMBIENT, AmbientNul);
369 glMaterialfv(GL_FRONT_AND_BACK,
370 GL_DIFFUSE, tmp_Color);
371 }
372 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
373 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 100);
374
375 }
376
377
ogrod(int ic,float * p1,float * p2,double rad)378 void ogrod(int ic, float *p1, float *p2, double rad)
379 {
380 int i;
381 double cosa;
382 float angle, vl;
383 float v1[3], v2[3], v3[3], p3[3];
384 float todeg;
385
386
387 todeg = 45.0 / atan(1.0);
388
389 for (i=0; i<3; i++) {
390 v1[i] = p2[i] - p1[i];
391 v2[i] = 0.0;
392 p3[i] = v1[i]/2.0 + p1[i];
393 }
394 v2[2] = 1.0;
395
396 improd(v1,v2,&cosa);
397
398 if (abs(cosa) == 1.0) {
399
400 for (i=0; i<3; i++) v3[i] = 0.0;
401 v3[1] = 1.0;
402 angle = 0.0;
403 if (cosa < 0) angle = 180.0;
404
405 } else {
406
407 angle = (float) acos(cosa)*todeg;
408 cross(v2,v1,v3);
409 vl = veclen(v3);
410 for (i=0; i<3; i++) v3[i] = v3[i] / vl;
411
412 }
413
414
415 glPushMatrix();
416 glTranslatef(p1[0],p1[1],p1[2]);
417 glRotatef(angle,v3[0],v3[1],v3[2]);
418 setAtomColor(ic);
419 vl = veclen(v1);
420 if (hires) {
421 gluCylinder( cyl, rad, rad, vl, stacks, 10 );
422 } else {
423 gluCylinder( cyl, rad, rad, vl, 15, 1 );
424 }
425 glPopMatrix();
426
427 }
428
ogsphere(int ic,float * p1,double rad)429 void ogsphere(int ic, float *p1, double rad)
430 {
431
432 glPushMatrix();
433 glTranslatef(p1[0],p1[1],p1[2]);
434 setAtomColor(ic);
435 if (hires) {
436 gluSphere(sphere, rad, stacks, stacks);
437 } else {
438 gluSphere(sphere, rad, 10, 10);
439 }
440 glPopMatrix();
441
442 }
443
ogwrmol(double * r,double * adjus,int * natoms,int * nat,double * xsym,double * ysym,double * zsym,double * vdwr)444 ogwrmol(double *r, double *adjus, int *natoms, int *nat,
445 double *xsym, double *ysym, double *zsym, double *vdwr)
446 {
447 int i,j,k,ia,ja,nconn;
448 double dmaxsq, dijsq, st, tmp1[3], tmp2[3];
449 int iconn[30];
450
451 if (!dowrt) return;
452
453 if (*adjus != 1.0) {
454 fprintf(out,"[MOLECULE] AU CONN\n");
455 } else {
456 fprintf(out,"[MOLECULE] CONN\n");
457 }
458
459 fprintf(out,"%f %f %f\n",r[0],r[1],r[2]);
460 fprintf(out,"%d\n",*natoms);
461 for (i=0; i<*natoms; i++) {
462
463 ia = nat[i];
464 tmp1[0] = -1.0 * ysym[i] / r[0];
465 tmp1[1] = -1.0 * xsym[i] / r[0];
466 tmp1[2] = -1.0 * zsym[i] / r[0];
467
468
469 nconn = 0;
470 for (j=0; j<*natoms; j++) {
471
472 ja = nat[j];
473 tmp2[0] = -1.0 * ysym[j] / r[0];
474 tmp2[1] = -1.0 * xsym[j] / r[0];
475 tmp2[2] = -1.0 * zsym[j] / r[0];
476
477 dmaxsq = (vdwr[ia] + vdwr[ja]);
478 dmaxsq = dmaxsq * dmaxsq;
479
480 dijsq = 0.0;
481
482 st = (xsym[i] - xsym[j])*(*adjus);
483 st *= st;
484 dijsq = dijsq + st;
485
486 st = (ysym[i] - ysym[j])*(*adjus);
487 st *= st;
488 dijsq = dijsq + st;
489
490 st = (zsym[i] - zsym[j])*(*adjus);
491 st *= st;
492 dijsq = dijsq + st;
493
494 if (i != j && dijsq < dmaxsq) {
495 iconn[nconn] = j+1;
496 nconn++;
497 }
498
499 }
500 fprintf(out,"%d %f %f %f %d",nat[i],xsym[i],ysym[i],zsym[i],nconn);
501 for (k=0; k<nconn; k++)
502 fprintf(out," %d",iconn[k]);
503 fprintf(out,"\n");
504 }
505
506 }
507
508 #define MXCON 12
509
ogmol(double * r,double * adjus,int * natoms,int * nat,int * iatclr,int * icol,double * xsym,double * ysym,double * zsym,double * vdwr,int * mopt,int * conn,int * nconn,int * iconn)510 ogmol(double *r, double *adjus, int *natoms, int *nat, int* iatclr, int *icol,
511 double *xsym, double *ysym, double *zsym, double *vdwr,
512 int *mopt, int *conn, int *nconn, int *iconn)
513 {
514 double roddef, dmaxsq, dijsq, st;
515 float tmp1[3],tmp2[3], tmp3[3];
516 int i,j,k,l, ia, ic, ja, ido, doclr ;
517
518 doclr = 0;
519 if (iatclr != NULL && !atcol) doclr = 1;
520
521 if (dowrt) ogwrmol(r,adjus,natoms,nat,xsym,ysym,zsym,vdwr);
522
523 roddef = (0.13/0.52917706)/r[0];
524
525 if (*adjus == 1.0) roddef = roddef*0.52917706;
526
527 glPopMatrix();
528 glPushMatrix();
529
530 if (NMols >= MXMOL - 1) return;
531 if (*natoms == 0) return;
532
533 NMols++;
534 theMol[NMols] = glGenLists(1);
535 glNewList(theMol[NMols], GL_COMPILE);
536
537 if (*conn) {
538
539 for (i=0; i<*natoms; i++) {
540
541 ia = nat[i];
542 if (doclr) {
543 ic = iatclr[i]-1;
544 } else {
545 ic = icol[ia-1]-1;
546 }
547 if (*mopt) {
548 tmp1[0] = (float) xsym[i];
549 tmp1[1] = (float) ysym[i];
550 tmp1[2] = (float) zsym[i];
551 } else {
552 tmp1[0] = (float) -1.0 * ysym[i] / r[0];
553 tmp1[1] = (float) -1.0 * xsym[i] / r[0];
554 tmp1[2] = (float) -1.0 * zsym[i] / r[0];
555 }
556
557
558 if (spacefill) {
559
560 roddef = vdwr[ia]*1.4/(r[0]*0.52917706);
561 if (*adjus == 1.0) roddef = roddef*0.52917706;
562 ogsphere(ic,tmp1,roddef);
563
564 } else {
565
566 ogsphere(ic,tmp1,roddef);
567
568 for (k=0; k<nconn[i]; k++) {
569
570 j = iconn[k+i*MXCON] - 1;
571 ja = nat[j];
572 if (*mopt) {
573 tmp2[0] = (float) xsym[j];
574 tmp2[1] = (float) ysym[j];
575 tmp2[2] = (float) zsym[j];
576 } else {
577 tmp2[0] = (float) -1.0 * ysym[j] / r[0];
578 tmp2[1] = (float) -1.0 * xsym[j] / r[0];
579 tmp2[2] = (float) -1.0 * zsym[j] / r[0];
580 }
581
582 if (1) {
583
584 ido = 1;
585 if (ja == ia) {
586 if (j > i) {
587 for (l=0; l<3; l++) tmp3[l] = tmp2[l];
588 } else {
589 ido = 0;
590 }
591 } else {
592 for (l=0; l<3; l++)
593 tmp3[l] = (tmp2[l] - tmp1[l])/2.0 + tmp1[l];
594 }
595
596 if (ido) ogrod(ic,tmp1,tmp3,roddef);
597
598 }
599 }
600 }
601 }
602
603 } else {
604
605 for (i=0; i<*natoms; i++) {
606
607 ia = nat[i];
608 if (doclr) {
609 ic = iatclr[i]-1;
610 } else {
611 ic = icol[ia-1]-1;
612 }
613 if (*mopt) {
614 tmp1[0] = (float) xsym[i];
615 tmp1[1] = (float) ysym[i];
616 tmp1[2] = (float) zsym[i];
617 } else {
618 tmp1[0] = (float) -1.0 * ysym[i] / r[0];
619 tmp1[1] = (float) -1.0 * xsym[i] / r[0];
620 tmp1[2] = (float) -1.0 * zsym[i] / r[0];
621 }
622
623
624 if (spacefill) {
625
626 roddef = vdwr[ia]*1.4/(r[0]*0.52917706);
627 if (*adjus == 1.0) roddef = roddef*0.52917706;
628 ogsphere(ic,tmp1,roddef);
629
630 } else {
631
632 ogsphere(ic,tmp1,roddef);
633
634 for (j=0; j<*natoms; j++) {
635
636 ja = nat[j];
637 if (*mopt) {
638 tmp2[0] = (float) xsym[j];
639 tmp2[1] = (float) ysym[j];
640 tmp2[2] = (float) zsym[j];
641 } else {
642 tmp2[0] = (float) -1.0 * ysym[j] / r[0];
643 tmp2[1] = (float) -1.0 * xsym[j] / r[0];
644 tmp2[2] = (float) -1.0 * zsym[j] / r[0];
645 }
646
647 dmaxsq = (vdwr[ia] + vdwr[ja]);
648 dmaxsq = dmaxsq * dmaxsq;
649
650
651 dijsq = 0.0;
652
653 st = (xsym[i] - xsym[j])*(*adjus);
654 st *= st;
655 dijsq = dijsq + st;
656
657 st = (ysym[i] - ysym[j])*(*adjus);
658 st *= st;
659 dijsq = dijsq + st;
660
661 st = (zsym[i] - zsym[j])*(*adjus);
662 st *= st;
663 dijsq = dijsq + st;
664
665 if (dijsq < dmaxsq) {
666
667 ido = 1;
668 if (ja == ia) {
669 if (j > i) {
670 for (l=0; l<3; l++) tmp3[l] = tmp2[l];
671 } else {
672 ido = 0;
673 }
674 } else {
675 for (l=0; l<3; l++)
676 tmp3[l] = (tmp2[l] - tmp1[l])/2.0 + tmp1[l];
677 }
678
679 if (ido) ogrod(ic,tmp1,tmp3,roddef);
680
681 }
682
683 }
684 }
685 }
686 }
687 glEndList();
688
689 }
690
691 #if defined(VMS) || defined(UNDERSC)
oglin()692 void oglin()
693 #else
694 #ifdef CRAY
695 void OGLIN()
696 #else
697 void oglin_()
698 #endif
699 #endif
700 {
701
702 glPopMatrix();
703 glPushMatrix();
704
705 NSurf++;
706 theSurf[NSurf] = glGenLists(1);
707
708 glNewList(theSurf[NSurf], GL_COMPILE);
709
710 glEnable(GL_COLOR_MATERIAL);
711 glBegin(GL_LINES);
712 }
713
714 #if defined(VMS) || defined(UNDERSC)
ogbeg(isurf)715 void ogbeg(isurf)
716 #else
717 #ifdef CRAY
718 void OGBEG(isurf)
719 #else
720 void ogbeg_(isurf)
721 #endif
722 #endif
723 int *isurf;
724 {
725 int itrns;
726
727 itrns = 0;
728 if (*isurf < 0) {
729 itrns = 1;
730 }
731 TRANS = itrns;
732
733 if (dowrt) {
734 if (itrns) {
735 fprintf(out,"[SURFACE] TRANS COLOR 1.0 1.0 0.0\n");
736 } else {
737 fprintf(out,"[SURFACE]\n");
738 }
739 }
740
741 NSurf++;
742 theSurf[NSurf] = glGenLists(1);
743
744 glNewList(theSurf[NSurf], GL_COMPILE);
745
746 if (mapped) {
747 glColorMaterial(GL_FRONT_AND_BACK,GL_DIFFUSE);
748 glEnable(GL_COLOR_MATERIAL);
749 }
750
751 glBegin(GL_TRIANGLES);
752 }
753
754 #if defined(VMS) || defined(UNDERSC)
ogend()755 void ogend()
756 #else
757 #ifdef CRAY
758 void OGEND()
759 #else
760 void ogend_()
761 #endif
762 #endif
763 {
764 glEnd();
765 glDisable(GL_BLEND);
766 glDisable(GL_COLOR_MATERIAL);
767 glDisable(GL_CULL_FACE);
768 glEndList();
769 }
770
ogelev()771 void ogelev()
772 {
773 int i;
774
775 glPopMatrix();
776 glPushMatrix();
777
778 NSurf++;
779 theSurf[NSurf] = glGenLists(1);
780 glNewList(theSurf[NSurf], GL_COMPILE);
781
782 for (i=0; i<4; i++)
783 diffuseColor[NSurf][i] = materialColor[ecol][i];
784
785 glBegin(GL_QUADS);
786 }
787
ogribb()788 void ogribb()
789 {
790
791 glPopMatrix();
792 glPushMatrix();
793
794 NSurf++;
795 theSurf[NSurf] = glGenLists(1);
796 glNewList(theSurf[NSurf], GL_COMPILE);
797
798 glBegin(GL_QUADS);
799 }
800
crpsin(a,b,c,d)801 void crpsin(a,b,c,d)
802 double *a;
803 double *b;
804 double *c;
805 double *d;
806 {
807 /*
808
809 calculates cross product: (b-a) x (c-a) = d
810 --- --- -
811 */
812 int i;
813 double v1[3],v2[3],dlen;
814
815 for (i=0; i<3; i++) {
816 v1[i] = b[i]-a[i];
817 v2[i] = c[i]-a[i];
818 }
819
820 d[0] = v2[1]*v1[2]-v2[2]*v1[1];
821 d[1] = v2[2]*v1[0]-v2[0]*v1[2];
822 d[2] = v2[0]*v1[1]-v2[1]*v1[0];
823 dlen = sqrt(d[0]*d[0]+d[1]*d[1]+d[2]*d[2]);
824
825 if (dlen > 0 ) for (i=0; i<3; i++) d[i] = d[i] / dlen;
826 }
827
vln(double * a)828 double vln( double *a)
829 {
830 double vl;
831 double tot;
832
833 tot = a[0]*a[0]+a[1]*a[1]+a[2]*a[2];
834
835 vl = 0.0;
836 if (tot > 0.0) vl = sqrt(tot);
837
838 return(vl);
839
840 }
841
znorm(double rpts,double cnst,double * dens,double * vn,int npts1,int npts2,int i,int j)842 void znorm(double rpts, double cnst, double *dens, double *vn,
843 int npts1, int npts2, int i, int j)
844 {
845 double vl,z1[3],z2[3],z3[3],nx[3],ny[3];
846 int k;
847
848 if (j+1 < npts2) {
849 z1[0] = 1.0; z1[1] = 0.0;
850 z1[2] = cnst*rpts*(dens[j+1+i*npts2]-dens[j+i*npts2]);
851 crpsin(z0,z1,zy,z2);
852 } else {
853 for (k=0; k<3; k++) z2[k] = z0[k];
854 }
855
856 if (j-1 >= 0) {
857 z1[0] = -1.0; z1[1] = 0.0;
858 z1[2] = cnst*rpts*(dens[j-1+i*npts2]-dens[j+i*npts2]);
859 crpsin(z0,zy,z1,z3);
860 } else {
861 for (k=0; k<3; k++) z3[k] = z0[k];
862 }
863
864 for (k=0; k<3; k++) nx[k] = z3[k] + z2[k];
865 vl = vln(nx);
866 for (k=0; k<3; k++) nx[k] = nx[k] / vl;
867
868 if (i+1 < npts1) {
869 z1[0] = 0.0; z1[1] = 1.0;
870 z1[2] = cnst*rpts*(dens[j+(i+1)*npts2]-dens[j+i*npts2]);
871 crpsin(z0,z1,zx,z2);
872 } else {
873 for (k=0; k<3; k++) z2[k] = z0[k];
874 }
875
876 if (i-1 >= 0) {
877 z1[0] = 0.0; z1[1] = -1.0;
878 z1[2] = cnst*rpts*(dens[j+(i-1)*npts2]-dens[j+i*npts2]);
879 crpsin(z0,zx,z1,z3);
880 } else {
881 for (k=0; k<3; k++) z3[k] = z0[k];
882 }
883
884 for (k=0; k<3; k++) ny[k] = z3[k] + z2[k];
885 vl = vln(ny);
886 for (k=0; k<3; k++) ny[k] = ny[k] / vl;
887
888 for (k=0; k<3; k++) vn[k] = ny[k] - nx[k];
889 vl = vln(vn);
890 for (k=0; k<3; k++) vn[k] = vn[k] / vl;
891
892 }
893
ps_header(file)894 void ps_header(file)
895 FILE *file;
896 {
897 fprintf(file,"%%true {\n");
898 fprintf(file,"systemdict /colorimage known not {\n");
899 fprintf(file,"%%\n");
900 fprintf(file,"/colorImageDict 50 dict def\n");
901 fprintf(file,"/colorimage {\n");
902 fprintf(file," colorImageDict begin\n");
903 fprintf(file," /Ncomp exch def\n");
904 fprintf(file," {\n");
905 fprintf(file," (Multi-source not implemented\\n) print flush\n");
906 fprintf(file," limitcheck\n");
907 fprintf(file," } {\n");
908 fprintf(file," /Dsrc exch def\n");
909 fprintf(file," /Matrix exch def\n");
910 fprintf(file," /Bcomp exch def\n");
911 fprintf(file," /Height exch def\n");
912 fprintf(file," /Width exch def\n");
913 fprintf(file," /Bycomp Bcomp 7 add 8 idiv def\n");
914 fprintf(file," Bcomp 8 gt { (Only 8 bit per sample images \\n)\n");
915 fprintf(file," print flush limitcheck\n");
916 fprintf(file," } if\n");
917 fprintf(file," Width Height Bcomp Matrix\n");
918 fprintf(file," Ncomp 1 eq {\n");
919 fprintf(file," { Dsrc exec }\n");
920 fprintf(file," } if\n");
921 fprintf(file," Ncomp 3 eq {\n");
922 fprintf(file," /Gstr Bycomp Width mul string def\n");
923 fprintf(file," { Dsrc exec\n");
924 fprintf(file," /Cstr exch def\n");
925 fprintf(file," 0 1 Width 1 sub {\n");
926 fprintf(file," /I exch def\n");
927 fprintf(file," /X I 3 mul def\n");
928 fprintf(file," Gstr I\n");
929 fprintf(file," Cstr X get 0.3 mul\n");
930 fprintf(file," Cstr X 1 add get 0.59 mul\n");
931 fprintf(file," Cstr X 2 add get 0.11 mul\n");
932 fprintf(file," add add cvi\n");
933 fprintf(file," put\n");
934 fprintf(file," } for\n");
935 fprintf(file," Gstr\n");
936 fprintf(file," }\n");
937 fprintf(file," } if\n");
938 fprintf(file," Ncomp 4 eq {\n");
939 fprintf(file," /Gstr Bycomp Width mul string def\n");
940 fprintf(file," { Dsrc exec\n");
941 fprintf(file," /Cstr exch def\n");
942 fprintf(file," 0 1 Width 1 sub {\n");
943 fprintf(file," /I exch def\n");
944 fprintf(file," /X I 4 mul def\n");
945 fprintf(file," Gstr I\n");
946 fprintf(file," 2 Bcomp exp 1 sub\n");
947 fprintf(file," Cstr X get 0.3 mul\n");
948 fprintf(file," Cstr X 1 add get 0.59 mul\n");
949 fprintf(file," Cstr X 2 add get 0.11 mul\n");
950 fprintf(file," Cstr X 3 add get\n");
951 fprintf(file," add add add dup 2 index gt {pop dup} if\n");
952 fprintf(file," sub cvi\n");
953 fprintf(file," put\n");
954 fprintf(file," } for\n");
955 fprintf(file," Gstr\n");
956 fprintf(file," }\n");
957 fprintf(file," } if\n");
958 fprintf(file," image\n");
959 fprintf(file," } ifelse\n");
960 fprintf(file," end\n");
961 fprintf(file,"} bind def\n");
962 fprintf(file,"} if\n");
963 }
964
965 #define Max(a,b) (((a)>(b))?(a):(b))
966 #define Min(a,b) (((a)<(b))?(a):(b))
967
968 /* OpenGL's GL_3D_COLOR feedback vertex format. */
969 typedef struct _Feedback3Dcolor {
970 GLfloat x;
971 GLfloat y;
972 GLfloat z;
973 GLfloat red;
974 GLfloat green;
975 GLfloat blue;
976 GLfloat alpha;
977 } Feedback3Dcolor;
978
979
980
981
982 /* Write contents of one vertex to stdout. */
983 void
print3DcolorVertex(GLint size,GLint * count,GLfloat * buffer)984 print3DcolorVertex(GLint size, GLint * count,
985 GLfloat * buffer)
986 {
987 int i;
988
989 printf(" ");
990 for (i = 0; i < 7; i++) {
991 printf("%4.2f ", buffer[size - (*count)]);
992 *count = *count - 1;
993 }
994 printf("\n");
995 }
996
997 void
printBuffer(GLint size,GLfloat * buffer)998 printBuffer(GLint size, GLfloat * buffer)
999 {
1000 GLint count;
1001 int token, nvertices;
1002
1003 count = size;
1004 while (count) {
1005 token = (int) buffer[size - count];
1006 count--;
1007 switch (token) {
1008 case GL_PASS_THROUGH_TOKEN:
1009 printf("GL_PASS_THROUGH_TOKEN\n");
1010 printf(" %4.2f\n", buffer[size - count]);
1011 count--;
1012 break;
1013 case GL_POINT_TOKEN:
1014 printf("GL_POINT_TOKEN\n");
1015 print3DcolorVertex(size, &count, buffer);
1016 break;
1017 case GL_LINE_TOKEN:
1018 printf("GL_LINE_TOKEN\n");
1019 print3DcolorVertex(size, &count, buffer);
1020 print3DcolorVertex(size, &count, buffer);
1021 break;
1022 case GL_LINE_RESET_TOKEN:
1023 printf("GL_LINE_RESET_TOKEN\n");
1024 print3DcolorVertex(size, &count, buffer);
1025 print3DcolorVertex(size, &count, buffer);
1026 break;
1027 case GL_POLYGON_TOKEN:
1028 printf("GL_POLYGON_TOKEN\n");
1029 nvertices = (int) buffer[size - count];
1030 count--;
1031 for (; nvertices > 0; nvertices--) {
1032 print3DcolorVertex(size, &count, buffer);
1033 }
1034 }
1035 }
1036 }
1037
1038 GLfloat pointSize;
1039
1040 static char *gouraudtriangleEPS[] =
1041 {
1042 "/bd{bind def}bind def /triangle { aload pop setrgbcolor aload pop 5 3",
1043 "roll 4 2 roll 3 2 roll exch moveto lineto lineto closepath fill } bd",
1044 "/computediff1 { 2 copy sub abs threshold ge {pop pop pop true} { exch 2",
1045 "index sub abs threshold ge { pop pop true} { sub abs threshold ge } ifelse",
1046 "} ifelse } bd /computediff3 { 3 copy 0 get 3 1 roll 0 get 3 1 roll 0 get",
1047 "computediff1 {true} { 3 copy 1 get 3 1 roll 1 get 3 1 roll 1 get",
1048 "computediff1 {true} { 3 copy 2 get 3 1 roll 2 get 3 1 roll 2 get",
1049 "computediff1 } ifelse } ifelse } bd /middlecolor { aload pop 4 -1 roll",
1050 "aload pop 4 -1 roll add 2 div 5 1 roll 3 -1 roll add 2 div 3 1 roll add 2",
1051 "div 3 1 roll exch 3 array astore } bd /gouraudtriangle { computediff3 { 4",
1052 "-1 roll aload 7 1 roll 6 -1 roll pop 3 -1 roll pop add 2 div 3 1 roll add",
1053 "2 div exch 3 -1 roll aload 7 1 roll exch pop 4 -1 roll pop add 2 div 3 1",
1054 "roll add 2 div exch 3 -1 roll aload 7 1 roll pop 3 -1 roll pop add 2 div 3",
1055 "1 roll add 2 div exch 7 3 roll 10 -3 roll dup 3 index middlecolor 4 1 roll",
1056 "2 copy middlecolor 4 1 roll 3 copy pop middlecolor 4 1 roll 13 -1 roll",
1057 "aload pop 17 index 6 index 15 index 19 index 6 index 17 index 6 array",
1058 "astore 10 index 10 index 14 index gouraudtriangle 17 index 5 index 17",
1059 "index 19 index 5 index 19 index 6 array astore 10 index 9 index 13 index",
1060 "gouraudtriangle 13 index 16 index 5 index 15 index 18 index 5 index 6",
1061 "array astore 12 index 12 index 9 index gouraudtriangle 17 index 16 index",
1062 "15 index 19 index 18 index 17 index 6 array astore 10 index 12 index 14",
1063 "index gouraudtriangle 18 {pop} repeat } { aload pop 5 3 roll aload pop 7 3",
1064 "roll aload pop 9 3 roll 4 index 6 index 4 index add add 3 div 10 1 roll 7",
1065 "index 5 index 3 index add add 3 div 10 1 roll 6 index 4 index 2 index add",
1066 "add 3 div 10 1 roll 9 {pop} repeat 3 array astore triangle } ifelse } bd",
1067 NULL
1068 };
1069
1070 GLfloat *
spewPrimitiveEPS(FILE * file,GLfloat * loc)1071 spewPrimitiveEPS(FILE * file, GLfloat * loc)
1072 {
1073 int token;
1074 int nvertices, i;
1075 GLfloat red, green, blue;
1076 int smooth;
1077 GLfloat dx, dy, dr, dg, db, absR, absG, absB, colormax;
1078 int steps;
1079 Feedback3Dcolor *vertex;
1080 GLfloat xstep, ystep, rstep, gstep, bstep;
1081 GLfloat xnext, ynext, rnext, gnext, bnext, distance;
1082
1083 token = *loc;
1084 loc++;
1085 switch (token) {
1086 case GL_LINE_RESET_TOKEN:
1087 case GL_LINE_TOKEN:
1088 vertex = (Feedback3Dcolor *) loc;
1089
1090 dr = vertex[1].red - vertex[0].red;
1091 dg = vertex[1].green - vertex[0].green;
1092 db = vertex[1].blue - vertex[0].blue;
1093
1094 if (dr != 0 || dg != 0 || db != 0) {
1095 /* Smooth shaded line. */
1096 dx = vertex[1].x - vertex[0].x;
1097 dy = vertex[1].y - vertex[0].y;
1098 #ifdef DARWIN
1099 distance = sqrt(dx * dx + dy * dy);
1100 #else
1101 distance = sqrtf(dx * dx + dy * dy);
1102 #endif
1103
1104 absR = fabsf(dr);
1105 absG = fabsf(dg);
1106 absB = fabsf(db);
1107
1108
1109 #define EPS_SMOOTH_LINE_FACTOR 0.06 /* Lower for better smooth
1110
1111 lines. */
1112
1113 colormax = Max(absR, Max(absG, absB));
1114 steps = Max(1.0, colormax * distance * EPS_SMOOTH_LINE_FACTOR);
1115
1116 xstep = dx / steps;
1117 ystep = dy / steps;
1118
1119 rstep = dr / steps;
1120 gstep = dg / steps;
1121 bstep = db / steps;
1122
1123 xnext = vertex[0].x;
1124 ynext = vertex[0].y;
1125 rnext = vertex[0].red;
1126 gnext = vertex[0].green;
1127 bnext = vertex[0].blue;
1128
1129 /* Back up half a step; we want the end points to be
1130 exactly the their endpoint colors. */
1131 xnext -= xstep / 2.0;
1132 ynext -= ystep / 2.0;
1133 rnext -= rstep / 2.0;
1134 gnext -= gstep / 2.0;
1135 bnext -= bstep / 2.0;
1136 } else {
1137 /* Single color line. */
1138 steps = 0;
1139 }
1140
1141 fprintf(file, "%g %g %g setrgbcolor\n",
1142 vertex[0].red, vertex[0].green, vertex[0].blue);
1143 fprintf(file, "%g %g moveto\n", vertex[0].x, vertex[0].y);
1144
1145 for (i = 0; i < steps; i++) {
1146 xnext += xstep;
1147 ynext += ystep;
1148 rnext += rstep;
1149 gnext += gstep;
1150 bnext += bstep;
1151 fprintf(file, "%g %g lineto stroke\n", xnext, ynext);
1152 fprintf(file, "%g %g %g setrgbcolor\n", rnext, gnext, bnext);
1153 fprintf(file, "%g %g moveto\n", xnext, ynext);
1154 }
1155 fprintf(file, "%g %g lineto stroke\n", vertex[1].x, vertex[1].y);
1156
1157 loc += 14; /* Each vertex element in the feedback
1158 buffer is 7 GLfloats. */
1159
1160 break;
1161 case GL_POLYGON_TOKEN:
1162 nvertices = *loc;
1163 loc++;
1164
1165 vertex = (Feedback3Dcolor *) loc;
1166
1167 if (nvertices > 0) {
1168 red = vertex[0].red;
1169 green = vertex[0].green;
1170 blue = vertex[0].blue;
1171 smooth = 0;
1172 for (i = 1; i < nvertices; i++) {
1173 if (red != vertex[i].red || green != vertex[i].green || blue != vertex[i].blue) {
1174 smooth = 1;
1175 break;
1176 }
1177 }
1178 if (smooth) {
1179 /* Smooth shaded polygon; varying colors at vetices. */
1180
1181 /* Break polygon into "nvertices-2" triangle fans. */
1182 for (i = 0; i < nvertices - 2; i++) {
1183 fprintf(file, "[%g %g %g %g %g %g]",
1184 vertex[0].x, vertex[i + 1].x, vertex[i + 2].x,
1185 vertex[0].y, vertex[i + 1].y, vertex[i + 2].y);
1186 fprintf(file, " [%g %g %g] [%g %g %g] [%g %g %g] gouraudtriangle\n",
1187 vertex[0].red, vertex[0].green, vertex[0].blue,
1188 vertex[i + 1].red, vertex[i + 1].green, vertex[i + 1].blue,
1189 vertex[i + 2].red, vertex[i + 2].green, vertex[i + 2].blue);
1190 }
1191 } else {
1192 /* Flat shaded polygon; all vertex colors the same. */
1193 fprintf(file, "newpath\n");
1194 fprintf(file, "%g %g %g setrgbcolor\n", red, green, blue);
1195
1196 /* Draw a filled triangle. */
1197 fprintf(file, "%g %g moveto\n", vertex[0].x, vertex[0].y);
1198 for (i = 1; i < nvertices; i++) {
1199 fprintf(file, "%g %g lineto\n", vertex[i].x, vertex[i].y);
1200 }
1201 fprintf(file, "closepath fill\n\n");
1202 }
1203 }
1204 loc += nvertices * 7; /* Each vertex element in the
1205 feedback buffer is 7 GLfloats. */
1206 break;
1207 case GL_POINT_TOKEN:
1208 vertex = (Feedback3Dcolor *) loc;
1209 fprintf(file, "%g %g %g setrgbcolor\n", vertex[0].red, vertex[0].green, vertex[0].blue);
1210 fprintf(file, "%g %g %g 0 360 arc fill\n\n", vertex[0].x, vertex[0].y, pointSize / 2.0);
1211 loc += 7; /* Each vertex element in the feedback
1212 buffer is 7 GLfloats. */
1213 break;
1214 default:
1215 /* XXX Left as an excersie to the reader. */
1216 printf("Incomplete implementation. Unexpected token (%d).\n", token);
1217 exit(1);
1218 }
1219 return loc;
1220 }
1221
1222 void
spewUnsortedFeedback(FILE * file,GLint size,GLfloat * buffer)1223 spewUnsortedFeedback(FILE * file, GLint size, GLfloat * buffer)
1224 {
1225 GLfloat *loc, *end;
1226
1227 loc = buffer;
1228 end = buffer + size;
1229 while (loc < end) {
1230 loc = spewPrimitiveEPS(file, loc);
1231 }
1232 }
1233
1234 typedef struct _DepthIndex {
1235 GLfloat *ptr;
1236 GLfloat depth;
1237 } DepthIndex;
1238
1239 static int
compare(const void * a,const void * b)1240 compare(const void *a, const void *b)
1241 {
1242 DepthIndex *p1 = (DepthIndex *) a;
1243 DepthIndex *p2 = (DepthIndex *) b;
1244 GLfloat diff = p2->depth - p1->depth;
1245
1246 if (diff > 0.0) {
1247 return 1;
1248 } else if (diff < 0.0) {
1249 return -1;
1250 } else {
1251 return 0;
1252 }
1253 }
1254
1255 void
spewSortedFeedback(FILE * file,GLint size,GLfloat * buffer)1256 spewSortedFeedback(FILE * file, GLint size, GLfloat * buffer)
1257 {
1258 int token;
1259 GLfloat *loc, *end;
1260 Feedback3Dcolor *vertex;
1261 GLfloat depthSum;
1262 int nprimitives, item;
1263 DepthIndex *prims;
1264 int nvertices, i;
1265
1266 end = buffer + size;
1267
1268 /* Count how many primitives there are. */
1269 nprimitives = 0;
1270 loc = buffer;
1271 while (loc < end) {
1272 token = *loc;
1273 loc++;
1274 switch (token) {
1275 case GL_LINE_TOKEN:
1276 case GL_LINE_RESET_TOKEN:
1277 loc += 14;
1278 nprimitives++;
1279 break;
1280 case GL_POLYGON_TOKEN:
1281 nvertices = *loc;
1282 loc++;
1283 loc += (7 * nvertices);
1284 nprimitives++;
1285 break;
1286 case GL_POINT_TOKEN:
1287 loc += 7;
1288 nprimitives++;
1289 break;
1290 default:
1291 /* XXX Left as an excersie to the reader. */
1292 printf("Incomplete implementation. Unexpected token (%d).\n",
1293 token);
1294 exit(1);
1295 }
1296 }
1297
1298 /* Allocate an array of pointers that will point back at
1299 primitives in the feedback buffer. There will be one
1300 entry per primitive. This array is also where we keep the
1301 primitive's average depth. There is one entry per
1302 primitive in the feedback buffer. */
1303 prims = (DepthIndex *) malloc(sizeof(DepthIndex) * nprimitives);
1304
1305 item = 0;
1306 loc = buffer;
1307 while (loc < end) {
1308 prims[item].ptr = loc; /* Save this primitive's location. */
1309 token = *loc;
1310 loc++;
1311 switch (token) {
1312 case GL_LINE_TOKEN:
1313 case GL_LINE_RESET_TOKEN:
1314 vertex = (Feedback3Dcolor *) loc;
1315 depthSum = vertex[0].z + vertex[1].z;
1316 prims[item].depth = depthSum / 2.0;
1317 loc += 14;
1318 break;
1319 case GL_POLYGON_TOKEN:
1320 nvertices = *loc;
1321 loc++;
1322 vertex = (Feedback3Dcolor *) loc;
1323 depthSum = vertex[0].z;
1324 for (i = 1; i < nvertices; i++) {
1325 /* depthSum += vertex[i].z;*/
1326 depthSum = Min(depthSum, vertex[i].z);
1327 }
1328 /* prims[item].depth = depthSum / nvertices;*/
1329 prims[item].depth = depthSum;
1330 loc += (7 * nvertices);
1331 break;
1332 case GL_POINT_TOKEN:
1333 vertex = (Feedback3Dcolor *) loc;
1334 prims[item].depth = vertex[0].z;
1335 loc += 7;
1336 break;
1337 /*
1338 default:
1339 */
1340 /* XXX Left as an excersie to the reader. */
1341 /* assert(1); */
1342 }
1343 item++;
1344 }
1345 /*
1346 assert(item == nprimitives);
1347 */
1348
1349 /* Sort the primitives back to front. */
1350 qsort(prims, nprimitives, sizeof(DepthIndex), compare);
1351
1352 /* XXX Understand that sorting by a primitives average depth
1353 doesn't allow us to disambiguate some cases like self
1354 intersecting polygons. Handling these cases would require
1355 breaking up the primitives. That's too involved for this
1356 example. Sorting by depth is good enough for lots of
1357 applications. */
1358
1359 /* Emit the Encapsulated PostScript for the primitives in
1360 back to front order. */
1361 for (item = 0; item < nprimitives; item++) {
1362 (void) spewPrimitiveEPS(file, prims[item].ptr);
1363 }
1364
1365 free(prims);
1366 }
1367
1368 #define EPS_GOURAUD_THRESHOLD 0.1 /* Lower for better (slower)
1369
1370 smooth shading. */
1371
1372 void
spewWireFrameEPS(FILE * file,int doSort,GLint size,GLfloat * buffer,char * creator)1373 spewWireFrameEPS(FILE * file, int doSort, GLint size, GLfloat * buffer, char *creator)
1374 {
1375 GLfloat clearColor[4], viewport[4];
1376 GLfloat lineWidth;
1377 int i;
1378
1379 /* Read back a bunch of OpenGL state to help make the EPS
1380 consistent with the OpenGL clear color, line width, point
1381 size, and viewport. */
1382 glGetFloatv(GL_VIEWPORT, viewport);
1383 glGetFloatv(GL_COLOR_CLEAR_VALUE, clearColor);
1384 glGetFloatv(GL_LINE_WIDTH, &lineWidth);
1385 glGetFloatv(GL_POINT_SIZE, &pointSize);
1386
1387 /* Emit EPS header. */
1388 fputs("%!PS-Adobe-2.0 EPSF-2.0\n", file);
1389 /* Notice %% for a single % in the fprintf calls. */
1390 fprintf(file, "%%%%Creator: %s (using OpenGL feedback)\n", file, creator);
1391 fprintf(file, "%%%%BoundingBox: %g %g %g %g\n",
1392 viewport[0], viewport[1], viewport[2], viewport[3]);
1393 fputs("%%EndComments\n", file);
1394 fputs("\n", file);
1395 fputs("gsave\n", file);
1396 fputs("\n", file);
1397
1398 /* Output Frederic Delhoume's "gouraudtriangle" PostScript
1399 fragment. */
1400 fputs("% the gouraudtriangle PostScript fragement below is free\n", file);
1401 fputs("% written by Frederic Delhoume (delhoume@ilog.fr)\n", file);
1402 fprintf(file, "/threshold %g def\n", EPS_GOURAUD_THRESHOLD);
1403 for (i = 0; gouraudtriangleEPS[i]; i++) {
1404 fprintf(file, "%s\n", gouraudtriangleEPS[i]);
1405 }
1406
1407 fprintf(file, "\n%g setlinewidth\n", lineWidth);
1408
1409 /* Clear the background like OpenGL had it. */
1410 fprintf(file, "%g %g %g setrgbcolor\n",
1411 clearColor[0], clearColor[1], clearColor[2]);
1412 fprintf(file, "%g %g %g %g rectfill\n\n",
1413 viewport[0], viewport[1], viewport[2], viewport[3]);
1414
1415 if (doSort) {
1416 spewSortedFeedback(file, size, buffer);
1417 } else {
1418 spewUnsortedFeedback(file, size, buffer);
1419 }
1420
1421 /* Emit EPS trailer. */
1422 fputs("grestore\n\n", file);
1423 fputs("showpage\n", file);
1424
1425 fclose(file);
1426 }
1427
1428 /**************************************************************************
1429 *
1430 * Save the Frame Buffer in a ps/eps format file
1431 *
1432 * With thanks to Pedro Vazquez vazquez@penelope.iqm.unicamp.br
1433 *
1434 **************************************************************************/
1435 void
save_ps(mode)1436 save_ps(mode)
1437 int mode;
1438 {
1439 int x,y;
1440 int i,k,l,rowlen;
1441 FILE *file;
1442 GLubyte *rgbbuf;
1443
1444 x = glutGet(GLUT_WINDOW_WIDTH);
1445 y = glutGet(GLUT_WINDOW_HEIGHT);
1446
1447 rowlen = Vsize;
1448 if (x < Vsize) rowlen = x;
1449
1450 glPixelStorei(GL_PACK_ROW_LENGTH,rowlen);
1451 glPixelStorei(GL_PACK_ALIGNMENT,1);
1452
1453 rgbbuf = (GLubyte *)malloc(3*rowlen*y*sizeof(GLubyte));
1454 if (!rgbbuf) {
1455 fprintf(stderr,"moldenogl: couldn't allocate memory\n");
1456 return;
1457 }
1458
1459 glReadBuffer(GL_FRONT);
1460 glReadPixels(0,0,x,y,GL_RGB,GL_UNSIGNED_BYTE,rgbbuf);
1461
1462 if(mode)
1463 #ifdef WIN32
1464 file=fopen("mogl.ps","w");
1465 #else
1466 file=fopen("moldenogl.ps","w");
1467 #endif
1468 else
1469 #ifdef WIN32
1470 file=fopen("mogl.eps","w");
1471 #else
1472 file=fopen("moldenogl.eps","w");
1473 #endif
1474
1475 if (!file) {
1476 fprintf(stderr,"moldenogl: can't open output file\n");
1477 return;
1478 }
1479
1480 fprintf(file,"%%!PS-Adobe-2.0 EPSF-2.0\n");
1481 fprintf(file,"%%%%BoundingBox: 16 16 %d %d\n",x+16,y+16);
1482 fprintf(file,"%%%%Creator: Moldenogl\n");
1483 fprintf(file,"%%%%Title: Moldenogl output file\n");
1484 fprintf(file,"%%%%EndComments\n");
1485
1486 ps_header(file);
1487
1488 fprintf(file,"/picstr %d string def\n",y*3);
1489
1490 fprintf(file,"16 16 translate\n");
1491 fprintf(file,"%d %d scale\n",x,y);
1492 fprintf(file,"%d %d 8 [ %d 0 0 %d 0 0] \n",x,y,x,y);
1493 fprintf(file,"{ currentfile picstr readhexstring pop }\n");
1494 fprintf(file,"false 3 colorimage\n");
1495
1496 k = l = 0;
1497 for (i=0;i<x*y+1;i++){
1498
1499 fprintf(file,"%02x%02x%02x",rgbbuf[l],rgbbuf[l+1],rgbbuf[l+2]);
1500 l += 3;
1501 k += 6;
1502
1503 if (k>70){
1504 fprintf(file,"\n");
1505 k=0;
1506 }
1507 }
1508 if (mode)
1509 fprintf(file,"\nshowpage\n");
1510 fprintf(file,"%%%%Trailer\n");
1511 fclose(file);
1512 free(rgbbuf);
1513
1514 }
1515
1516 /**************************************************************************
1517 *
1518 *
1519 * Save the Frame Buffer in a ppm format file
1520 *
1521 * With thanks to Pedro Vazquez vazquez@penelope.iqm.unicamp.br
1522 *
1523 **************************************************************************/
1524
save_pixmap(ppmfile)1525 save_pixmap(ppmfile)
1526 char *ppmfile;
1527 {
1528 FILE *file;
1529 int i,j,k,x,y,rowlen;
1530 GLubyte *rgbbuf;
1531
1532 x = glutGet(GLUT_WINDOW_WIDTH);
1533 y = glutGet(GLUT_WINDOW_HEIGHT);
1534
1535 rowlen = Vsize;
1536 if (x < Vsize) rowlen = x;
1537
1538 glPixelStorei(GL_PACK_ROW_LENGTH,rowlen);
1539 glPixelStorei(GL_PACK_ALIGNMENT,1);
1540
1541 rgbbuf = (GLubyte *) malloc(3*rowlen*y*sizeof(GLubyte));
1542 if (!rgbbuf) {
1543 fprintf(stderr,"moldenogl: couldn't allocate memory\n");
1544 return;
1545 }
1546
1547 glReadBuffer(GL_FRONT);
1548 glReadPixels(0,0,x,y,GL_RGB,GL_UNSIGNED_BYTE,rgbbuf);
1549
1550 file = fopen(ppmfile,"w");
1551
1552 if (!file) {
1553 fprintf(stderr,"moldenogl: can't open output file\n");
1554 return;
1555 }
1556 fprintf(file,"P6\n");
1557 fprintf(file,"#Image rendered with moldenogl\n");
1558 fprintf(file,"%d\n%d\n255\n", x,y);
1559
1560 for(i=y-1; i>= 0; i--){
1561 for(j=0; j< x; j++){
1562 k = 3*(j + i*x);
1563 fwrite( &rgbbuf[k] ,sizeof(*rgbbuf), 1, file);
1564 fwrite( &rgbbuf[k+1] ,sizeof(*rgbbuf), 1, file);
1565 fwrite( &rgbbuf[k+2] ,sizeof(*rgbbuf), 1, file);
1566 }
1567 }
1568
1569 fclose(file);
1570 free(rgbbuf);
1571 }
1572
1573
1574
putbyte(outf,val)1575 putbyte(outf,val)
1576 FILE *outf;
1577 unsigned char val;
1578 {
1579 unsigned char buf[1];
1580
1581 buf[0] = val;
1582 fwrite(buf,1,1,outf);
1583 }
1584
putshort(outf,val)1585 putshort(outf,val)
1586 FILE *outf;
1587 unsigned short val;
1588 {
1589 unsigned char buf[2];
1590
1591 buf[0] = (val>>8);
1592 buf[1] = (val>>0);
1593 fwrite(buf,2,1,outf);
1594 }
1595
putlong(outf,val)1596 static int putlong(outf,val)
1597 FILE *outf;
1598 unsigned long val;
1599 {
1600 unsigned char buf[4];
1601
1602 buf[0] = (val>>24);
1603 buf[1] = (val>>16);
1604 buf[2] = (val>>8);
1605 buf[3] = (val>>0);
1606 return fwrite(buf,4,1,outf);
1607 }
1608
save_rgb(rgbfile)1609 save_rgb(rgbfile)
1610 char *rgbfile;
1611 {
1612 FILE *of;
1613 char iname[80];
1614 int i, k, rowlen;
1615 int Xsize, Ysize;
1616 GLubyte *rgbbuf;
1617
1618 of = fopen(rgbfile,"w");
1619
1620 if (!of) {
1621 fprintf(stderr,"moldenogl: can't open output file\n");
1622 return;
1623 }
1624
1625 Xsize = glutGet(GLUT_WINDOW_WIDTH);
1626 Ysize = glutGet(GLUT_WINDOW_HEIGHT);
1627
1628 rowlen = Vsize;
1629 if (Xsize < Vsize) rowlen = Xsize;
1630
1631 glPixelStorei(GL_PACK_ROW_LENGTH,rowlen);
1632 glPixelStorei(GL_PACK_ALIGNMENT,1);
1633
1634 rgbbuf = (GLubyte *)malloc(3*rowlen*Ysize*sizeof(GLubyte));
1635 if (!rgbbuf) {
1636 fprintf(stderr,"moldenogl: couldn't allocate memory\n");
1637 close(of);
1638 return;
1639 }
1640 glReadBuffer(GL_FRONT);
1641 glReadPixels(0,0,Xsize,Ysize,GL_RGB,GL_UNSIGNED_BYTE,rgbbuf);
1642
1643 putshort(of,474); /* MAGIC */
1644 putbyte(of,0); /* STORAGE is VERBATIM */
1645 putbyte(of,257); /* BPC is 257 */
1646 putshort(of,3); /* DIMENSION is 3 */
1647 putshort(of,Xsize); /* XSIZE */
1648 putshort(of,Ysize); /* YSIZE */
1649 putshort(of,3); /* ZSIZE */
1650 putlong(of,0); /* PIXMIN is 0 */
1651 putlong(of,255); /* PIXMAX is 255 */
1652 for(i=0; i<4; i++) /* DUMMY 4 bytes */
1653 putbyte(of,0);
1654 strcpy(iname,"Moldenogl");
1655 fwrite(iname,80,1,of); /* IMAGENAME */
1656 putlong(of,0); /* COLORMAP is 0 */
1657
1658 for(i=0; i<404; i++)
1659 putbyte(of,0);
1660
1661 /* red */
1662 k=0;
1663 for(i=0;i< Xsize*Ysize; i++){
1664 fwrite( &rgbbuf[k] ,sizeof(*rgbbuf), 1, of);
1665 k=k+3;
1666 }
1667
1668 /* green */
1669 k=0;
1670 for(i=0;i< Xsize*Ysize; i++){
1671 fwrite( &rgbbuf[k+1] ,sizeof(*rgbbuf), 1, of);
1672 k=k+3;
1673 }
1674
1675 /* blue */
1676 k=0;
1677 for(i=0;i< Xsize*Ysize; i++){
1678 fwrite( &rgbbuf[k+2] ,sizeof(*rgbbuf), 1, of);
1679 k=k+3;
1680 }
1681
1682 fclose(of);
1683 free(rgbbuf);
1684 }
1685
1686 unsigned char bmp_header[]=
1687 { 'B','M', 0,0,0,0, 0,0, 0,0, 54,0,0,0,
1688 40,0,0,0, 0,0,0,0, 0,0,0,0, 1,0, 24,0, 0,0,0,0, 0,0,0,0,
1689 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0 };
1690
WLSBL(val,arr)1691 static void WLSBL(val,arr)
1692 int val;
1693 char* arr;
1694 {
1695 arr[0] = (char) (val&0xff);
1696 arr[1] = (char) ((val>>8) &0xff);
1697 arr[2] = (char) ((val>>16)&0xff);
1698 arr[3] = (char) ((val>>24)&0xff);
1699 }
1700
save_bmp()1701 save_bmp()
1702 { int i,j;
1703 FILE *fp;
1704 GLubyte *rgbbuf;
1705 GLubyte rgbtmp[3];
1706 int Xsize, Ysize, rowlen;
1707 int pad;
1708
1709 #ifdef WIN32
1710 if ((fp=fopen("mogl.bmp","wb"))==NULL) return(1);
1711 #else
1712 if ((fp=fopen("moldenogl.bmp","wb"))==NULL) return(1);
1713 #endif
1714
1715 Xsize = glutGet(GLUT_WINDOW_WIDTH);
1716 Ysize = glutGet(GLUT_WINDOW_HEIGHT);
1717
1718 rowlen = Vsize;
1719 if (Xsize < Vsize) rowlen = Xsize;
1720
1721 glPixelStorei(GL_PACK_ROW_LENGTH,rowlen);
1722 glPixelStorei(GL_PACK_ALIGNMENT,1);
1723
1724 rgbbuf = (GLubyte *)malloc(3*rowlen*Ysize*sizeof(GLubyte));
1725 if (!rgbbuf) {
1726 fprintf(stderr,"moldenogl: couldn't allocate memory\n");
1727 close(fp);
1728 return;
1729 }
1730 glReadBuffer(GL_FRONT);
1731 glReadPixels(0,0,Xsize,Ysize,GL_RGB,GL_UNSIGNED_BYTE,rgbbuf);
1732
1733 /* The number of bytes on a screenline should be wholly devisible by 4 */
1734
1735 pad = (Xsize*3)%4;
1736 if (pad) pad = 4 - pad;
1737
1738 WLSBL((int) (3*Xsize+pad)*Ysize+54,bmp_header+2);
1739 WLSBL((int) Xsize,bmp_header+18);
1740 WLSBL((int) Ysize,bmp_header+22);
1741 WLSBL((int) 3*Xsize*Ysize,bmp_header+34);
1742
1743 fwrite(bmp_header,1,54,fp);
1744
1745 for (i=0;i<Ysize;i++) {
1746 for (j=0;j<Xsize;j++) {
1747 rgbtmp[0] = rgbbuf[(j+Xsize*i)*3+2];
1748 rgbtmp[1] = rgbbuf[(j+Xsize*i)*3+1];
1749 rgbtmp[2] = rgbbuf[(j+Xsize*i)*3+0];
1750 fwrite(rgbtmp,3,1,fp);
1751 }
1752 rgbtmp[0] = (char) 0;
1753 for (j=0;j<pad;j++) fwrite(rgbtmp,1,1,fp);
1754 }
1755
1756 fclose(fp);
1757 free(rgbbuf);
1758 }
1759
BuildList(r,cnst,nnpts1,nnpts2,dens)1760 BuildList(r,cnst,nnpts1,nnpts2,dens)
1761 double *r;
1762 double *cnst;
1763 int *nnpts1;
1764 int *nnpts2;
1765 double *dens;
1766 {
1767
1768 int i,j,noff1,noff2,npts1,npts2;
1769 double v[3], rpts;
1770 double vec1[3], vn1[3];
1771 float hinv1,hinv2;
1772
1773 /*
1774 a grid of n*n points has n-1*n-1 squares
1775 and twice as much triangular polygons
1776 so 2*(npts-1)**2
1777 npts is 80 at maximum so lets make it 12800
1778 */
1779
1780 npts1 = *nnpts1;
1781 npts2 = *nnpts2;
1782 noff1 = npts1/2;
1783 noff2 = npts2/2;
1784 rpts = (double) (npts1-1);
1785 hinv1 = r[1]/ (npts2*r[0]);
1786 hinv2 = 1.0/ npts1;
1787
1788 NSurf++;
1789 theSurf[NSurf] = glGenLists(1);
1790
1791 glPopMatrix();
1792 glPushMatrix();
1793
1794 glNewList(theSurf[0], GL_COMPILE);
1795
1796 setColor(2);
1797
1798 glBegin(GL_QUADS);
1799
1800 if (dowrt) fprintf(out,"[ELEVATIONGRID]\n");
1801
1802 for (i=0; i<npts1-1; i++) {
1803 for (j=0; j<npts2-1; j++) {
1804 /*
1805 first triangle
1806 */
1807 vec1[0] = (double) (j-noff2);
1808 vec1[1] = (double) (i-noff1);
1809 vec1[2] = dens[j+i*npts2]*(*cnst)*rpts;
1810
1811 znorm(rpts,*cnst,dens,vn1,npts1,npts2,i,j);
1812
1813 #if defined(VMS) || defined(UNDERSC)
1814 ognorm(&vn1[0],&vn1[1],&vn1[2]);
1815 #else
1816 #ifdef CRAY
1817 OGNORM(&vn1[0],&vn1[1],&vn1[2]);
1818 #else
1819 ognorm_(&vn1[0],&vn1[1],&vn1[2]);
1820 #endif
1821 #endif
1822
1823 v[0] = vec1[0]*hinv1;
1824 v[1] = vec1[1]*hinv2;
1825 v[2] = vec1[2]*hinv1;
1826 #if defined(VMS) || defined(UNDERSC)
1827 ogvert(&v[0],&v[1],&v[2]);
1828 #else
1829 #ifdef CRAY
1830 OGVERT(&v[0],&v[1],&v[2]);
1831 #else
1832 ogvert_(&v[0],&v[1],&v[2]);
1833 #endif
1834 #endif
1835
1836 vec1[0] = (double) (j+1-noff2);
1837 vec1[1] = (double) (i-noff1);
1838 vec1[2] = dens[j+1+i*npts2]*(*cnst)*rpts;
1839
1840 znorm(rpts,*cnst,dens,vn1,npts1,npts2,i,j+1);
1841
1842 #if defined(VMS) || defined(UNDERSC)
1843 ognorm(&vn1[0],&vn1[1],&vn1[2]);
1844 #else
1845 #ifdef CRAY
1846 OGNORM(&vn1[0],&vn1[1],&vn1[2]);
1847 #else
1848 ognorm_(&vn1[0],&vn1[1],&vn1[2]);
1849 #endif
1850 #endif
1851
1852 v[0] = vec1[0]*hinv1;
1853 v[1] = vec1[1]*hinv2;
1854 v[2] = vec1[2]*hinv1;
1855 #if defined(VMS) || defined(UNDERSC)
1856 ogvert(&v[0],&v[1],&v[2]);
1857 #else
1858 #ifdef CRAY
1859 OGVERT(&v[0],&v[1],&v[2]);
1860 #else
1861 ogvert_(&v[0],&v[1],&v[2]);
1862 #endif
1863 #endif
1864
1865 vec1[0] = (double) (j+1-noff2);
1866 vec1[1] = (double) (i+1-noff1);
1867 vec1[2] = dens[j+1+(i+1)*npts2]*(*cnst)*rpts;
1868
1869 znorm(rpts,*cnst,dens,vn1,npts1,npts2,i+1,j+1);
1870
1871 #if defined(VMS) || defined(UNDERSC)
1872 ognorm(&vn1[0],&vn1[1],&vn1[2]);
1873 #else
1874 #ifdef CRAY
1875 OGNORM(&vn1[0],&vn1[1],&vn1[2]);
1876 #else
1877 ognorm_(&vn1[0],&vn1[1],&vn1[2]);
1878 #endif
1879 #endif
1880
1881 v[0] = vec1[0]*hinv1;
1882 v[1] = vec1[1]*hinv2;
1883 v[2] = vec1[2]*hinv1;
1884 #if defined(VMS) || defined(UNDERSC)
1885 ogvert(&v[0],&v[1],&v[2]);
1886 #else
1887 #ifdef CRAY
1888 OGVERT(&v[0],&v[1],&v[2]);
1889 #else
1890 ogvert_(&v[0],&v[1],&v[2]);
1891 #endif
1892 #endif
1893
1894 vec1[0] = (double) (j-noff2);
1895 vec1[1] = (double) (i+1-noff1);
1896 vec1[2] = dens[j+(i+1)*npts2]*(*cnst)*rpts;
1897
1898 znorm(rpts,*cnst,dens,vn1,npts1,npts2,i+1,j);
1899
1900 #if defined(VMS) || defined(UNDERSC)
1901 ognorm(&vn1[0],&vn1[1],&vn1[2]);
1902 #else
1903 #ifdef CRAY
1904 OGNORM(&vn1[0],&vn1[1],&vn1[2]);
1905 #else
1906 ognorm_(&vn1[0],&vn1[1],&vn1[2]);
1907 #endif
1908 #endif
1909
1910 v[0] = vec1[0]*hinv1;
1911 v[1] = vec1[1]*hinv2;
1912 v[2] = vec1[2]*hinv1;
1913 #if defined(VMS) || defined(UNDERSC)
1914 ogvert(&v[0],&v[1],&v[2]);
1915 #else
1916 #ifdef CRAY
1917 OGVERT(&v[0],&v[1],&v[2]);
1918 #else
1919 ogvert_(&v[0],&v[1],&v[2]);
1920 #endif
1921 #endif
1922
1923 }
1924 }
1925
1926 glEnd();
1927
1928 glEndList();
1929
1930 }
1931
dispsf(void)1932 void dispsf(void)
1933 {
1934 int i;
1935 double ca,sa,x,y,z;
1936
1937 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
1938
1939 glMatrixMode(GL_PROJECTION);
1940 glLoadIdentity();
1941
1942 if (PERSP) {
1943 glFrustum(-0.2,0.2,-0.2,0.2,0.3,300);
1944 } else {
1945 glOrtho(-1.0,1.0,-1.0,1.0,-10.0,10.0);
1946 }
1947
1948 glMatrixMode(GL_MODELVIEW);
1949 glLoadIdentity();
1950
1951 if (PERSP) {
1952 glTranslatef( posx, posy, posz);
1953 } else {
1954 glScalef(posz, posz, posz);
1955 glTranslatef( posx, posy, 0.0);
1956 }
1957
1958 glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
1959 if (DoLights) {
1960 glPushMatrix();
1961 glTranslatef(light0_position[0],light0_position[1],light0_position[2]);
1962 gluSphere(sphere, 1, 10, 10);
1963 glPopMatrix();
1964 }
1965
1966 glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
1967 if (DoLights) {
1968 glPushMatrix();
1969 glTranslatef(light1_position[0],light1_position[1],light1_position[2]);
1970 gluSphere(sphere, 1, 10, 10);
1971 glPopMatrix();
1972 }
1973
1974 glLightfv(GL_LIGHT2, GL_POSITION, light2_position);
1975 if (DoLights) {
1976 glPushMatrix();
1977 glTranslatef(light2_position[0],light2_position[1],light2_position[2]);
1978 gluSphere(sphere, 1, 10, 10);
1979 glPopMatrix();
1980 }
1981
1982
1983 if (RotType) {
1984
1985 ca = cos(angincr2*TORAD);
1986 sa = sin(angincr2*TORAD);
1987 for (i=0; i < 3; i++) {
1988 y = RR[i][1];
1989 z = RR[i][2];
1990 RR[i][1] = ca*y - sa*z;
1991 RR[i][2] = ca*z + sa*y;
1992 }
1993
1994 ca = cos(angincr1*TORAD);
1995 sa = sin(angincr1*TORAD);
1996 for (i=0; i < 3; i++) {
1997 x = RR[i][0];
1998 z = RR[i][2];
1999 RR[i][0] = ca*x + sa*z;
2000 RR[i][2] = ca*z - sa*x;
2001 }
2002
2003 glMultMatrixd((const GLdouble *) RR);
2004
2005 } else {
2006
2007 glRotatef( ang2, 1.0, 0.0, 0.0 );
2008 glRotatef( ang1, 0.0, 0.0, 1.0 );
2009 }
2010
2011 glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
2012
2013 glPushMatrix();
2014
2015 if (molon) {
2016 glCallList(theMol[CMols]);
2017 }
2018
2019 if (DoLines) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
2020 else glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
2021
2022 glPopMatrix();
2023
2024 for (i=0; i<NSurf; i++) {
2025
2026 if (TRANS) {
2027 glEnable(GL_BLEND);
2028 glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);
2029 diffuseColor[i][3] = tr_val;
2030 } else {
2031 diffuseColor[i][3] = 1.0;
2032 glDisable(GL_BLEND);
2033 }
2034
2035 glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, &diffuseColor[i][0]);
2036 glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, ambientColor);
2037 glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, &specularColor[i][0]);
2038 glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, 100);
2039
2040 glCallList(theSurf[i]);
2041
2042 }
2043
2044 glFlush();
2045 glutSwapBuffers();
2046 }
2047
2048 void
outputEPS(int size,int doSort,char * filename)2049 outputEPS(int size, int doSort, char *filename)
2050 {
2051 GLfloat *feedbackBuffer;
2052 GLint returned;
2053 FILE *file;
2054
2055 feedbackBuffer = (GLfloat*) calloc(size, sizeof(GLfloat));
2056 glFeedbackBuffer(size, GL_3D_COLOR, feedbackBuffer);
2057 (void) glRenderMode(GL_FEEDBACK);
2058 glPushMatrix();
2059 dispsf();
2060 glPopMatrix();
2061 returned = glRenderMode(GL_RENDER);
2062 if (filename) {
2063 file = fopen(filename, "w");
2064 if (file) {
2065 spewWireFrameEPS(file, doSort, returned, feedbackBuffer, "rendereps");
2066 } else {
2067 printf("Could not open %s\n", filename);
2068 }
2069 } else {
2070 /* Helps debugging to be able to see the decode feedback
2071 buffer as text. */
2072 printBuffer(returned, feedbackBuffer);
2073 }
2074 free(feedbackBuffer);
2075 }
2076
2077
Reshape(int width,int height)2078 void Reshape(int width, int height)
2079 {
2080
2081 Vsize = width;
2082 if (height > width) Vsize = height;
2083
2084 glViewport(0, 0, Vsize, Vsize);
2085 }
2086
2087
Key(unsigned char key,int x,int y)2088 static void Key( unsigned char key, int x, int y )
2089 {
2090 (void) x;
2091 (void) y;
2092
2093 if (moving) return;
2094
2095 switch (key) {
2096 case 'x':
2097 light0_position[0] += 0.5;
2098 break;
2099 case 'X':
2100 light0_position[0] -= 0.5;
2101 break;
2102 case 'y':
2103 light0_position[1] += 0.5;
2104 break;
2105 case 'Y':
2106 light0_position[1] -= 0.5;
2107 break;
2108 case 'z':
2109 light0_position[2] += 0.5;
2110 break;
2111 case 'Z':
2112 light0_position[2] -= 0.5;
2113 break;
2114 case 'i':
2115 light1_position[0] += 0.5;
2116 break;
2117 case 'I':
2118 light1_position[0] -= 0.5;
2119 break;
2120 case 'j':
2121 light1_position[1] += 0.5;
2122 break;
2123 case 'J':
2124 light1_position[1] -= 0.5;
2125 break;
2126 case 'k':
2127 light1_position[2] += 0.5;
2128 break;
2129 case 'K':
2130 light1_position[2] -= 0.5;
2131 break;
2132 case '<':
2133 case ',':
2134 light2_position[2] += 0.5;
2135 break;
2136 case '>':
2137 case '.':
2138 light2_position[2] -= 0.5;
2139 break;
2140 case 'F':
2141 case 'f':
2142 glutFullScreen();
2143 break;
2144 case 'T':
2145 case 't':
2146 if (TRANS) TRANS = 0;
2147 else TRANS = 1;
2148 break;
2149 case 'P':
2150 case 'p':
2151 if (PERSP) {
2152 PERSP = 0;
2153 if (poszz > 0.0) posz = (1.0 / poszz);
2154 } else {
2155 PERSP = 1;
2156 posz = poszz*-1.85;
2157 }
2158 break;
2159 case '1':
2160 if (l1on) {
2161 l1on = 0;
2162 glDisable(GL_LIGHT0);
2163 } else {
2164 l1on = 1;
2165 glEnable(GL_LIGHT0);
2166 }
2167 break;
2168 case '2':
2169 if (l2on) {
2170 l2on = 0;
2171 glDisable(GL_LIGHT1);
2172 } else {
2173 l2on = 1;
2174 glEnable(GL_LIGHT1);
2175 }
2176 break;
2177 case '3':
2178 if (l3on) {
2179 l3on = 0;
2180 glDisable(GL_LIGHT2);
2181 } else {
2182 l3on = 1;
2183 glEnable(GL_LIGHT2);
2184 }
2185 break;
2186 case '0':
2187 if (DoLights) {
2188 DoLights = 0;
2189 } else {
2190 DoLights = 1;
2191 }
2192 break;
2193 case 27:
2194 exit(0);
2195 break;
2196 case 'M':
2197 case 'm':
2198 if (molon) {
2199 molon = 0;
2200 } else {
2201 molon = 1;
2202 }
2203 break;
2204 case 'N':
2205 case 'n':
2206 CMols++;
2207 if (CMols >= NMols) CMols = 0;
2208 break;
2209 case 'g':
2210 if (DoFog) {
2211 DoFog = 0;
2212 glDisable(GL_FOG);
2213 } else {
2214 DoFog = 1;
2215 glEnable(GL_FOG);
2216 {
2217 GLfloat fogColor[4] = {0.5, 0.5, 0.5, 1.0};
2218
2219 if (ColBG != -1) {
2220 fogColor[0] = clrColor[ColBG][0];
2221 fogColor[1] = clrColor[ColBG][1];
2222 fogColor[2] = clrColor[ColBG][2];
2223 } else {
2224 fogColor[0] = clrColor[bgcol][0];
2225 fogColor[1] = clrColor[bgcol][1];
2226 fogColor[2] = clrColor[bgcol][2];
2227 }
2228 glFogi (GL_FOG_MODE, GL_EXP2);
2229 glFogfv (GL_FOG_COLOR, fogColor);
2230 glFogf (GL_FOG_DENSITY, 0.03);
2231 glHint (GL_FOG_HINT, GL_DONT_CARE);
2232 glFogf (GL_FOG_START, posz);
2233 glFogf (GL_FOG_END, posz+5);
2234 }
2235 }
2236 break;
2237 }
2238 angincr1 = 0.0;
2239 angincr2 = 0.0;
2240 glutPostRedisplay();
2241 }
2242
SpecialKey(int key,int x,int y)2243 static void SpecialKey( int key, int x, int y )
2244 {
2245 (void) x;
2246 (void) y;
2247
2248 if (moving) return;
2249
2250 switch (key) {
2251 case GLUT_KEY_LEFT:
2252 yrot -= ROTINCR;
2253 break;
2254 case GLUT_KEY_RIGHT:
2255 yrot += ROTINCR;
2256 break;
2257 case GLUT_KEY_UP:
2258 xrot += ROTINCR;
2259 break;
2260 case GLUT_KEY_DOWN:
2261 xrot -= ROTINCR;
2262 break;
2263 case GLUT_KEY_F9:
2264 save_bmp();
2265 break;
2266 case GLUT_KEY_F10:
2267 save_rgb(rgbfile);
2268 break;
2269 case GLUT_KEY_F11:
2270 save_ps(1);
2271 break;
2272 case GLUT_KEY_F12:
2273 save_pixmap(ppmfile);
2274 break;
2275 case GLUT_KEY_PAGE_UP:
2276 fdens += 0.001;
2277 glFogf (GL_FOG_DENSITY, fdens);
2278 break;
2279 case GLUT_KEY_PAGE_DOWN:
2280 fdens -= 0.001;
2281 glFogf (GL_FOG_DENSITY, fdens);
2282 break;
2283 default:
2284 return;
2285 }
2286 angincr1 = 0.0;
2287 angincr2 = 0.0;
2288 dispsf();
2289 glutPostRedisplay();
2290 }
2291
2292 static void
motion(int x,int y)2293 motion(int x, int y)
2294 {
2295 int i;
2296 if (moving) {
2297 moving = 0;
2298 ang1 = ang1 + (x - startx);
2299 ang2 = ang2 + (y - starty);
2300 /*
2301 angincr1 = (double) (x - startx) ;
2302 angincr2 = (double) (y - starty) ;
2303 */
2304 for (i=0; i < HISTMAX-1; i++) AngIncrHist1[i] = AngIncrHist1[i+1];
2305 for (i=0; i < HISTMAX-1; i++) AngIncrHist2[i] = AngIncrHist2[i+1];
2306 AngIncrHist1[HISTMAX-1] = (double) (x - startx) ;
2307 AngIncrHist2[HISTMAX-1] = (double) (y - starty) ;
2308 angincr1 = 0.0;
2309 for (i=0; i < HISTMAX-1; i++) angincr1 = angincr1 + AngIncrHist1[i];
2310 angincr1 = MULTH * angincr1 / (double) HISTMAX;
2311 angincr2 = 0.0;
2312 for (i=0; i < HISTMAX-1; i++) angincr2 = angincr2 + AngIncrHist2[i];
2313 angincr2 = MULTH * angincr2 / (double) HISTMAX;
2314
2315 startx = x;
2316 starty = y;
2317 glutPostRedisplay();
2318 moving = 1;
2319 }
2320 if (mmoving) {
2321 posx = posx + (x - mstartx) / 600.0;
2322 posy = posy - (y - mstarty) / 600.0;
2323 mstartx = x;
2324 mstarty = y;
2325 angincr1 = 0.0;
2326 angincr2 = 0.0;
2327 glutPostRedisplay();
2328 }
2329 if (smoving) {
2330 posz = posz - (y - sstarty) / 60.0;
2331 if (posz < 0.005 && !PERSP) posz = 0.005;
2332 sstarty = y;
2333 angincr1 = 0.0;
2334 angincr2 = 0.0;
2335 glutPostRedisplay();
2336 }
2337 }
2338
2339 static void
mouse(int button,int state,int x,int y)2340 mouse(int button, int state, int x, int y)
2341 {
2342 int modf;
2343
2344 if (button == GLUT_LEFT_BUTTON) {
2345 if (state == GLUT_DOWN) {
2346 modf = glutGetModifiers();
2347 if (modf & GLUT_ACTIVE_SHIFT) {
2348 mmoving = 1;
2349 mstartx = x;
2350 mstarty = y;
2351 } else if (modf & GLUT_ACTIVE_CTRL) {
2352 smoving = 1;
2353 sstarty = y;
2354 } else {
2355 moving = 1;
2356 startx = x;
2357 starty = y;
2358 }
2359 }
2360 if (state == GLUT_UP) {
2361 moving = 0;
2362 mmoving = 0;
2363 smoving = 0;
2364 }
2365 }
2366 }
2367
menu_select(int iopt)2368 void menu_select(int iopt)
2369 {
2370 switch (iopt) {
2371 case 1:
2372 molon = 0;
2373 break;
2374 case 2:
2375 molon = 1;
2376 break;
2377 case 3:
2378 if (TRANS) TRANS = 0;
2379 else TRANS = 1;
2380 break;
2381 case 4:
2382 if (PERSP) {
2383 PERSP = 0;
2384 if (poszz > 0.0) posz = (1.0 / poszz);
2385 } else {
2386 PERSP = 1;
2387 posz = poszz*-1.85;
2388 }
2389 break;
2390 case 5:
2391 if (l1on) {
2392 l1on = 0;
2393 glDisable(GL_LIGHT0);
2394 } else {
2395 l1on = 1;
2396 glEnable(GL_LIGHT0);
2397 }
2398 break;
2399 case 6:
2400 if (l2on) {
2401 l2on = 0;
2402 glDisable(GL_LIGHT1);
2403 } else {
2404 l2on = 1;
2405 glEnable(GL_LIGHT1);
2406 }
2407 break;
2408 case 7:
2409 if (l3on) {
2410 l3on = 0;
2411 glDisable(GL_LIGHT2);
2412 } else {
2413 l3on = 1;
2414 glEnable(GL_LIGHT2);
2415 }
2416 break;
2417 case 8:
2418 glutFullScreen();
2419 break;
2420 case 9:
2421 if (DoLines) DoLines = 0;
2422 else DoLines = 1;
2423 break;
2424 case 10:
2425 if (AutoRot) AutoRot = 0;
2426 else {
2427 AutoRot = 1;
2428 angincr2 = 0.0;
2429 glutPostRedisplay();
2430 return;
2431 }
2432 break;
2433 case 11:
2434 exit(0);
2435 break;
2436 }
2437
2438 angincr1 = 0.0;
2439 angincr2 = 0.0;
2440 glutPostRedisplay();
2441 }
2442
bg_select(int iopt)2443 void bg_select(int iopt)
2444 {
2445
2446 ColBG = iopt;
2447 glClearColor(clrColor[iopt][0],clrColor[iopt][1],clrColor[iopt][2],
2448 clrColor[iopt][3]);
2449 glutPostRedisplay();
2450 }
2451
anim_select(int iopt)2452 void anim_select(int iopt)
2453 {
2454
2455 switch (iopt) {
2456 case 1:
2457 if (Anim) Anim = 0;
2458 else Anim = 1;
2459 break;
2460 case 2:
2461 CMols++;
2462 if (CMols >= NMols) CMols = 0;
2463 break;
2464 case 3:
2465 AnimSlow = 0;
2466 AnimCount = 0;
2467 break;
2468 case 4:
2469 AnimSlow = 2;
2470 AnimCount = 2;
2471 break;
2472 case 5:
2473 AnimSlow = 5;
2474 AnimCount = 5;
2475 break;
2476 case 6:
2477 AnimSlow = 10;
2478 AnimCount = 10;
2479 break;
2480 }
2481 glutPostRedisplay();
2482 }
2483
capture_select(int iopt)2484 void capture_select(int iopt)
2485 {
2486
2487 switch (iopt) {
2488 case 1:
2489 save_bmp();
2490 break;
2491 case 2:
2492 save_rgb(rgbfile);
2493 break;
2494 case 3:
2495 save_ps(1);
2496 break;
2497 case 4:
2498 glutSetCursor(GLUT_CURSOR_WAIT);
2499 #ifdef WIN32
2500 outputEPS(objectComplexity, 1, "mogl.ps");
2501 #else
2502 outputEPS(objectComplexity, 1, "moldenogl.ps");
2503 #endif
2504 glutSetCursor(GLUT_CURSOR_INHERIT);
2505 break;
2506 case 5:
2507 save_pixmap(ppmfile);
2508 break;
2509 case 6:
2510 if (DoCap) DoCap = 0;
2511 else DoCap = 1;
2512 break;
2513 }
2514 glutPostRedisplay();
2515 }
2516
2517 #if defined(VMS) || defined(UNDERSC)
initog(int * ofil)2518 void initog(int *ofil)
2519 #else
2520 #ifdef CRAY
2521 void INITOG(int *ofil)
2522 #else
2523 void initog_(int *ofil)
2524 #endif
2525 #endif
2526
2527 {
2528
2529 int i,bgmenu,animmenu,capmenu;
2530
2531 static float lmodel_ambient[] = {0.1, 0.1, 0.1, 0.1};
2532 static float lmodel_twoside[] = {GL_TRUE};
2533 static float lmodel_local[] = {GL_FALSE};
2534 static float light0_ambient[] = {0.1, 0.1, 0.1, 1.0};
2535 static float light0_diffuse[] = {1.0, 1.0, 1.0, 0.0};
2536 static float light0_specular[] = {1.0, 1.0, 1.0, 0.0};
2537 static float light1_ambient[] = {0.1, 0.1, 0.1, 1.0};
2538 static float light1_diffuse[] = {1.0, 1.0, 1.0, 1.0};
2539 static float light1_specular[] = {1.0, 1.0, 1.0, 0.0};
2540 static float light2_ambient[] = {0.3, 0.3, 0.3, 1.0};
2541 static float light2_diffuse[] = {1.0, 1.0, 1.0, 1.0};
2542 static float light2_specular[] = {1.0, 1.0, 1.0, 0.0};
2543 int argc = 2;
2544 #ifdef WIN32
2545 char *argv[] = {"mogl","yes"};
2546 #else
2547 char *argv[] = {"moldenogl","yes"};
2548 #endif
2549
2550 if (*ofil) {
2551 out = fopen("molden.ogl","w");
2552
2553 if (out != NULL) {
2554 dowrt = 1;
2555 } else {
2556 dowrt = 0;
2557 }
2558 } else {
2559 dowrt = 0;
2560 }
2561
2562 if (dowrt) fprintf(out,"[MOLDENOGL]\n");
2563
2564 #ifdef __CYGWIN__
2565 if (getenv("DISPLAY") == NULL) putenv("DISPLAY=localhost:0.0");
2566 #endif
2567 glutInit(&argc, argv);
2568
2569 glutInitWindowSize( width, height);
2570
2571 glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH );
2572
2573 if (glutCreateWindow("Molden") == GL_FALSE) {
2574 exit(1);
2575 }
2576
2577 glutReshapeFunc(Reshape);
2578 glutSpecialFunc(SpecialKey);
2579 glutKeyboardFunc(Key);
2580 glutDisplayFunc(dispsf);
2581 glutMotionFunc(motion);
2582 glutMouseFunc(mouse);
2583 glutIdleFunc(idle);
2584
2585 bgmenu = glutCreateMenu(bg_select);
2586 for (i=0;i<Nclr;i++) glutAddMenuEntry(clrNames[i],i);
2587
2588 animmenu = glutCreateMenu(anim_select);
2589
2590 glutAddMenuEntry("Animation On/Off", 1);
2591 glutAddMenuEntry("Next Point [n]", 2);
2592 glutAddMenuEntry("Dont Slow Down", 3);
2593 glutAddMenuEntry("Slow Down Factor 2", 4);
2594 glutAddMenuEntry("Slow Down Factor 5", 5);
2595 glutAddMenuEntry("Slow Down Factor 10", 6);
2596
2597 capmenu = glutCreateMenu(capture_select);
2598 glutAddMenuEntry("BMP Pixmap [F9]", 1);
2599 glutAddMenuEntry("IRIS RGB format [F10]", 2);
2600 glutAddMenuEntry("Postscript [F11]", 3);
2601 glutAddMenuEntry("Vector Postscript", 4);
2602 glutAddMenuEntry("PPM Pixmap [F12]", 5);
2603 glutAddMenuEntry("RGB file each update", 6);
2604
2605 glutCreateMenu(menu_select);
2606 glutAddSubMenu("BackGround Color",bgmenu);
2607 glutAddSubMenu("Animation",animmenu);
2608 glutAddSubMenu("Screen Capture",capmenu);
2609 glutAddMenuEntry("Molecule Off", 1);
2610 glutAddMenuEntry("Molecule On", 2);
2611 glutAddMenuEntry("Transparency Toggle", 3);
2612 glutAddMenuEntry("Perspective Toggle", 4);
2613 glutAddMenuEntry("Light1 Toggle", 5);
2614 glutAddMenuEntry("Light2 Toggle", 6);
2615 glutAddMenuEntry("Light3 Toggle", 7);
2616 glutAddMenuEntry("Fullscreen", 8);
2617 glutAddMenuEntry("SurfLines Toggle", 9);
2618 glutAddMenuEntry("Auto Rotate", 10);
2619 glutAddMenuEntry("Quit", 11);
2620
2621 glutAttachMenu(GLUT_RIGHT_BUTTON);
2622
2623 glMatrixMode(GL_MODELVIEW);
2624 glLoadIdentity();
2625
2626 if (RotType) {
2627 glPushMatrix();
2628 glLoadMatrixd((const GLdouble *) RR);
2629 glRotatef( ang2, 1.0, 0.0, 0.0 );
2630 glRotatef( ang1, 0.0, 0.0, 1.0 );
2631 glGetDoublev(GL_MODELVIEW_MATRIX,(GLdouble *) RR);
2632 glPopMatrix();
2633 }
2634
2635 glEnable(GL_DEPTH_TEST);
2636
2637 if (l1on) glEnable(GL_LIGHT0);
2638 else glDisable(GL_LIGHT0);
2639 if (l2on) glEnable(GL_LIGHT1);
2640 else glDisable(GL_LIGHT1);
2641 if (l3on) glEnable(GL_LIGHT2);
2642 else glDisable(GL_LIGHT2);
2643
2644 glLightfv(GL_LIGHT0, GL_AMBIENT, light0_ambient);
2645 glLightfv(GL_LIGHT0, GL_DIFFUSE, light0_diffuse);
2646 glLightfv(GL_LIGHT0, GL_SPECULAR, light0_specular);
2647 glLightfv(GL_LIGHT0, GL_POSITION, light0_position);
2648
2649 glLightfv(GL_LIGHT1, GL_AMBIENT, light1_ambient);
2650 glLightfv(GL_LIGHT1, GL_DIFFUSE, light1_diffuse);
2651 glLightfv(GL_LIGHT1, GL_SPECULAR, light1_specular);
2652 glLightfv(GL_LIGHT1, GL_POSITION, light1_position);
2653
2654 glLightfv(GL_LIGHT2, GL_AMBIENT, light2_ambient);
2655 glLightfv(GL_LIGHT2, GL_DIFFUSE, light2_diffuse);
2656 glLightfv(GL_LIGHT2, GL_SPECULAR, light2_specular);
2657 glLightfv(GL_LIGHT2, GL_POSITION, light2_position);
2658
2659 glLightModelfv(GL_LIGHT_MODEL_LOCAL_VIEWER, lmodel_local);
2660 glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE, lmodel_twoside);
2661 glLightModelfv(GL_LIGHT_MODEL_AMBIENT, lmodel_ambient);
2662 glEnable(GL_LIGHTING);
2663
2664 glEnable(GL_NORMALIZE);
2665 glShadeModel(GL_SMOOTH);
2666 glLineWidth(1.5);
2667 glClearColor(clrColor[bgcol][0],clrColor[bgcol][1],clrColor[bgcol][2],
2668 clrColor[bgcol][3]);
2669 PERSP = perspon;
2670 glClearIndex(0);
2671 glClearDepth(1);
2672
2673 glPushMatrix();
2674 glLoadIdentity();
2675
2676 cyl = gluNewQuadric();
2677 sphere = gluNewQuadric();
2678
2679 }
2680
2681 #if defined(VMS) || defined(UNDERSC)
oginid(double * r,double * adjus,int * natoms,int * nat,int * icol,double * xsym,double * ysym,double * zsym,double * vdwr,double * cnst,int * nnpts1,int * nnpts2,double * dens)2682 void oginid(double *r, double *adjus, int *natoms, int *nat, int *icol,
2683 #else
2684 #ifdef CRAY
2685 void OGINID(double *r, double *adjus, int *natoms, int *nat, int *icol,
2686 #else
2687 void oginid_(double *r, double *adjus, int *natoms, int *nat, int *icol,
2688 #endif
2689 #endif
2690 double *xsym, double *ysym, double *zsym, double *vdwr,
2691 double *cnst, int *nnpts1, int *nnpts2, double *dens)
2692 {
2693 int mopt;
2694
2695 mopt = 0;
2696 ogmol(r,adjus,natoms,nat,NULL,icol,xsym,ysym,zsym,vdwr,&mopt,NULL,NULL,NULL);
2697 BuildList(r,cnst,nnpts1,nnpts2,dens);
2698
2699 NSurf++;
2700 NMols++;
2701 glutMainLoop();
2702
2703 }
2704
2705 #if defined(VMS) || defined(UNDERSC)
oginsp(double * r,double * adjus,int * natoms,int * nat,int * iatclr,int * icol,double * xsym,double * ysym,double * zsym,double * vdwr,int * mopt,int * conn,int * nconn,int * iconn,int * ofil)2706 void oginsp(double *r, double *adjus, int *natoms, int *nat, int *iatclr, int *icol,
2707 #else
2708 #ifdef CRAY
2709 void OGINSP(double *r, double *adjus, int *natoms, int *nat, int *iatclr, int *icol,
2710 #else
2711 void oginsp_(double *r, double *adjus, int *natoms, int *nat, int *iatclr, int *icol,
2712 #endif
2713 #endif
2714 double *xsym, double *ysym, double *zsym, double *vdwr,
2715 int *mopt, int *conn, int *nconn, int *iconn, int *ofil)
2716 {
2717
2718
2719 AmbAndDiff = 0;
2720 ogmol(r,adjus,natoms,nat,iatclr,icol,xsym,ysym,zsym,vdwr,mopt,conn,nconn,iconn);
2721
2722 }
2723
2724 #if defined(VMS) || defined(UNDERSC)
ogspst()2725 void ogspst()
2726 #else
2727 #ifdef CRAY
2728 void OGSPST()
2729 #else
2730 void ogspst_()
2731 #endif
2732 #endif
2733 {
2734
2735 if (dowrt) fclose(out);
2736
2737 NSurf++;
2738 NMols++;
2739
2740 if (perspon) {
2741 posz = poszz*-1.85;
2742 light2_position[2] = poszz*2.5;
2743 } else {
2744 if (poszz > 0.0) {
2745 posz = (1.0 / poszz);
2746 light2_position[2] = posz;
2747 }
2748 }
2749 glutMainLoop();
2750 }
2751
2752
2753