home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright 1992, 1993, 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
-
- /* Tom Davis -- 1992 */
-
- /* draw worm */
-
- #include <stdio.h>
- #include <math.h>
- #include <gl.h>
- #include <device.h>
- #include "3d.h"
-
- #define PI 3.1415926535
- #define EPSILON .0001
-
- #define SSTEPS 400
- #define NORMFACTOR 80.0
-
- void drawsurface();
-
- float blackvec[3] = {0.0, 0.0, 0.0};
- static float idmat[4][4] = {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};
-
- float shiny_material[] = {SPECULAR, 0.8, 0.8, 0.8,
- DIFFUSE, 0.4, 0.4, 0.4,
- SHININESS, 30.0,
- LMNULL};
-
- float purple_material[] = {SPECULAR, 0.3, 0.3, 0.3,
- DIFFUSE, 0.8, 0.0, 0.8,
- SHININESS,5.0,
- AMBIENT, 0.2, 0.0, 0.2,
- LMNULL};
-
- float material1[] = {SPECULAR, 0.3, 0.3, 0.3,
- DIFFUSE, 0.8, 0.0, 0.8,
- SHININESS,5.0,
- LMNULL};
-
- float material2[] = {SPECULAR, 0.3, 0.3, 0.8,
- DIFFUSE, 0.0, 0.0, 0.8,
- SHININESS,2.0,
- AMBIENT, 0.2, 0.0, 0.2,
- LMNULL};
-
- float material3[] = {SPECULAR, 0.3, 0.3, 0.3,
- DIFFUSE, 0.8, 0.0, 0.0,
- SHININESS,50.0,
- AMBIENT, 0.2, 0.0, 0.0,
- LMNULL};
-
- float material4[] = {SPECULAR, 0.3, 0.3, 0.3,
- DIFFUSE, 0.0, 0.8, 0.8,
- SHININESS,5.0,
- LMNULL};
-
- float blue_light[] = {LCOLOR, 0.0, 0.0, 0.6,
- POSITION, 0.0, 1.0, 0.0, 0.0,
- LMNULL};
-
- void drawworld()
- {
- c3f(blackvec);
- clear();
- zclear();
- drawsurface();
- }
-
- /*
- ** Tell the Graphics Library to DEFINE a simple lighting model
- ** that accounts for diffuse and ambient reflection. This simple
- ** lighting model happens to be the default lighting model for
- ** the Graphics Library.
- */
- def_simple_light_model()
-
- {
- lmdef(DEFLMODEL, 1, 0, NULL);
- lmdef(DEFMATERIAL, 1, 11, shiny_material);
- lmdef(DEFMATERIAL, 2, 15, purple_material);
- lmdef(DEFMATERIAL, 3, 11, material1);
- lmdef(DEFMATERIAL, 4, 15, material2);
- lmdef(DEFMATERIAL, 5, 15, material3);
- lmdef(DEFMATERIAL, 6, 11, material4);
- lmdef(DEFLIGHT, 1, 0, NULL);
- lmdef(DEFLIGHT, 2, 10, blue_light);
- }
-
- /*
- ** Tell the Graphics Library to USE the simple lighting model
- ** that we defined earlier.
- */
- use_simple_light_model()
-
- {
- lmbind(LMODEL, 1);
- lmbind(LIGHT0, 1);
- lmbind(LIGHT1, 2);
- }
-
- float vectlist[200000][3];
- float normlist[200000][3];
- long vcount = 0;
-
- float trilist[100000][3];
- float trinorm[100000][3];
- long tcount;
-
- void savefunc(type, n0, v0, n1, v1, n2, v2, n3, v3)
- long type;
- float *n0, *n1, *n2, *n3, *v0, *v1, *v2, *v3;
- {
- if (type == ADD_QUAD) {
- if (vcount > 200000) {
- fprintf(stderr, "too many points\n");
- exit();
- }
- copy3(n0, &normlist[vcount][0]);
- copy3(v0, &vectlist[vcount++][0]);
- copy3(n1, &normlist[vcount][0]);
- copy3(v1, &vectlist[vcount++][0]);
- copy3(n2, &normlist[vcount][0]);
- copy3(v2, &vectlist[vcount++][0]);
- copy3(n3, &normlist[vcount][0]);
- copy3(v3, &vectlist[vcount++][0]);
- } else {
- if (tcount > 100000) {
- fprintf(stderr, "too many points\n");
- exit();
- }
- copy3(n0, &trinorm[tcount][0]);
- copy3(v0, &trilist[tcount++][0]);
- copy3(n1, &trinorm[tcount][0]);
- copy3(v1, &trilist[tcount++][0]);
- copy3(n2, &trinorm[tcount][0]);
- copy3(v2, &trilist[tcount++][0]);
- }
- }
-
- void drawsurface()
- {
- long i;
-
- for (i = 0; i < vcount;) {
- bgnpolygon();
- n3f(&normlist[i][0]);
- v3f(&vectlist[i++][0]);
- n3f(&normlist[i][0]);
- v3f(&vectlist[i++][0]);
- n3f(&normlist[i][0]);
- v3f(&vectlist[i++][0]);
- n3f(&normlist[i][0]);
- v3f(&vectlist[i++][0]);
- endpolygon();
- }
- for (i = 0; i < tcount;) {
- bgnpolygon();
- n3f(&trinorm[i][0]);
- v3f(&trilist[i++][0]);
- n3f(&trinorm[i][0]);
- v3f(&trilist[i++][0]);
- n3f(&trinorm[i][0]);
- v3f(&trilist[i++][0]);
- endpolygon();
- }
- }
- #ifdef NOTDEF
- #define R 3
- #define r .7
-
- float x(float s, float t)
- {
- return cos(s)*(R+r*cos(t));
- }
-
- float y(float s, float t)
- {
- return sin(s)*(R+r*cos(t));
- }
-
- float z(float s, float t)
- {
- return r*sin(t);
- }
-
- float xs(float s, float t)
- {
- return -sin(s)*(R+r*cos(t));
- }
-
- float ys(float s, float t)
- {
- return cos(s)*(R+r*cos(t));
- }
-
- float zs(float s, float t)
- {
- return 0.0;
- }
-
- float xt(float s, float t)
- {
- return -cos(s)*(r*sin(t));
- }
-
- float yt(float s, float t)
- {
- return -sin(s)*(r*sin(t));
- }
-
- float zt(float s, float t)
- {
- return r*cos(t);
- }
- #endif /* NOTDEF */
-
- float x(float s, float t)
- {
- return s;
- }
-
- float y(float s, float t)
- {
- return t;
- }
-
- float z(float s, float t)
- {
- return cos(1.5*(s*s+t*t));
- }
-
- float xs(float s, float t)
- {
- return 1.0;
- }
-
- float ys(float s, float t)
- {
- return 0.0;
- }
-
- float zs(float s, float t)
- {
- return -3.0*s*sin(1.5*(s*s+t*t));
- }
-
- float xt(float s, float t)
- {
- return 0.0;
- }
-
- float yt(float s, float t)
- {
- return 1.0;
- }
-
- float zt(float s, float t)
- {
- return -3.0*t*sin(1.5*(s*s+t*t));
- }
-
- float al = 3.0;
- #ifdef NOTDEF
- float x(float s, float t)
- {
- return 3*s;
- }
-
- float y(float s, float t)
- {
- return 3*t;
- }
-
- float z(float s, float t)
- {
- float u;
- s = fabs(s); t = fabs(t);
- u = 1.0 - pow(s, al) - pow(t, al);
- if (u <= 0.0) return 0.0;
- return 3*pow(u, 1/al);
- }
-
- float xs(float s, float t)
- {
- return 1.0;
- }
-
- float ys(float s, float t)
- {
- return 0.0;
- }
-
- float zs(float s, float t)
- {
- float u;
- s = fabs(s); t = fabs(t);
- u = 1.0 - pow(s, al) - pow(t, al);
- if (u <= 0.0) return 0.0;
- return -pow(u, 1/al-1)*pow(s, al-1);
- }
-
- float xt(float s, float t)
- {
- return 0.0;
- }
-
- float yt(float s, float t)
- {
- return 1.0;
- }
-
- float zt(float s, float t)
- {
- float u;
- s = fabs(s); t = fabs(t);
- u = 1.0 - pow(s, al) - pow(t, al);
- if (u <= 0.0) return 0.0;
- return -pow(u, 1/al-1)*pow(t, al-1);
- }
- #endif
-
- float zero[3] = {0.0, 0.0, 0.0};
- float one[3] = {1.0, 1.0, 1.0};
- float minusone[3] = {-1.0, -1.0, -1.0};
-
- main(argc, argv)
- int argc;
- char **argv;
- {
- long i=0, j=0;
- curve_t *c;
- float theta, t1, t2, t3;
- if (argc == 2) al = atof(argv[1]);
- /* surface */
- analyticsurface(x, y, z, xs, ys, zs, xt, yt, zt,
- 100, -3, 3,
- 100, -3, 3, 0, savefunc);
- keepaspect(1, 1);
- foreground();
- winopen("worm");
- backface(1);
- RGBmode();
- doublebuffer();
- zbuffer(TRUE);
- gconfig();
- mmode(MVIEWING);
- perspective(450, 1.0, 1.0, 1000.0);
- def_simple_light_model();
- use_simple_light_model();
- lmbind(MATERIAL, 6);
- trackmodel(drawworld, 15.0, 0.8, -0.8, 0.8);
- }
-