Chapter3Drawing Basic Graphics Primitives基本图元绘制概要1
3.5. Simple Interaction with the mouse and keyboard 鼠标键盘交互 Interactive graphics applications let the user control the flow of a program by natural human motions: pointing and clicking the mouse, and pressing various keyboard keys.交互式图形应用就是让用户通过点击鼠标和键盘来控制程序 Using the OpenGL Utility Toolkit (GLUT) the programmer can register a callback function with each of these events by using the following commands: glutMouseFunc(myMouse) which registers myMouse() with the event that occurs when the mouse button is pressed or released; glutMotionFunc(myMovedMouse) which registers myMovedMouse() with the event that occurs when the mouse is moved while one of the buttons is pressed; glutKeyboardFunc(myKeyboard) which registers myKeyBoard() with the event that occurs when a keyboard key is pressed. 3.4.1. Mouse interaction鼠标交互 (1)callback function myMouse() must take four parameters, the prototype(必须4参数,其原型): void myMouse(int button, int state, int x, int y); value of button will be one of: GLUT_LEFT_BUTTON, GLUT_MIDDLE_BUTTON, or GLUT_RIGHT_BUTTON, value of state will be one of: GLUT_UP or GLUT_DOWN. values x and y are the position of the mouse at the time of the event (2)callback function myMovedMouse() must take two parameters,the prototype (必须2参数,其原型): myMovedMouse(int x, int y); values of x and y are the position of the mouse when the event occurred; Application Framework void main() { // initialize things5 // create a screen window glutDisplayFunc(myDisplay); // register the redraw function glutMouseFunc(myMouse); // register the mouse function glutKeyboardFunc(myKeyboard); // register the keyboard action function ………… glutMainLoop(); // enter the unending main loop } 例:鼠标坐标获取与绘图方法 #include GL/glut.h #include math.h #include stdlib.h GLfloat x = 0.0;GLfloat y = 0.0; GLfloat size = 50.0; GLsizei wh = 500, ww = 500; void drawSquare(GLint x, GLint y)//绘制矩形 { y = wh-y; glBegin(GL_POLYGON); glVertex3f(x + size, y + size, 0); glVertex3f(x - size, y + size, 0); glVertex3f(x
您可能关注的文档
- Chapter 8 establishment of LC and amendment概要1.ppt
- Chapter 7 语言学理论概要1.ppt
- Chapter 9 meaning and context 意义和语境概要1.ppt
- Chapter 8 Poetry Translation精简版课堂用概要1.pptx
- Chapter 9 Sinusoids and Phasors (new)概要1.ppt
- chapter 6 literature概要1.ppt
- chapter 9Cash and Marketable Securities Management(财务管理,Gregory A. Kuhlemeyer)概要1.ppt
- CHAPTER 9longlived assets财务会计概要1.pptx
- Chapter Five概要1.doc
- chapter eight英语笔译概要1.ppt
最近下载
- 2024-2025学年上海市普陀区六年级下学期数学期末试题含详解.pdf VIP
- 制造业企业员工高离职率分析.pdf VIP
- GB50461-2024:石油化工静设备安装工程施工质量验收规范.pptx VIP
- 三江A116火灾报警控制器简易操作规程.docx
- (新版)社会体育指导员理论知识考试题库(含答案).docx VIP
- DB31T 1104-2018 城市轨道交通导向标识系统设计规范.docx VIP
- 2023年浙江省军队转业干部录用考试试题.docx VIP
- 口渴了-朋友帮你.ppt VIP
- Xikong西莱克低温机控制板SHXK814用户手册.pdf
- 爱迪生牛顿大发明攻略.doc VIP
原创力文档

文档评论(0)