/* * makesphere * * make a sphere object */ makesphere() { float r, z; int i, a; makeobj(SPHERE); /* * create the latitudinal rings */ for (i = 0; i < 1800; i += 200) { pushmatrix(); rotate(i, 'y'); circ(0.0, 0.0, RADIUS); popmatrix(); } /* * create the longitudinal rings */ pushmatrix(); rotate(900, 'x'); for (a = -900; a < 900; a += 200) { r = RADIUS * cos((double)a * PI / 180.0); z = RADIUS * sin((double)a * PI / 180.0); pushmatrix(); translate(0.0, 0.0, -z); circ(0.0, 0.0, r); popmatrix(); } popmatrix(); closeobj(); }
main() { char device[10], *p; float x, y, tdir = TRANS; int but, nplanes; int i, n; char buf[10][128]; fprintf(stderr,"Enter output device: "); gets(device); prefposition(50, 50); vinit(device); window(-800.0, 800.0, -800.0, 800.0, -800.0, 800.0); lookat(0.0, 0.0, 1500.0, 0.0, 0.0, 0.0, 0.0); makeobj(1); makepoly(); rect(-CUBE_SIZE, -CUBE_SIZE, CUBE_SIZE, CUBE_SIZE); closepoly(); closeobj(); if ((nplanes = getdepth()) == 1) makecubes(0); makecubes(1); backface(1); if (backbuffer() < 0) { vexit(); fprintf(stderr, "lcube: device doesn't support double buffering.\n"); exit(0); } while((but = slocator(&x, &y)) != 44) { pushmatrix(); rotate(100.0 * x, 'y'); rotate(100.0 * y, 'x'); color(BLACK); clear(); callobj(3); if (nplanes == 1) callobj(2); popmatrix(); swapbuffers(); switch (but = checkkey()) { case 'x': translate(tdir, 0.0, 0.0); break; case 'y': translate(0.0, tdir, 0.0); break; case 'z': translate(0.0, 0.0, tdir); break; case '-': tdir = -tdir; break; case '+': tdir = TRANS; break; case 27: /* ESC */ case 'q': vexit(); exit(0); default: ; } } vexit(); }