#include /* replaces 5 pager in GUIDE sec 9.2.1 */ #include /* MOUSEX MOUSEY */ #include /* fcos fsin */ #include /* NULL would you believe */ #define DG .01745 #define SSTEP 15 int step, t = 1, dtime; Matrix id = {1.,0.,0.,0., 0.,1.,0.,0., 0.,0.,1.,0., 0.,0.,0.,1.}; float vv[3],nn[3]; float white[]={ DIFFUSE, 0.4, 0.4, 0.4, /* MATERIAL list */ SPECULAR,0.0,0.0,0.0, LMNULL}; float plain[] = {DIFFUSE, 1.0, 0.8, 0.0, SPECULAR, 1.0, 1.0, 1.0, SHININESS, 100.0, LMNULL}; float moon[] ={ LCOLOR, 1.0, 1.0, 1.0, /* LIGHT list */ POSITION, 1.0, 0.0, 0.3, 0.0, AMBIENT, 0.1, 0.1, 0.1, LMNULL}; float satmat[] = {DIFFUSE, 0.5, 0.0, 0.0, SPECULAR, 0.5, 0.5, 0.5, SHININESS, 128.0, EMISSION, 0.4, 0.0, 0.0, AMBIENT, 0.0, 0.0, 0.0, LMNULL}; lightit(spec, shine) float spec, shine; { plain[5] = plain[6] = plain[7] = spec; plain[9] = shine; lmdef(DEFMATERIAL,1,11,plain); lmdef(DEFMATERIAL,2,19,satmat); lmdef(DEFLIGHT,1,14,moon); lmdef(DEFLMODEL,1,0,NULL); /* #1 atmosphere is default */ } bindall() { bindmaterial(); bindlight(); bindmodel(); } bindmodel() { lmbind(LMODEL,1); } bindmaterial() { lmbind(MATERIAL,1); /* ? to be explained */ } bindlight(i) int i; { lmbind(LIGHT0,1); lmbind(LIGHT1,i); } hair(th,ta) int th,ta;{ float fth,fta; /* sphere normals are easy */ fth = DG * (float)th; fta = DG * (float)ta; vv[0] = fcos(fth)*(1. + 0.5*fcos(fta)); vv[1] = fsin(fth)*(1. + 0.5*fcos(fta)); vv[2] = 0.5*fsin(fta); nn[0] = fcos(fth)*fcos(fta); nn[1] = fsin(fth)*fcos(fta); nn[2] = fsin(fta); } drawit() { int th,ta; for(th=0;th<=360;th +=step){ bgntmesh(); for(ta= (0); ta<=380; ta +=step){ hair(th,ta); n3f(nn); v3f(vv); hair(th+step,ta); n3f(nn); v3f(vv); } endtmesh(); } } orbit() { int th,ta; float posy, posz; posy = 1 + fsin(DG * t * dtime); posz = fcos(DG * t * dtime); for(th = 0; th <= 360; th += SSTEP){ bgntmesh(); for(ta = -90; ta <= 90; ta += SSTEP){ sphere(posy, posz, 0.1, th,ta); n3f(nn); v3f(vv); sphere(posy, posz, 0.1, th + SSTEP,ta); n3f(nn); v3f(vv); } endtmesh(); } } sphere(py, pz, r, th, ta) float py, pz, r; int th, ta; { float fth, fta; fth = DG * (float)th; fta = DG * (float)ta; vv[0] = r * fcos(fth)*fcos(fta); vv[1] = py + r * fsin(fth)*fcos(fta); vv[2] = pz + r * fsin(fta); nn[0] = fcos(fth)*fcos(fta); nn[1] = fsin(fth)*fcos(fta); nn[2] = fsin(fta); } float orbitl[] = {LCOLOR, 0.4, 0.0, 0.0, POSITION, 0.0, 0.0, 0.0, 1.0, LMNULL}; deforbits(dtime) int dtime; { int i,increments; float posy,posz; increments = (int)360/dtime; for(i = 1; i <= increments; i++){ posy = 1 + fsin(DG * i * dtime); posz = fcos(DG * i * dtime); orbitl[6] = posy; orbitl[7] = posz; lmdef(DEFLIGHT, i+1, 10, orbitl); } } main(argc, argv) int argc; char **argv; { /* if (argc != 5){ printf("enter spec reflectance (sp) shininess (sp) step size (sp) orbit step\n"); printf("example: ltor2 1.0 128.0 10 20 \n"); exit(0); } no more command liners*/ /* step = atoi(argv[3]); dtime = atoi(argv[4]); */ step = 10; dtime = 10; keepaspect(1,1); /*new style, corrected gkf 4dec94 */ winopen("light"); doublebuffer(); RGBmode(); gconfig(); lsetdepth(0, 0x7FFFFF); zbuffer(1); mmode(MVIEWING); deforbits(dtime); /* lightit(atof(argv[1]), atof(argv[2])); was */ lightit(.7, 80.0); bindmaterial(); bindmodel(); perspective(900, 1.0, 0.1, 100.0); while(1) { reshapeviewport(); /* added 21mar08 gkf */ loadmatrix(id); polarview(4.0, getvaluator(MOUSEX)*4, getvaluator(MOUSEY)*4, 0); if(t >= (int)360/dtime) t = 1; else t++; bindlight(t + 1); cpack(0); clear(); zclear(); lmbind(MATERIAL,1); drawit(); lmbind(MATERIAL,2); orbit(); swapbuffers(); } }