版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、Input and Interaction输入与交互原著Ed AngelProfessor of Computer Science, Electrical and Computer Engineering, and Media ArtsUniversity of New Mexico编辑 武汉大学计算机学院图形学课程组ObjectivesIntroduce the basic input devicesPhysical Devices物理设备Logical Devices逻辑设备Input Modes输入模式Event-driven input事件驱动Introduce double buff
2、ering双缓存 for smooth animations平滑动画Programming event input with GLUT用GLUT进行事件输入编程Outline3.1 Interaction 3.2 Input Device3.3 Client and Server3.6 Programming Event-Driven Input 相关内容3.11 Animating Interactive Programs 交互式动画3.11.2 Double Buffering 双缓存3.6.4 Idle callbacks空闲回调的应用3.1 Interaction(Project Sk
3、etchpad项目)Ivan Sutherland (MIT 1963) established the basic interactive paradigm基本交互框架 that characterizes interactive computer graphics:User sees an object on the display看到一个对象User points to (picks) the object with an input device (light pen, mouse, trackball)点选该对象Object changes (moves, rotates, morp
4、hs)对象发生了改变Repeat3.1 Interaction(Interactive Graphics)Graphics :Raster Raster graphics光栅图形学 Interaction重要性Interactive graphics交互式图形学MSRA微软亚洲研究院SIGGRAPH Association for Computing Machinerys Special Interest Group on Computer Graphics and Interactive Techniques GLUT, not OpenGL3.2 Input Device(Graphica
5、l Input图形输入设备)Devices can be described either byPhysical properties物理属性MouseKeyboardTrackballLogical Properties逻辑属性What is returned to program via APIA position位置An object identifier对象标识Modes模式How and when input is obtained如何以及何时获取输入?Request请求(主动) or event或者事件(被动) 3.2.1 Physical Input Devices物理输入设备m
6、ousetrackballlight pendata tabletjoy stickspace ball3.2.1 Physical Input Devices物理输入设备(Incremental (Relative) Devices增量/相对设备)Devices such as the data tablet数据板 return a absolute position绝对位置 directly to the operating systemDevices such as the mouse, trackball, and joy stick return incremental inputs
7、增量输入 (or velocities速率) to the operating systemMust integrate these inputs输入累加 在一起 to obtain an absolute position绝对位置Rotation of cylinders in mouse鼠标滚轮的旋转Roll of trackball跟踪球的滚动Difficult to obtain absolute positionCan get variable sensitivity输入可能相当敏感3.2.2 Logical Devices逻辑设备Consider the C and C+ code
8、C+: cin x;C: scanf (“%d”, &x);What is the input device输入设备?Cant tell from the codeCould be keyboard, file, output from another programThe code provides logical input逻辑输入 A number (an int) is returned to the program regardless of the physical device物理设备3.2.2 Logical Devices逻辑设备(Graphical Logical Devi
9、ces图形逻辑设备)Graphical input is more varied形式更多 than input to standard programs which is usually numbers, characters, or bitsTwo older APIs (GKS, PHIGS) defined six types of logical inputLocator: return a position返回一个位置Pick: return ID of an object返回对象的标识IDKeyboard: return strings of characters返回字符串Stro
10、ke: return array of positions返回一系列位置Valuator: return floating point number返回浮点数Choice: return one of n items返回n项中的一项3.2.3 Input Modes输入模式 (Request Mode请求模式)三种基本模式Request Mode请求模式Sample Mode采样模式Event Mode事件模式3.2.3 Input Modes输入模式 (Request Mode请求模式)Input devices contain a trigger触发板机 which can be used
11、 to send a signal发送一个信息 to the operating systemButton on mouse鼠标上的按钮Pressing or releasing a key按/放键盘上的键When triggered, input devices return information (their measure度量) to the systemMouse returns position information鼠标返回位置信息Keyboard returns ASCII code键盘返回ASCII代码3.2.3 Input Modes输入模式(Request Mode请求模
12、式)Input provided to program only when user triggers触发 the deviceTypical of keyboard input典型例子Can erase (backspace), edit, correct until enter (return) key (the trigger) is depressed按回车键命令行参数Figure 3.8 Request mode3.2.3 Input Modes输入模式(Sample Mode采样模式)Sample Mode采样模式用户程序中遇到了函数调用,则将测量数据返回给程序Instant立即n
13、o triggers没有触发器3.2.3 Input Modes输入模式(Event Mode事件模式)Most systems have more than one input device, each of which can be triggered at an arbitrary time随时 by a userEach trigger generates an event whose measure is put in an event queue事件队列which can be examined by the user program用户程序检查该队列Figure 3.10 Eve
14、nt Mode3.3 Client and Server(X Window Input的输入)The X Window System introduced a client-server model for a network of workstationsClient: OpenGL programGraphics Server: bitmap display位图显示设备 with a pointing device and a keyboardFigure 3.11 Network3.6 Programming event input (Event Types事件类型)Window: re
15、size, expose, iconify缩成图标Mouse: click one or more buttonsMotion: move mouseKeyboard: press or release a keyIdle noneventDefine what should be done if no other event is in queue队列 可以定义如果队列中没有其它事件就可以进行的某种操作3.6 Programming event input (Callbacks回调)Programming interface程序界面 for event-driven inputDefine
16、a callback function for each type of event the graphics system recognizesThis user-supplied function用户指定 is executed when the event occurs当相应的事件出现时,就会自动执行用户指定的函数GLUT example: glutMouseFunc(mymouse)mouse callback function鼠标回调函数3.6 Programming event input (GLUT callbacks中的回调函数)GLUT recognizes a subset
17、 子集 of the events recognized by any particular window system (Windows, X, Macintosh)glutDisplayFunc /显示回调glutMouseFuncglutReshapeFunc /形状改变是的回调glutKeyboardFuncglutIdleFuncglutMotionFuncglutPassiveMotionFunc3.6 Programming event input (GLUT Event Loop事件循环-1)Recall需要记住的是 that the last line in main.c f
18、or a program using GLUT must be最后一行实质语句必须是glutMainLoop();which puts the program in an infinite event loop这条语句使得程序进入一个无穷的事件循环3.6 Programming event input (GLUT Event Loop事件循环-2)In each pass through the event loop, GLUT每经过事件循环一次,GLUT进行下述操作 looks at the events in the queue查看事件队列中的事件for each event in the
19、 queue, GLUT executes the appropriate callback function if one is defined对于在队列中的每个事件,如果定义了相应的回调函数,GLUT就执行这个回调函数if no callback is defined for the event, the event is ignored如果对该事件没有定义回调函数,那么就忽略该事件3.6 Programming event input(The display callback显示回调函数-1)The display callback回调函数 is executed whenever GL
20、UT determines that the window should be refreshed只要GLUT确定需要刷新窗口,那么就会执行显示回调函数When the window is first opened当第一次打开窗口When the window is reshaped改变了窗口形状When a window is exposed重新露出窗口When the user program decides it wants to change the display当用户程序决定需要改变显示内容的时候 /例如动画3.6 Programming event input(The displ
21、ay callback显示回调函数-2)In main.cglutDisplayFunc(mydisplay) identifies the function to be executed确定要执行的显示回调函数Every GLUT program must have a display callback每个GLUT程序都必须有一个显示回调函数,必要时,可以设置为空函数3.6.4 The display and idle callbacks (Posting redisplays标识重新显示-1)Many events may invoke the display callback funct
22、ion许多事件都会导致调用显示回调函数Can lead to multiple executions of the display callback on a single pass through the event loop这会导致遍历一次事件循环的过程中多次执行显示回调函数We can avoid this problem by instead using避免这个问题glutPostRedisplay();3.6.4 The display and idle callbacks (Posting redisplays标识重新显示-2)glutPostRedisplay(); which
23、sets a flag这条语句设置一个标志. GLUT checks to see if the flag is set at the end of the event loop检查是否设置上述标志If set then the display callback function is executed如果设置了标志,那么就会执行显示回调函数3.6.4 The display and idle callbacks(Using the idle callback空闲回调的应用-2)Avoid extra or unnecessary screen drawings by setting s fl
24、ag inside GLUTs main loop在一个循环中避免多余的绘制Indicating that the display needs to be redrawnEnsuring that the display will be drawn only once each time the program goes through the event loop每次循环绘制一次动画实现技术在任何你认为需要重绘的时候,调用glutPostRedisplay配合glutIdleFunc()使用,用glutTimerFunc设置一个定时器3.11 Animating Interactive Pr
25、ograms (Animating a Display动画显示-1)When we redraw the display through the display callback当通过显示回调函数重新绘制显示结果时we usually start by clearing the window我们通常会首先清除整个窗口 glClear()then draw the altered display然后再绘制已发生了变化的显示结果通常的情况3.11 Animating Interactive Programs (Animating a Display动画显示-2)Problem: the drawi
26、ng of information in the frame buffer is decoupled from the display of its contents问题:帧缓冲区中的信息在显示器上的显示结果出现了错位(分离、脱钩、不一致) Graphics systems use dual ported双口 memory图形系统可以同时向显存中写入内容和从中读出内容Hence we can see partially drawn display只会看到部分显示内容See the program single_double.c for an example with a rotating cu
27、be显卡若启动了硬件加速功能,不会发现上述问题,刷新速度大于动画速度3.11 Animating Interactive Programs (Animating a Display动画显示-2)原因: (1)场景图片生成速度慢,没有达到refresh帧率。导致出现部分场景等问题。 (2)场景绘制到帧缓存中与使用硬件重新显示帧缓存中的内容之间不存在同步衔接。3.11.2 Double Buffering双缓存(1)For unchanged contents静止图象 of the buffer, We refresh the frame buffer at 60 to 85 Hz rateFor
28、 animation动画, instead of one color buffer, we use two BuffersFront Buffer前端缓存: one that is displayed but not written 显示/不写Back Buffer后端缓存: one that is written to but not displayed 写/不显示3.11.2 Double Buffering双缓存(2)Program then requests a double buffer in main.c序在main()中请求使用双缓存glutInitDisplayMode(GL_
29、RGB | GL_DOUBLE)At the end of the display callback buffers are swapped在显示回调函数结束之前,交换两个缓冲区void mydisplay()glClear(GL_COLOR_BUFFER_BIT|.)./* draw graphics here */.glutSwapBuffers()3.6.4 The display and idle callbacks(Using the idle callback空闲回调的应用-1)The idle callback is executed whenever there are no
30、events in the event queue当在事件队列中没有事件时,就执行该回调函数 glutIdleFunc(myidle)To continue to generate graphical primitives through a display function通过显示函数连续产生图元Useful for animations在动画中非常有用3.6.4 The display and idle callbacks(Using the idle callback空闲回调的应用-2)void myidle() /* change something */改变一些内容t += dtgl
31、utPostRedisplay();Void mydisplay() glClear();/* draw something that depends on t */根据t绘制图形glutSwapBuffers(); 3.6 Programming event input(Using global variables全局变量的应用-1)The form of all GLUT callbacks is fixed回调函数的调用形式是固定的void mydisplay() /空参数void mymouse(GLint button, GLint state, GLint x, GLint y)
32、/固定参数回调函数的参数如何传递?3.6 Programming event input (Using global variables全局变量的应用-2)Must use global variables to pass information to callbacks必须使用全局变量float t; /*global */void mydisplay()/* draw something that depends on t */* * double.c * This program demonstrates double buffering for * flicker-free animation. The left and middle mouse * buttons start and stop the spinning motion of the square. */#include #ifdef _APPLE_#include #else#include #endIf
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 教学楼室内装修协议模板
- 家庭护理保姆服务合同样本
- 办公空间色彩搭配合同范本
- 咖啡店店员招聘协议书
- 城市文化中心地暖工程承包合同
- 环境保护企业消防整改施工合同
- 化工厂彩钢板翻新合同
- 劳动报酬零花钱协议
- 消防工程发包合同
- 常州乒乓球馆租赁合同
- 汽轮机主汽门活动试验
- 工程质量检测论文范文10篇
- 【真题解析】2023年2月26日河南省直遴选笔试真题(考生回忆版)
- 《企业采购成本控制现状、问题及对策研究-以伊利乳业集团为例(论文)10000字》
- 中华医学会杂志社作者贡献声明
- 国开电大本科《人文英语4》机考总题库珍藏版
- 腮腺疾病围手术期护理查房
- 学生假期安全承诺书200字(5篇)
- 血液透析个案护理两篇
- GB/T 37814-2019综采综放工作面远距离供电系统技术规范
- 高中通用技术《技术试验及其方法》公开课课件
评论
0/150
提交评论