资源描述:
《opengl键盘控制及鼠标控制实例》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、1.学习在VisualC卄6.0中安装glut库操作截图:3文件(D«K£)MM・A(DM(B曲⑻TM(D窗匚(W).
2、0
3、x◎cRd»一□同啓刘Jh.CirsorTableclassmembers]^
4、
5、(NomembersCreateC/C**McmbjJ;X■9Z!0Aqlut32classes•F^Criterion•C^CursorTablenF:DhplayMode•;:_FrameBut1ert•C.GLUTcolorce•tX^GLUTcolormiF.GLUTeventPi•Q^GLUTmenu_GLUT
6、menult(F^GLUToverlay•tJ^GLUTstalc•!GLUTtimer2J~•厂tlEK组建/痕在文件1中査找在文件2中査找二结果XSQLDebu“m#include#includeintangle;doublepi=3.1415;voidinit(void){glOrtho(・5“5,5,
7、・:U);〃视野缩放}voiddisplay(void){glClear(GL_COLOR_BU阡ER_BIT);〃清除所有像素glColor3f(l.0,0,0);inti;glPushMatrixf);〃入栈glTranslatef(O,O,O);g-ROartef(ang-e、0pl)jg_Begin(GLIUNEILOOPrg_co_or3f(l、lo);fomuo二Aloooj++i)g_vertex2f(0.5癸cos(2*pwlooo*)o.5*sin(2癸pi'looo*));gmndojg_Begin(G
8、LIL_NEILOOP);g_co_or3f(l、lorfoHll'o二Aloooj++i)g_vertex2f(o.75+0.25*cos(2*pi、一ooo*)o.25癸sin(2*pi、1000*)rgmndo;g_Begin(GL—L_NEILOOP)」g-co-or3f(l、l、0rfor(li*o二C1OO5?++i)g_vertex2f(0.75+0.25癸cos(2*pi、looo*)o.25餐sm(2*pi、1000*)rg_End();g_Begin(GLIL_NEILOOP);g_co_or3f(l、
9、l、0);foruHOJA'loooj++i)g_vertex2f(0.25r?os(2癸pi、1000*)、6.75+0.25关sin(2幕pwooo*));g_End(rg_Begin(GL—UNEILOOP);g_co_or-3f(l、l、orforvojAlooo;++i)g_vertex2f(0.25幕cos(2*pi、looo*)o.75+0.25
10、f(keyHGLUTIKEYILEFT)ang-e+"30;if(keynnGLUTIKEYIR_GHT)angle-=30;glutPostRedisplay();//重新调用绘制函数}voidmymouse(intbutton,!ntstate,intx,inty){if(state==GLUT_DOWN){if(button==GLUT_LEFT_BUTTON){glTranslatef(-0.5,0,0);〃左移}elseiffbutton二二GLUT_RIGHT_BUTTON){glTranslatef(0.5,
11、0,0);//右移}glutPostRedisplay();//重新调用绘制函数}return;}voidmain(intargc,char**argv){glutlnit(&argc,argv);//初始化工具包glutlnitDisplayMode(GLUT_SINGLE
12、GLUT_RGB);//设置显式模式glutlnitWindowSize(640,480);//设置窗口大小glutlnitWindowPosition(100,150);//设置窗口位置glutCreateWindow("旋转平移”);//创建屏幕
13、窗口init();glutMouseFuncf&mymouse);//调用鼠标响应函数glutDisplayFunc(display);//注册绘制函数glutSpecialFunc(&Keyboard);//调用键盘回调函数glutMainLoop();//进入主循环}运行结果:初始位置:当按下键盘一