float paramval() { float p; p = (float)(getmousex()-SLIDERLEFT)/(xsize-SLIDERLEFT); if(p<0.0) return 0.0; if(p>1.0) return 1.0; return p; }
void handler(float time) { static float oldtime=0.0f; static float lx=0.0f,ly=0.0f; static float mx,my; static BOOLINT b1,b2,b3; static int key; int t1,t2,t3; float newtime; BOOLINT update; int hook; float over; if (!GUI_demo) { mx=getmousex(); my=getmousey(); b1=getbutton1(); b2=getbutton2(); b3=getbutton3(); key=getkey(); } else switch (key=getkey()) { case '\033': // quit application case 'q': case 'Q': case 'x': quithook(); } if (GUI_record) fprintf(GUI_recfile,"time=%g dt=%g mx=%g my=%g b1=%d b2=%d b3=%d key=%d\n", gettime()-GUI_start,time,mx,my,b1,b2,b3,(key!='D')?key:0); update=TRUE; if (GUI_demo) if (oldtime<gettime()-GUI_start) if (fscanf(GUI_recfile,"time=%g dt=%g mx=%g my=%g b1=%d b2=%d b3=%d key=%d\n", &newtime,&time,&mx,&my,&t1,&t2,&t3,&key)!=8) if (GUI_loop==0) { oldtime=newtime; GUI_demo=FALSE; b1=b2=b3=FALSE; key=0; } else { fclose(GUI_recfile); if ((GUI_recfile=fopen(RECORD,"rb"))==NULL) ERRORMSG(); oldtime=0.0f; GUI_start=gettime(); b1=b2=b3=FALSE; key=0; } else { oldtime=newtime; b1=(t1!=0); b2=(t2!=0); b3=(t3!=0); } else update=FALSE; if (update) { switch (key) { case ' ': // start/stop of flight if (EYE_SPEED==0.0f) EYE_SPEED=EYE_MAXSPEED; else stophook(); break; case 'a': // accelerate flight acchook(); break; case 's': // decelerate flight dechook(); break; case 'w': // toggle wireframe GUI_wire=!GUI_wire; break; case 'b': // toggle white background GUI_white=!GUI_white; break; case 'B': // toggle inverse mode GUI_inv=!GUI_inv; break; case 'm': // toggle premultiplied alpha GUI_premult=!GUI_premult; break; case 'i': // toggle preintegration GUI_preint=!GUI_preint; break; case 'g': // toggle 2DTF GUI_grad=!GUI_grad; reloadhook(); break; case 'l': // toggle lighting GUI_light=!GUI_light; reloadhook(); break; case 'h': // hide GUI if (GUI_capt) GUI_capt=FALSE; else GUI_hide=!GUI_hide; reloadhook(); break; case 'H': // hide GUI except TF GUI_hide=FALSE; GUI_capt=!GUI_capt; reloadhook(); break; case 'p': // toggle barycenters GUI_points=!GUI_points; break; case '+': // select higher gradients case 'A': cyclehook(); break; case '-': // select lower gradients case 'S': recyclehook(); break; case '>': // select more gradients incrangehook(); break; case '<': // select fewer gradients decrangehook(); break; case '0': // disable gradient selection VOLREN->get_tfunc()->unset_imp(); break; case '1': // enable gradient selection VOLREN->get_tfunc()->set_imp(GUI_cycle,GUI_range); break; case 'C': // toggle coupling GUI_coupled=!GUI_coupled; break; case 'W': // write .sav file savehook(); break; case 'R': // read .sav file loadhook(); break; case 'D': // toggle event recording if (!GUI_demo) { GUI_record=!GUI_record; if (GUI_record) { if ((GUI_recfile=fopen(RECORD,"wb"))==NULL) ERRORMSG(); GUI_start=gettime(); } } break; case '\033': // quit application case 'q': case 'Q': case 'x': quithook(); } if (gettime()-GUI_time>VOL_DELAY1) GUI_reduced=FALSE; if (!b1) OGL_GUI.release(mx,my); else { hook=OGL_GUI.click(mx,my); if (hook==0) if (!GUI_clip) { GUI_rotx+=mx-lx; GUI_roty-=my-ly; GUI_reduced=TRUE; } else { GUI_clip_dist-=my-ly; GUI_reduced=TRUE; } else if (hook!=GUI_hook1 && hook!=GUI_hook2 && hook!=GUI_hook3 && hook!=GUI_hook4 && hook!=GUI_hook5 && hook!=GUI_hook6 && hook!=GUI_hook7 && hook!=GUI_hook8 && hook!=GUI_hook9 && hook!=GUI_hook10 && hook!=GUI_hook11 && hook!=GUI_hook12 && hook!=GUI_hook14 && hook!=GUI_hook15 && hook!=GUI_hook16 && hook!=GUI_hook17 && hook!=GUI_hook18 && hook!=GUI_hook19 && hook!=GUI_hook20 && hook!=GUI_hook21 && hook!=GUI_hook22 && hook!=GUI_hook23 && hook!=GUI_hook24 && hook!=GUI_hook25 && hook!=GUI_hook26 && hook!=GUI_hook27 && hook!=GUI_hook28) GUI_reduced=TRUE; GUI_time=gettime(); } lx=mx; ly=my; GUI_roty=fmin(fmax(GUI_roty,-0.5f),0.5f); EYE_DX=fsin(GUI_rotx*PI)*fcos(GUI_roty*PI); EYE_DY=fsin(GUI_roty*PI); EYE_DZ=-fcos(GUI_rotx*PI)*fcos(GUI_roty*PI); EYE_UX=-fsin(GUI_rotx*PI)*fsin(GUI_roty*PI); EYE_UY=fcos(GUI_roty*PI); EYE_UZ=fcos(GUI_rotx*PI)*fsin(GUI_roty*PI); if (b2) if (b3) stophook(); else acchook(); else if (b3) dechook(); if (fabs(EYE_SPEED)>EYE_MAXSPEED/20.0f) { GUI_reduced=TRUE; GUI_time=gettime(); } EYE_X+=EYE_DX*EYE_SPEED*time; EYE_Y+=EYE_DY*EYE_SPEED*time; EYE_Z+=EYE_DZ*EYE_SPEED*time; } if (!GUI_reduced) if (gettime()-GUI_time>VOL_DELAY2) over=VOL_OVERMIN; else if (GUI_slab1<0.5f) { float w=2.0f*GUI_slab1; over=((1.0f-w)*VOL_OVERMAX+w); } else { float w=2.0f*(1.0f-GUI_slab1); over=((1.0f-w)*VOL_OVERMIN+w); } else if (GUI_slab1<0.5f) { float w=2.0f*GUI_slab1; over=((1.0f-w)*VOL_OVERMAX+w)*fmin(1.0f/GUI_slab2,VOL_OVERMAX); } else { float w=2.0f*(1.0f-GUI_slab1); over=((1.0f-w)*VOL_OVERMIN+w)*fmin(1.0f/GUI_slab2,VOL_OVERMAX); } VOLREN->enablewireframe(GUI_wire); VOLREN->enablehistogram(GUI_points); VOLREN->begin(EYE_FOVY,getaspect(),EYE_NEAR,EYE_FAR, GUI_white,GUI_inv); VOLREN->render(EYE_X,EYE_Y,EYE_Z, EYE_DX,EYE_DY,EYE_DZ, EYE_UX,EYE_UY,EYE_UZ, EYE_NEAR, GUI_fbo, 360.0f*GUI_rot,0.0f,0.0f, 0.0f,4.0f*(GUI_height-0.5f),0.0f, VOL_EMISSION,VOL_DENSITY, GUI_re_scale,GUI_ge_scale,GUI_be_scale, GUI_ra_scale,GUI_ga_scale,GUI_ba_scale, GUI_premult,GUI_preint, GUI_inv, over, GUI_light, GUI_clip,GUI_clip_dist); OGL_GUI.refresh(); if (GUI_demo) { glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0.0f,getwinwidth()-1,0.0f,getwinheight()-1); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); glScalef(getwinwidth()-1,getwinheight()-1,0.0f); glDisable(GL_DEPTH_TEST); glColor3f(1.0f,0.0f,0.0f); glBegin(GL_LINES); glVertex2f(0.5f+mx-0.01f/getaspect(),0.5f+my-0.01f); glVertex2f(0.5f+mx+0.01f/getaspect(),0.5f+my+0.01f); glVertex2f(0.5f+mx+0.01f/getaspect(),0.5f+my-0.01f); glVertex2f(0.5f+mx-0.01f/getaspect(),0.5f+my+0.01f); glEnd(); glEnable(GL_DEPTH_TEST); glPopMatrix(); } swapbuffers(); }