📄 wzwindow.c
字号:
win->asp=1.0; win->frame=1; win->gouraud_shading=1; win->sensitivity=0.5; win->bg_black=1; win->lightTX=0.0; win->lightTY=0.5; win->lightTZ= -1.0; win->sliceDir='z'; win->slice[0]=0.0; win->slice[1]=0.0; win->slice[2]=1.0; win->slice[4]=-0.5*(win->boxMax[2]-win->boxMin[2]); win->p_min=win->boxMin[2]+p_eps*(win->boxMax[2]-win->boxMin[2]); win->p_boxMax=win->boxMax[2]-p_eps*(win->boxMax[2]-win->boxMin[2]); win->list_valid=0; win->level_surf=0; win->level=0.0; win->dialog=1; }wzWindow wzwCreate( char *name, char *help, char *url, int xpos, int ypos, int wdt, int hgt){ glWindow w; wzWindow win; glwInitPosition(xpos,ypos,wdt,hgt); glwInitTitle(name); w=glwCreate(); if (w==NULL) { fprintf(stderr,"wzwnd: unable to open window\n"); return NULL; } win=(struct wzWindowStruct*) calloc(1,sizeof(struct wzWindowStruct)); win->name = name; win->help = help; win->url = url; win->glwin=w; win->volume_init = 1; wzwReset(win); /* cool picture !*/ glClearColor(0.2, 0.2, 0.2, 1.0); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glwSwapBuffers(win->glwin); glFlush(); /* new keys */ wzwRegisterKeyAction(win,WZW_KEY_Print,wzwActionPrint,"print actual picture into *_*.ppm","wzwindow.html#Print"); wzwRegisterKeyAction(win,WZW_KEY_PrintAlt,wzwActionPrint,"print actual picture into *_*.ppm","wzwindow.html#Print"); wzwRegisterKeyAction(win,WZW_KEY_FrameToggle,wzwActionFrameToggle,"toggle frame (bounding box) drawing.","wzwindow.html#FrameToggle"); wzwRegisterKeyAction(win,WZW_KEY_Background,wzwKeyAction_Background,"toggle background color (black/white)","wzwindow.html#Background"); wzwRegisterKeyAction(win,WZW_KEY_QuitAlt,wzwKeyAction_Quit,"quit","wzwindow.html#Quit"); wzwRegisterKeyAction(win,WZW_KEY_Quit,wzwKeyAction_Quit,"quit","wzwindow.html#Quit"); wzwRegisterKeyAction(win,WZW_KEY_Inc_Mouse,wzwKeyAction_inc_mouse, "increase mouse sensitivity.","wzwindow.html#Mouse"); wzwRegisterKeyAction(win,WZW_KEY_Dec_Mouse,wzwKeyAction_dec_mouse,"decrease mouse sensitivity.","wzwindow.html#Mouse"); wzwRegisterKeyAction(win,WZW_KEY_Wireframe,wzwKeyAction_wireframe,"toggle wireframe mode","wzwindow.html#Wireframe"); wzwRegisterKeyAction(win,WZW_KEY_Gouraud,wzwKeyAction_g,"toggle Gouraud/flat shading","wzwindow.html#Gouraud"); wzwRegisterKeyAction(win,WZW_KEY_MoveStatus,wzwKeyAction_move_status,"toggle what to move: wireframe or frame only","wzwindow.html#MoveStatus"); /* wzwRegisterKeyAction(win,GLW_w,wzwKeyAction_w, "w: Move showing wireframe only (fast).","wzwindow.html"); wzwRegisterKeyAction(win,GLW_f,wzwKeyAction_f, "f: Move frame (bounding box) only","wzwindow.html"); wzwRegisterKeyAction(win,GLW_greater,wzwKeyAction_SC_in,">: scale in.","wzwindow.html#scale"); wzwRegisterKeyAction(win,GLW_less, wzwKeyAction_SC_out,"<: scale out.","wzwindow.html#scale");*/ /* wzwRegisterKeyAction(win,GLW_space,wzwKeyAction_Quit, "SPACE: State control","wzwindow.html"); wzwRegisterKeyAction(win,GLW_o,wzwKeyAction_object_move, "o: Toogle object/frame movement","wzwindow.html#o"); wzwRegisterKeyAction(win,GLW_l,wzwKeyAction_l, "l: Level surface.","wzwindow.html"); wzwRegisterKeyAction(win,GLW_x,wzwKeyAction_x, "x: Show x orthogonal slice section.","wzwindow.html"); wzwRegisterKeyAction(win,GLW_y,wzwKeyAction_y, "y: Show y orthogonal slice section.","wzwindow.html"); wzwRegisterKeyAction(win,GLW_z,wzwKeyAction_z, "z: Show z orthogonal slice section.","wzwindow.html"); wzwRegisterKeyAction(win,GLW_question,wzwKeyAction_help, "?: Key help.","wzwindow.html"); wzwRegisterKeyAction(win,GLW_r,wzwKeyAction_r, "r: Reset.","wzwindow.html"); wzwRegisterKeyAction(win,GLW_Left ,wzwKeyAction_left , "<= :rotate/ SHIFT+<=:shift/ SHIFT+CTRL+<=:level/ ALT+CTRL+<=:move light/" ,"wzwindow.html"); wzwRegisterKeyAction(win,GLW_Right,wzwKeyAction_right, "=> :rotate/ SHIFT+=>:shift/ SHIFT+CTRL+=>:level/ ALT+CTRL+=>:move light/","wzwindow.html"); wzwRegisterKeyAction(win,GLW_Up ,wzwKeyAction_up , "Up :rotate/ SHIFT+Up:shift/ SHIFT+CTRL+Up:scale/ ALT+CTRL+Up:move light/","wzwindow.html"); wzwRegisterKeyAction(win,GLW_Down ,wzwKeyAction_down , "Down:rotate/ SHIFT+Dn:shift/ SHIFT+CTRL+Dn:scale/ ALT+CTRL+Dn:move light/","wzwindow.html"); wzwRegisterKeyAction(win,GLW_I,wzwKeyAction_info, "I: full state information","wzwindow.html"); wzwRegisterKeyAction(win,GLW_S,wzwKeyAction_S,"S: increase scale factor.","wzwindow.html"); wzwRegisterKeyAction(win,GLW_s,wzwKeyAction_s,"s: decrease scale factor.","wzwindow.html"); */ win->list=1; win->list_valid=0; win->data_valid=0; win->firstcall=1; win->next_dialog=0; win->dump_w=600; win->dump_h=600; win->dump_i=0; strcpy(win->dump_name_stub,name); wzwInit(win); glwShowState(win->glwin, win->help); wzwShowState(win); return win;}void wzwDumpNext(wzWindow win){ win->dump=1;}void wzwSetDumpFileNameStub(wzWindow win, char *name){ strcpy(win->dump_name_stub,name);}void wzwSetDumpPixmapSize(wzWindow win, int w, int h){ win->dump_w=600; win->dump_h=600;}void wzwSetTitle(wzWindow win, char *title){ glwSetTitle(win->glwin,title);}void wzwDestroy(wzWindow win){ glwDestroy(win->glwin); free(win);}void wzwGetLevelSurface(wzWindow win, int* mode){ *mode=win->level_surf;}void wzwSetLevelSurface(wzWindow win, int mode){ win->level_surf=mode;}void wzwGetLevel(wzWindow win, double* lev){ *lev=win->level;}void wzwSetLevel(wzWindow win, double lev){ win->level=lev;}void wzwSetDataValid(wzWindow win, int valid){ win->data_valid=valid;}void wzwMoveFrame(wzWindow win){ win->move_frame=1; win->move_wireframe=0; win->drawLevel = WZW_DRAW_BEST; win->move_model=0;}void wzwMoveWireframe(wzWindow win){ win->move_wireframe=1; win->drawLevel = WZW_DRAW_COARSE; win->move_frame=0; win->move_model=0;}void wzwMoveModel(wzWindow win){ win->move_wireframe=0; win->drawLevel = WZW_DRAW_BEST; win->move_frame=0; win->move_model=1;}void wzwSetPerspective(wzWindow win, double rotx, double rotz){ win->cameraRX=rotx; win->cameraRY=rotz;}void wzwGetPerspective(wzWindow win, double *rotx, double *rotz){ *rotx=win->cameraRX; *rotz=win->cameraRY;}void wzwGetWireframe(wzWindow win, int *wf){ *wf=win->wireframe;}void wzwSetFlatshading(wzWindow win, int flat){ win->gouraud_shading=!flat;}void wzwGetFlatshading(wzWindow win, int *flat){ *flat=!win->gouraud_shading;}void wzwSetDialog(wzWindow win, int dialog){ win->dialog=dialog;}void wzwGetDialog(wzWindow win, int *dialog){ *dialog=win->dialog;}void wzwSetPlane(wzWindow win, double a,double b,double c, double d){ win->slice[0]=a; win->slice[1]=b; win->slice[2]=c; win->slice[4]=d;}void wzwGetSliceState(wzWindow win, int *hold){ *hold = win->showSlice;}void wzwGetMouseState(wzWindow win, int *hold){ *hold = win->button_hold;}void wzwSetVScale(wzWindow win, double vscale){ win->vscale= vscale;}void wzwGetVScale(wzWindow win, double *vscale){ *vscale= win->vscale;}static void wzwReshape(glWindow w, void *info,int width, int height){ wzWindow win=(wzWindow)info; win->asp=(double)width/(double)height; glViewport(0, 0, (GLint)width, (GLint)height);}static GLenum wzwMouse1(glWindow w, void * info,int x,int y, GLenum mask){ wzWindow win=(wzWindow)info; if (mask & GLW_SHIFT){ /* translate */ if (win->object_move){ double xs,ys; xs=0.008*win->sensitivity*(x-win->lastxpos); ys=0.008*win->sensitivity*(y-win->lastypos); win->lastxpos=x; win->lastypos=y; switch(win->sliceDir){ case 'x': xs *= win->boxMax[1]-win->boxMin[1]; ys *= win->boxMax[2]-win->boxMin[2]; wzwSetVolume(win, win->boxMin[0],win->boxMax[0], win->boxMin[1]-xs,win->boxMax[1]-xs, win->boxMin[2]+ys,win->boxMax[2]+ys); break; case 'y': xs *= win->boxMax[0]-win->boxMin[0]; ys *= win->boxMax[2]-win->boxMin[2]; wzwSetVolume(win, win->boxMin[0]-xs,win->boxMax[0]-xs, win->boxMin[1],win->boxMax[1], win->boxMin[2]+ys,win->boxMax[2]+ys); break; case 'z': xs *= win->boxMax[0]-win->boxMin[0]; ys *= win->boxMax[1]-win->boxMin[1]; wzwSetVolume(win, win->boxMin[0]-xs,win->boxMax[0]-xs, win->boxMin[1]+ys,win->boxMax[1]+ys, win->boxMin[2],win->boxMax[2]); break; } win->list_valid=0; wzwShowState(win); return GL_TRUE; } win->cameraTX+=0.008*win->sensitivity*(x-win->lastxpos); win->cameraTY-=0.008*win->sensitivity*(y-win->lastypos); win->lastxpos=x; win->lastypos=y; return GL_TRUE; } else /* rotate */ { win->cameraRY+=0.7*win->sensitivity*(x-win->lastxpos); win->cameraRX+=0.7*win->sensitivity*(y-win->lastypos); win->lastxpos=x; win->lastypos=y; return GL_TRUE; }}static GLenum wzwMouse2(glWindow w, void * info,int x,int y, GLenum mask){ wzWindow win=(wzWindow)info; if (mask & GLW_SHIFT) /* rotate light */ { win->lightTX+=0.05*win->sensitivity*(x-win->lastxpos); win->lightTY-=0.05*win->sensitivity*(y-win->lastypos); win->lastxpos=x; win->lastypos=y; return GL_TRUE; } else { /* scale values */ win->vscale-=0.1*win->sensitivity*(y-win->lastypos); win->lastypos=y; win->list_valid=0; return GL_TRUE; }}static GLenum wzwMouse3(glWindow w, void * info,int x,int y, GLenum mask){ wzWindow win=(wzWindow)info; if (win->level_surf) { win->level-= 0.01*win->sensitivity*(y-win->lastypos); win->lastypos=y; win->list_valid=0; wzwShowState(win); return GL_TRUE; } else { win->slice[4]+= 0.01*win->sensitivity*(win->p_boxMax-win->p_min)*(y-win->lastypos); if ( -win->slice[4] < win->p_min) win->slice[4]= -win->p_min; if ( -win->slice[4] > win->p_boxMax) win->slice[4]= -win->p_boxMax; win->lastypos=y; win->list_valid=0; wzwShowState(win); return GL_TRUE; }}static GLenum wzwMouseDown(glWindow w, void * info,int x,int y, GLenum mask){ wzWindow win=(wzWindow)info; win->button_hold = 1; win->drawLevel = WZW_DRAW_WIREFRAME;/* if (mask&GLW_LEFTBUTTON) glwSetMouseMoveFunc(w,wzwMouse1); else if (mask&GLW_MIDDLEBUTTON) glwSetMouseMoveFunc(w,wzwMouse2); else if (mask&GLW_RIGHTBUTTON) glwSetMouseMoveFunc(w,wzwMouse3);*/ glwSetMouseMoveFunc(w,wzwMouse); if (win->move_wireframe||win->move_frame) { if (win->move_wireframe) win->list_valid=0; win->wireframe=1; glDisable(GL_LIGHTING); glDisable(GL_COLOR_MATERIAL); glDisable(GL_DEPTH_TEST); glPolygonMode(GL_FRONT_AND_BACK,GL_LINE); } win->lastxpos=x; win->lastypos=y; wzwShowState(win); return GL_TRUE;}static GLenum wzwMouseUp(glWindow w, void * info,int x,int y, GLenum mask){ wzWindow win=(wzWindow)info; win->button_hold = 0; win->drawLevel = WZW_DRAW_NORMAL; if (win->move_wireframe) win->list_valid=0; glwSetMouseMoveFunc(w,NULL); glEnable(GL_LIGHTING); glEnable(GL_COLOR_MATERIAL); glEnable(GL_DEPTH_TEST); glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); win->wireframe=0; wzwShowState(win); return GL_TRUE;}void wzwDrawIntern(glWindow w, void *info);void wzwDraw(glWindow w, void *info) /*{ wzWindow win=(wzWindow)info; while(!win->list_valid) wzwDrawIntern(w,info);}void wzwDrawIntern(glWindow w, void *info)*/{ wzWindow win=(wzWindow)info;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -