// new dawn and szg-1.1 11jun07 // put in SLevy's dawn() after drawall() has stereo but no stars. 3jun07 // how to fix the fleeing at startup? doesn't do it in simulator or CANVAS // possibly put start with gesture=0 instead of 1 (tumble) // Portal 03may07 GF //venus 6mar06 //museum mode 5mar06 // esopus szg0.7 27feb06 /* gesture tracking in, gkf: on 5jun04 */ /*2jun: remove the other 2 jokers. Handtracking only in gesturetrack */ /*joker controlled but Euclidean gesturetrack working as of 1jun04 */ /* autotymer and paintor now work but here remain many mysteries about the arMSF syntax */ /* sidestep a problem with the syntx for armaslav */ /****************************************************************/ /**** skel.c = OpenSkelGlut.c = Noosh97 with CAVE removed ****/ /**** (C) 1994 Board of Trustees University of Illinois ****/ /**** A Model Real-Time Interactive OpenGL Application ****/ /**** George Francis, Glenn Chappell, Chris Hartman ****/ /**** e-mail gfrancis@math.uiuc.edu ****/ /******* revised 16jan2K by gkf**********************************/ /****************************************************************/ #include "arPrecompiled.h" //must be the first line #include "arMasterSlaveFramework.h" #include //gkf 11jun07 #define DLIMA .1 #define DROMBOY .1 #define DT 0.001 #define KK .9 //kludge factor in the denominator #define WAIST .8 #define GOVERNOR 5 #define UNIX //#define WIN32 /****************************************************************/ #include #include #include #ifdef WIN32 #include /* for windows */ #define random rand #endif #ifdef UNIX #include /* for unix */ #endif #define MAX(x,y) (((x)<(y))?(y):(x)) #define MIN(x,y) (((x)<(y))?(x):(y)) #define ABS(u) ((u)<0 ? -(u): (u)) #define FOR(a,b,c) for((a)=(b);(a)<(c);(a)++) #define DOT(p,q) ((p)[0]*(q)[0]+(p)[1]*(q)[1]+(p)[2]*(q)[2]) #define NRM(p) sqrt(DOT((p),(p))) #define DG M_PI/180 #define S(u) sin(u*DG) #define C(u) cos(u*DG) #define CLAMP(x,u,v) (xv ? v: x)) /* global variables */ float gap, gap0=.9; /* kludge so that arguments() can set a default gap0 */ float lux[3]={1.,2.,3.}; /*world light direction vector */ float luxx[3]; /* object space direction vector*/ float amb, pwr ; /* ambient fraction, pseudo-specular power */ float mysiz,speed, torq, focal, wfar; /*console navigation variables */ int win = 1; /* 2 full screen, use 0 for demand sized */ unsigned int BUT, XX, YY,SHIF; /* used in chaptrack gluttery */ int xt,yt; /* once was xt,yt,xm,ym for viewportery */ int mode,morph,msg,binoc; /* pretty global */ int sizz; //from siz, and caveyes in CAVEskels enum {console, cave, cube} eyes; int gesture; float eps; float del ; int resethand; int caveyes=0; //to please the opengl_stars.c //MUSEUM #define GOVERNOR 4 // animation thottler, Portal = 10 #define EPS .002 // default .002 rotation gain factor #define DEL .02 // default .02 translation gain factor #define INIY 5 // initial position of center #define INIZ -20 // back of screen, fully visible #define GT 0.01 // grantour increment by degrees #define LT .05 // latitude in degrees //(0,1 fast around x-axis) (0.1,.5) rapid tumble int th0, th1, dth, ta0, ta1, dta; /* torus parameters */ float lima, romboy; //venus parameters #define FLYMODE (0) #define TURNMODE (1) int ii, jj, kk; float tmp, temp; /* saves gray hairs later */ float affmat[16], starmat[16], mat[16]; float nose; /* to eye distance in console */ /**********************************************************************/ //prototypes void dawn(int dawn); /**********************************************************************/ bool cubeinit(arMasterSlaveFramework& fw, arSZGClient& ){ ar_setNavMatrix(ar_translationMatrix(0,-5,0)); //initial position fw.addTransferField("affmat", affmat, AR_FLOAT, 16); fw.addTransferField("starmat", starmat, AR_FLOAT, 16); fw.addTransferField("sizz", (&sizz), AR_FLOAT, 1); fw.addTransferField("del", (&del), AR_FLOAT, 1); fw.addTransferField("eps", (&eps), AR_FLOAT, 1); fw.addTransferField("gesture", (&gesture), AR_INT, 1); fw.addTransferField("resethand", (&resethand), AR_INT, 1); fw.addTransferField("mode", (&mode), AR_INT, 1); fw.addTransferField("luxx", luxx, AR_FLOAT, 3); fw.addTransferField("th0", (&th0), AR_INT, 1); fw.addTransferField("th1", (&th1), AR_INT, 1); fw.addTransferField("ta0", (&ta0), AR_INT, 1); fw.addTransferField("ta1", (&ta1), AR_INT, 1); fw.addTransferField("gap", (&gap), AR_FLOAT, 1); fw.addTransferField("morph", (&morph), AR_INT, 1); //venus fw.addTransferField("lima", (&lima), AR_FLOAT, 1); fw.addTransferField("romboy", (&romboy), AR_FLOAT, 1); return true; } // #endif /**********************************************************************/ void autotymer(int reset){ /* cheap animations */ #define TYME(cnt,max,act) {static int cnt; if(first)cnt=max; else\ if(cnt?cnt--:0){ act ; goto Break;}} static int first = 1; /* the first time autymer is called */ if( reset)first=1; /* or if it is reset to start over */ TYME( shrink , 150,th0++;th1--;ta0++;ta1--) TYME( pause , 20, ) TYME( grow , 150,th0--;th1++;ta0--;ta1++) TYME( dwell , 30, ) TYME( finish , 1 , first = 1 ) first = 0; Break: ; /* yes Virginia, C has gotos */ } /**********************************************************************/ void deFault(void){ float tmp; lima =0; romboy= 0; th0=0; th1=360; ta0=0; ta1=360; gap = gap0; msg=1; binoc=0; nose=.06; mode=TURNMODE; #if SZG msg=0; #endif //SZG speed=.01; torq=.002; focal = 2.; wfar =13.; mysiz=.01; morph=1; sizz=5; FOR(ii,0,16) starmat[ii]=affmat[ii] = (ii/4==ii%4); /* identities */ tmp=NRM(lux); FOR(ii,0,3)lux[ii]/=tmp; amb = .3; pwr = 10. ; if(eyes==cave){affmat[12]=0; affmat[13]= 5; affmat[14]= -5 ; } if(eyes==cube){affmat[12]=0; affmat[13]= INIY; affmat[14]= INIZ ; } if(eyes==console){affmat[12]=0; affmat[13]= 0; affmat[14]= -4.2;} /* place where we can see it */ autotymer(1); /* reset autotymer to start at the beginning */ //gesture=1; //tumbling mode gesture=0; //no gesture .. starts on middle button in CUBE eps=EPS; //hand rotation gesture attenuation del=DEL; //hand translation gesture attenuation resethand=0; } /**********************************************************************/ void torvert(int th, int ta){ float lmb,spec,nn[3], dog, cat; nn[0] = C(th)*C(ta); /* unit sphere radius vector */ nn[1] = S(th)*C(ta); nn[2] = S(ta); lmb = DOT(nn,luxx);lmb =(lmb<0 ? lmb : lmb); lmb = MAX(amb, lmb); spec = CLAMP((1.1 - pwr+pwr*lmb), 0., 1.); dog = (ta-ta0)/(float)(ta1-ta0); cat = (th-th0)/(float)(th1-th0); glColor3f( MAX(spec, lmb*dog), /* map R^2(dog,cat)->R^3(RGBspace */ MAX(spec, lmb*(.25 + ABS(cat -.5))), /* dog cat model of Hartman */ MAX(spec, lmb*(1 - cat))); /* illiLight by Ray Idaszak 1989 */ glVertex3f( C(th) + .5*nn[0], S(th) + .5*nn[1], .5*nn[2]); } /* end torvert */ /**********************************************************************/ void venvert(int ta, int th){ float num,den,kk,lmb,spec,vv[3], aa[3], bb[3], nn[3], dog, cat, tmp; ta=ta/2 ; //to keep from doubly covering // th=th/2; we need to know when this is happening. vv[0]= C(2*th)*C(ta) + WAIST*S(ta)*C(th) ; vv[1]= S(2*th)*C(ta) - WAIST*S(ta)*S(th) ; vv[2]= 1.75*C(ta); num = C(lima) + S(lima)*C(ta); den = 1-S(romboy)*S(3*th)*S(2*ta)*KK; kk = num/den; vv[0] *= kk; vv[1] *= kk;vv[2] *= kk; aa[0]= 2*S(2*th)*C(ta) - 0.707*S(ta)*S(th) ; aa[1]= 2*C(2*th)*C(ta) - 0.707*S(ta)*C(th) ; aa[2]= 0; bb[0]= -C(2*th)*S(ta) + 0.707*C(ta)*C(th) ; bb[1]= -S(2*th)*S(ta) - 0.707*C(ta)*S(th) ; bb[2]= -1.75*S(ta); nn[0] = aa[1]*bb[2] - aa[2]*bb[1]; nn[1] = aa[2]*bb[0] - aa[0]*bb[2]; nn[2] = aa[0]*bb[1] - aa[1]*bb[0]; tmp = NRM(nn); nn[0]/=tmp; nn[1]/=tmp; nn[2]/=tmp; //resume old code lmb = DOT(nn,luxx);lmb =(lmb<0 ? -lmb : lmb); lmb = MAX(amb, lmb); spec = CLAMP((1.1 - pwr+pwr*lmb), 0., 1.); dog = (2*ta-ta0)/(float)(ta1-ta0); cat = (th-th0)/(float)(th1-th0); glColor3f( MAX(spec, lmb*dog), /* map R^2(dog,cat)->R^3(RGBspace */ MAX(spec, lmb*(.25 + ABS(cat -.5))), /* dog cat model of Hartman */ MAX(spec, lmb*(1 - cat))); /* illiLight by Ray Idaszak 1989 */ glVertex3f(vv[0],vv[1],vv[2]); } /* end venvert */ void drawtor(void){ int th, ta; dth = (int)((th1-th0)/24); /* 24 meridian strips */ dta = (int)((ta1-ta0)/24); /* 24 triangle pairs per strip */ for(th=th0; th < th1; th += dth){ glBegin(GL_TRIANGLE_STRIP); for(ta=ta0; ta < ta1; ta += dta){ torvert(th,ta); torvert(th+gap*dth,ta); } glEnd(); } /* end for.theta loop */ } /* end drawtor */ void drawven(void){ int th, ta; dth = (int)((th1-th0)/36); /* 24 meridian strips */ dta = (int)((ta1-ta0)/36); /* 24 triangle pairs per strip */ for(th=th0; th < th1; th += dth){ glBegin(GL_TRIANGLE_STRIP); for(ta=ta0; ta < ta1; ta += dta){ venvert(th,ta); venvert(th+gap*dth,ta); } glEnd(); } /* end for.theta loop */ } /* end drawtor */ /**********************************************************************/ void drawcube(void){ /* transfer from skel.c as an exercise */ } /**********************************************************************/ void drawall(void){ if(morph){ //lima += DLIMA; romboy += DROMBOY; static float t=0 ; t = (t<(4-DT))? (t+DT): 0 ; #define P2 90 lima = (t<1)? t*P2 : (t<2) ? P2 : (t<3) ? (3-t)*P2 : 0 ; romboy = (t<1)? 0 : (t<2) ?(t-1)*P2 : (t<3) ? P2 : (4-t)*P2 ; } glRotatef(-90, 1,0,0); drawven(); } /**********************************************************************/ #include "dawn.c" #include "opengl_stars.c" #if 0 //if opengl_stars.c doesn't work, use these poor stars instead. void drawstars(void){ static float star[1000][3]; static int virgin=1; if(virgin){ /* first time set up the stars */ FOR(ii,0,1000)FOR(jj,0,3)star[ii][jj]=random()/(float)0x40000000-1.; virgin=0; /* never again */ } glMatrixMode(GL_MODELVIEW); glPushMatrix(); /* insurance of superstition */ glMultMatrixf(starmat); glColor3f(1.0,1.0,0.0); glBegin(GL_POINTS); FOR(ii,0,1000)glVertex3fv(star[ii]); glEnd(); glPopMatrix(); glClear(GL_DEPTH_BUFFER_BIT); /* so the stars are behind everything */ } #endif /**********************************************************************/ void arguments(int argc,char **argv){ /* Pat Hanrahan 1989 */ eyes=cube; while(--argc){++argv; if(argv[0][0]=='-')switch(argv[0][1]){ case 'w': win =atoi(argv[1]); argv++; argc--; break; case 'c': eyes=console;break; case 'g': gap0 =atof(argv[1]); argv++; argc--; break; case 'L': lux[0]=atof(argv[1]); lux[1]=atof(argv[2]); lux[2]=atof(argv[3]); argv +=3; argc -=3; break; }}} /**********************************************************************/ void keyboard(unsigned char key, int x, int y){ #define IF(K) if(key==K) #define PRESS(K,A,b) IF(K){b;}IF((K-32)){A;} /*was backwards in previous versions */ #define TOGGLE(K,flg) IF(K){(flg) = 1-(flg); } #define CYCLE(K,f,m) PRESS((K), (f)=(((f)+(m)-1)%(m)),(f)=(++(f)%(m))) #define SLIDI(K,f,m,M) PRESS(K,(--fM?M:f)) #define SLIDF(K,f,m,M,d) PRESS(K,((f -= d)M?M:f)) /* Only ASCII characters can be processes by this GLUT callback function */ IF(27) { exit(0); } /* ESC exit */ TOGGLE('v',binoc); /* cross-eyed STEREO */ CYCLE('m', mode,TURNMODE+1); /* fly/turn modes */ TOGGLE('h',morph); /* autotymer on/off */ TOGGLE('w',msg); /* writing on/off */ PRESS('n', nose -= .001 , nose += .001 ); /* for binoculars */ PRESS('s',speed /= 1.02, speed *= 1.02); /* flying speed */ PRESS('q',torq /= 1.02, torq *= 1.02); /* turning speed */ PRESS('o', focal *= 1.1 , focal /= 1.1) /* telephoto */ PRESS('i', mysiz /= 1.1, mysiz *= 1.1) /* rescale the world */ PRESS('p', wfar *= 1.01 , wfar /= 1.01) /* rear clipping plane */ PRESS('z', deFault(), deFault()); /* zap changes */ PRESS('g',gap /= .9, gap *= .9); /* gap parameter */ PRESS('a',amb /= .9, amb *= .9); /* ambient fraction */ PRESS('r',pwr /= .9, pwr *= .9); /* pseudo-spec power */ } /**********************************************************************/ void clefs(arMasterSlaveFramework& , unsigned char key, int x, int y){ keyboard(key,x,y); } /**********************************************************************/ void special_keybo(int key, int x, int y){ /*non-ASCII keypresses go here, if you're lucky enough to know their names */ fprintf(stderr," non-ASCII character was pressed.\n"); fprintf(stderr," use special_keybo() to process it\n"); } /**********************************************************************/ #ifdef UNIX float speedometer(void){ double dbl; static double rate; static int ii=0; static struct timezone notused; static struct timeval now, then; if(++ii % 8 == 0){ /* 8 times around measure time */ gettimeofday(&now, ¬used); /* elapsed time */ dbl = (double)(now.tv_sec - then.tv_sec) +(double)(now.tv_usec - then.tv_usec)/1000000; then = now; rate = 8/dbl; } return((float)rate); } #endif #ifdef WIN32 float speedometer(void){ /* this one is for win32*/ double dbl; static double rate; static int ii=0; static struct _timeb lnow, lthen; if(++ii % 8 == 0){ /* 8 times around measure time */ _ftime(&lnow); dbl = (double)(lnow.time - lthen.time) +(double)(lnow.millitm - lthen.millitm)/1000; lthen = lnow; rate = 8/dbl; } return((float)rate); } #endif /**********************************************************************/ void char2wall(float x,float y,float z, char buf[]){ char *p; glRasterPos3f(x,y,z); for(p = buf;*p;p++) glutBitmapCharacter(GLUT_BITMAP_9_BY_15,*p); } /**********************************************************************/ void graffiti(void){ char buf[256]; /* console graffiti are done differently from cave */ #define LABEL2(x,y,W,u) {sprintf(buf,(W),(u));char2wall(x,y,0.,buf);} glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluOrtho2D(0,3000,0,3000); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); /*bull's eye*/ if(mode==TURNMODE) glColor3f(0x22/255.,0x88/255.,0xdd/255.); else glColor3f(.8,.8,.8); LABEL2(1500,1500,"%s","o"); /* writings */ if(mode==TURNMODE) glColor3f(1.,0.,1.); else glColor3f(1.,1.,0.); LABEL2(80,80,"%4.1f fps",speedometer()); LABEL2(80,2840,\ "(ESC)ape {wandbutn} (V)Binoc (MAUS2)Fore (BAR)Flymode %s {A}(H)omotopy (W)riting", mode?"FLYING":"CONTROL"); LABEL2(10,10,"illiOpenSkelGLUT+SZG 3jun07\ by Francis, Schaeffer, Blank, Woodruff, Bourd, Hartman & Chappell, U Illinois, 1995..2004 %s",""); LABEL2(80,2770,"(N)ose %0.3f",nose); LABEL2(80,2700,"(S)peed %0.4f",speed); LABEL2(80,2630," tor(Q) %0.4f",torq); LABEL2(80,2560,"near clipper %g", mysiz*focal); LABEL2(80,2490,"f(O)cal factor %g",focal); LABEL2(80,2420,"my s(I)ze %.2g",mysiz); LABEL2(80,2350,"wfar cli(P)er= %.2g",wfar); LABEL2(80,2280,"(Z)ap{Z} %s",""); LABEL2(80,2210,"(G)ap %.2g",gap); LABEL2(80,2140,"(A)mb %.2g",amb); LABEL2(80,2070,"pw(R) %.2g",pwr); LABEL2(80,2000,"morph{A} %d",morph); LABEL2(80,1790,"head {B} %d",resethand); LABEL2(80,1930,"gesture {C} %d",gesture); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); } /**********************************************************************/ void chaptrack(int but,int xx,int yy,int shif){ long dx,dy; dx = xx -.5*xt; dx = abs(dx)>5?dx:0; dy = yy -.5*yt; dy = abs(dy)>5?dy:0; glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); if(mode==TURNMODE) glTranslatef(affmat[12],affmat[13],affmat[14]); glRotatef(dx*torq,0.,1.,0.); glRotatef(dy*torq,1.,0.,0.); if(but&(1< tr[1]) ii = 0; if(tr[3] > tr[2]) jj = 3; if(tr[jj] > tr[ii]) ii = jj; // printf("\n %i is the largest trace. \n", ii); tmp = 4*sqrt(tr[ii]+1)/2; switch(ii){ case 0: quat[0] = tmp/4; quat[1] = (mat[6] - mat[9]) / tmp; quat[2] = (mat[8] - mat[2]) / tmp; quat[3] = (mat[1] - mat[4]) / tmp; break; case 1: quat[0] = (mat[6] - mat[9]) / tmp; quat[1] = tmp/4; quat[2] = (mat[1] + mat[4]) / tmp; quat[3] = (mat[8] + mat[2]) / tmp; break; case 2: quat[0] = (mat[8] - mat[2]) / tmp; quat[1] = (mat[4] + mat[1]) / tmp; quat[2] = tmp/4; quat[3] = (mat[9] + mat[6]) / tmp; break; case 3: quat[0] = (mat[1] - mat[4]) / tmp; quat[1] = (mat[8] + mat[2]) / tmp; quat[2] = (mat[9] + mat[6]) / tmp; quat[3] = tmp/4; break; } } void loadIdentity(float* mat) {int ii; for(ii=0;ii<16;ii++) mat[ii]=float(ii/4 == ii%4);} void getmat(float *target, float *source){ memcpy(target,source, 16*sizeof(float)); } void multmatinv(float *T){ // of an Euclidean isometry float N[16]; getmat(N,T); N[1] = T[4]; N[2] = T[8]; N[6] = T[9]; N[4] = T[1]; N[8] = T[2]; N[9] = T[6]; N[12]= -T[0]*T[12]-T[1]*T[13]-T[2]*T[14]; N[13]= -T[4]*T[12]-T[5]*T[13]-T[6]*T[14]; N[14]= -T[8]*T[12]-T[9]*T[13]-T[10]*T[14]; glMultMatrixf(N); } // uses eps to shrink rotation and del to shring translation void updateaffmat(float *oldhand, float *newhand){ float dx=0, dy=0, dz=0 ; float dhand[16]; float quat[4]; glMatrixMode(GL_TEXTURE); //do some arithmetic on an unused stack glPushMatrix(); glLoadIdentity(); multmatinv(newhand); glMultMatrixf(oldhand); glGetFloatv(GL_TEXTURE_MATRIX, dhand); glPopMatrix(); //dhand= newhand^-1 * oldhand dx=del*dhand[12]; dhand[12]=0; //attenuation is about right dy=del*dhand[13]; dhand[13]=0; dz=del*dhand[14]; dhand[14]=0; //use a bit of the translation in dhand and then make it the rotation if(gesture==2){ //shrink dhand m2q(dhand,quat); quat[0]= 1-eps + eps*quat[0]; quat[1] *= eps; quat[2] *= eps; quat[3] *= eps; normalize(quat); q2m(quat,dhand); } // tumble museum mode is now 1 and proper gesture is 2 if(gesture==1){ static float gt=0; gt+=GT; quat[0]=C(LT) ; quat[1]=S(LT)*C(gt)*C(1.618*gt); quat[2]=S(LT)*S(gt)*C(1.618*gt); quat[3]=S(LT)*S(1.618*gt); normalize(quat); q2m(quat,dhand); } if(mode==FLYMODE){ glMatrixMode(GL_TEXTURE); glLoadIdentity(); glMultMatrixf(dhand); //rotate the stars glMultMatrixf(starmat); glGetFloatv(GL_TEXTURE_MATRIX,starmat); } glMatrixMode(GL_TEXTURE); glPushMatrix(); glLoadIdentity(); if(mode==TURNMODE) glTranslatef(affmat[12],affmat[13],affmat[14]); glMultMatrixf(dhand); //just the rotation of it glTranslatef(dx,dy,dz); if(mode==TURNMODE) glTranslatef(-affmat[12],-affmat[13],-affmat[14]); glMultMatrixf(affmat); glGetFloatv(GL_TEXTURE_MATRIX,affmat); } void readbuttons(arMasterSlaveFramework& fw){ const int butn[6]= { fw.getButton(0), fw.getButton(1), fw.getButton(2), fw.getButton(3), fw.getButton(4), fw.getButton(5) }; static int obutn[6]={0,0,0,0,0,0}; if(obutn[0]==0 & butn[0] == 1) morph=1-morph; //{A}button if(obutn[1]==0 & butn[1] == 1) resethand=1; //{B}button if(obutn[2]==0 & butn[2] == 1) gesture=gesture==2?0:2; //{C}button if(obutn[4]==0 & butn[4] == 1) mode=1-mode; //{Y}button if(obutn[5]==0 & butn[5] == 1) deFault(); //{Z}button #if 0 {static int click=GOVERNOR; if(morph&&click==0)autotymer(0); click=click>0?click-1:GOVERNOR;} #endif memcpy(obutn,butn,6*sizeof(int)); } void gesturetrack(arMasterSlaveFramework& fw){ //the present logic is legacy stuff from zyspace, rationalize it! if (!fw.getMaster())return; //only the master should listen //this is the gesture navigator static float oldhand[16]; float handmat[16]; arMatrix4 arhand=fw.getMatrix(1); getmat(handmat,arhand.v); //geotrack(arhand.v) gets arhand.v and used as float* handmat static bool reshand=true; if(resethand){reshand=true; resethand=false;} //do we really need two flags? if(gesture){ updateaffmat(oldhand,handmat); } if(reshand){reshand=false; getmat(oldhand, handmat);} //this is the Pape navigator //this should really be done on the arithmetic (Texture) stack glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); const float joy0 = fw.getAxis(0); //joystick right-left const float joy1 = fw.getAxis(1); //joystick fore-aft const float xx = arhand.v[8]; const float yy = arhand.v[9]; const float zz = arhand.v[10]; // printf(" xx %g yy %g zz %g \n",xx,yy,zz); const float da = .5*joy0; const float ds = .1*joy1; //joystick translates in the wand direction glTranslatef(xx*ds, yy*ds, zz*ds); glRotatef(da, 0.,1.,0.); glMultMatrixf(affmat); glGetFloatv(GL_MODELVIEW_MATRIX,affmat); glPopMatrix(); //not the bast place for calculite but ... {int ii,jj; for(ii=0;ii<3;ii++){ luxx[ii]=0; /* calculite */ for(jj=0;jj<3;jj++) luxx[ii] += affmat[ii*4+jj]*lux[jj];} } //this is an illogical place for this but maybe it works again readbuttons(fw); } /**********************************************************************/ #if 0 //alternate Papish navigator void cubetrack(arMasterSlaveFramework& fw){ int ii; if (!fw.getMaster()) return; // chokes here but it's in skel1j const int butn[3]={fw.getButton(0), fw.getButton(1), fw.getButton(2)}; const float j0 = fw.getAxis(0); const float j1 = fw.getAxis(1); arMatrix4 handmatrix=fw.getMatrix(1); const float xx = handmatrix.v[8]; const float yy = handmatrix.v[9]; const float zz = handmatrix.v[10]; glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glTranslatef(xx*j1/10,0,0); glTranslatef(0,yy*j1/10,0); glTranslatef(0,0,zz*j1/10); glRotatef(j0/2.0, 0.,1.,0.); glMultMatrixf(affmat); glGetFloatv(GL_MODELVIEW_MATRIX,affmat); {int ii,jj; for(ii=0;ii<3;ii++){ luxx[ii]=0; /* calculite */ for(jj=0;jj<3;jj++) luxx[ii] += affmat[ii*4+jj]*lux[jj];} } glPopMatrix(); if(butn[0] == 1) deFault(); if(butn[2] == 1)morph = 1-morph; if(morph)autotymer(0); } #endif void diddle(arMasterSlaveFramework&) { //now we want to do any calculations that would rely on the shared stuff } void cubedraw(arMasterSlaveFramework& fw){ glPushMatrix(); glTranslatef(0,5,0); glScalef(sizz,sizz,sizz); dawn(1); drawstars(); glPopMatrix(); glMultMatrixf(affmat); glScalef(sizz,sizz,sizz); drawall(); } int main(int argc, char **argv){ arguments(argc, argv); dataprep(); if(eyes==console){ /*console main*/ glutInit(&argc, argv); glutInitDisplayMode(GLUT_DOUBLE|GLUT_DEPTH); switch(win) { case 0: break; case 1: glutInitWindowSize(640, 480); glutInitWindowPosition(0,1024-480); break; case 2: glutInitWindowPosition(0,0); break; } glutCreateWindow("<* illiSkel in C/OpenGL/GLUT *>"); if(win==2) glutFullScreen(); glEnable(GL_DEPTH_TEST); glutDisplayFunc(drawcons); glutKeyboardFunc(keyboard); glutSpecialFunc(special_keybo); glutMouseFunc(mousepushed); glutMotionFunc(mousemoved); glutPassiveMotionFunc(mousemoved); glutReshapeFunc(reshaped); glutIdleFunc(idle); glutMainLoop(); } else if(eyes==cube){ //syzygy main arMasterSlaveFramework* fff = new arMasterSlaveFramework(); if(!fff->init(argc,argv)) return 1; // fff->setInitCallback(cubeinit); fff->setStartCallback(cubeinit); fff->setPreExchangeCallback(gesturetrack); // fff->setPreExchangeCallback(cubetrack); fff->setDrawCallback(cubedraw); fff->setPostExchangeCallback(diddle); fff->setKeyboardCallback(clefs); fff->setOverlayCallback(overlay); // framework.setClipPlanes( .1, 1000 ); // framework.setEyeSpacing(6/(12*2.54)); return fff->start() ? 0:1; } }