




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、Better Interactive Programs更好交互程序設(shè)計原著Ed AngelProfessor of Computer Science, Electrical and Computer Engineering, and Media ArtsUniversity of New Mexico編輯 武漢大學計算機學院圖形學課程組Objectives and outlineLearn to build more sophisticated interactive programs using Picking選取 section 3.8 PickingSelect objects from
2、 the display從顯示結(jié)果中選擇對象Three methods三種方法Logic Operations邏輯運算 section 3.13Rubberbanding橡皮條Interactive drawing of lines and rectangles直線與矩形的交互繪制方法Display Lists顯示列表section 3.4 Display ListsRetained mode graphics圖形的記憶模式保留模式3.8 Picking選取(1)Identify a user-defined object on the display從顯示結(jié)果中識別用戶定義的對象In pri
3、nciple, it should be simple becauseThe mouse gives the position and We should be able to determine to which object(s) a position corresponds原則上說要達到這個目標是很簡單的,因為鼠標可以提供位置信息,我們因當能夠根據(jù)位置確定對應(yīng)的是哪個對象3.8 Picking選取(2)Practical difficulties實際操作中的困難Pipeline architecture is feed forward, hard to go from screen ba
4、ck to world流水線式的圖形體系是單向的,很難從二維屏幕返回到三維世界Complicated by screen being 2D, world is 3D二維屏幕,三維世界,也使問題變得復雜How close do we have to come to object to say we selected it?離位置多近可以認為選擇了對象?3.8 Picking選取(Three Approaches三種方法-1) 第一種方法Hit list擊中(hit)列表Most general approach but most difficult to implement最一般性的方法,實現(xiàn)也
5、最困難OpenGL supports this approach OpenGL支持本ppt主要介紹的3.8 Picking選取(Three Approaches三種方法-2)第二種方法Rectangular maps矩形映射Easy to implement for many applications容易實現(xiàn)See paint program in text3.8 Picking選取(Three Approaches三種方法-3)第三種方法Use back or some other buffer to store object ids as the objects are rendered當
6、繪制對象時,利用后緩沖區(qū)或者其它緩沖區(qū)存貯對象的標識第一種方法3.8.1 Picking and Selection Model(Rendering Modes顯示輸出模式-1)OpenGL can render in one of three modes selected by glRenderMode(mode) mode)可以設(shè)置OpenGL用下述三種模式顯示內(nèi)容GL_RENDER: normal rendering to the frame buffer (default)正常顯示到幀緩沖區(qū)中(缺省模式)第一種方法3.8.1 Picking and Selection Model(Re
7、ndering Modes顯示輸出模式-2)GL_FEEDBACK: provides list of primitives rendered but no output to the frame buffer提供要顯示的幾何列表,但并不輸出到幀緩沖區(qū)中GL_SELECTION: Each primitive in the view volume generates a hit record that is placed in a name stack which can be examined later在視景體中的每個幾何體創(chuàng)建一個擊中記錄,這個記錄放到名稱堆棧中,稍后要被檢測第一種方法3
8、.8.1 Picking and Selection Model(Selection Mode Functions選擇模式中用到的函數(shù))glSelectBuffer(): specifies name buffer指定名稱緩沖區(qū)glInitNames(): initializes name buffer初始化名稱緩沖區(qū)glPushName(id): push id on name buffer把id放到名稱緩沖區(qū)中g(shù)lPopName(): pop top of name buffer把名稱緩沖區(qū)頂部的名稱彈出glLoadName(id): replace top name on buffer取
9、代在名稱緩沖區(qū)頂部的名稱id is set by application program to identify objectsid是由應(yīng)用程序設(shè)置,用以識別對象第一種方法3.8.1 Picking and Selection Model (Using Selection Mode選擇模式的應(yīng)用)Initialize name buffer初始化名稱緩沖區(qū)Enter selection mode (using mouse)進入選擇模式(例如:應(yīng)用鼠標)Render scene with user-defined identifiers顯示輸出場景,場景中對象具有用戶指定的標識Reenter n
10、ormal render mode重新進入正常的顯示輸出模式This operation returns number of hits該操作返回擊中對象個數(shù)Examine contents of name buffer (hit records)檢查名稱緩沖區(qū)的內(nèi)容(擊中記錄)Hit records include id and depth information擊中記錄包含id與深度信息第一種方法3.8.1 Picking and Selection Model (Selection Mode and Picking選擇模式與選取)As we just described it, selec
11、tion mode wont work for picking because every primitive in the view volume will generate a hit在選擇模式中不能進行選取,因為這時在視景體中的每個對象都會生成一個擊中記錄/如何理解,見程序例子,調(diào)大gluPickMatrix參數(shù)Change the viewing parameters so that only those primitives near the cursor are in the altered view volume改變視圖參數(shù),使得只有靠近鼠標指針的對象位于新的視景體中Use gl
12、uPickMatrix (see text for details)第二種方法Using Regions of the Screen應(yīng)用屏幕上的區(qū)域Many applications use a simple rectangular arrangement of the screen在許多應(yīng)用程序中,屏幕采用簡單的矩形分劃Example: paint/CAD programEasier to look at mouse position and determine which area of screen it is in than using selection mode picking這時
13、,相比于應(yīng)用選擇模式進行選取而言,通過查看鼠標位置,確定屏幕的區(qū)域就更簡單了drawing areatoolsmenus第三種方法Using another buffer and colors for picking通過另外的緩沖區(qū)和顏色進行選取-1For a small number of objects, we can assign a unique color (often in color index mode) to each object對于很少數(shù)目的對象,可以給每個對象賦以唯一的顏色(有時是在顏色索引模式中)We then render the scene to a color
14、buffer other than the front buffer so the results of the rendering are not visible然后把場景輸入到不是前緩沖區(qū)的一個顏色緩沖區(qū)中,這樣就不會看到顯示出來的結(jié)果第三種方法Using another buffer and colors for picking通過另外的緩沖區(qū)和顏色進行選取-2We then get the mouse position and use glReadPixels() to read the color in the buffer we just wrote at the position
15、 of the mouse然后獲到鼠標位置,讀取緩沖區(qū)中的顏色The returned color gives the id of the object根據(jù)返回的顏色確定是哪個對象Back buffer is not displayed后緩沖區(qū)不可見3.13 Logic Operations(Writing Modes像素的寫入模式-1)Writing mode寫入模式Copy復制模式(or replacement替換 )Exclusive OR異或模式 (or XOR)Source pixel源像素Destination pixel目標像素3.13 Logic Operations(Writ
16、ing Modes像素的寫入模式-2)frame buffer幀緩沖區(qū)applicationbitwise logical operation逐位邏輯操作3.13 Logic Operations(XOR write寫入模式-1)Usual (default) mode: source replaces destination (d = s)缺省的寫入模式是直接用源像素取代目標像素即d=sCannot write temporary lines this way because we cannot recover what was “under” the line in a fast simp
17、le way用這種方法不能繪制一條臨時直線,因為我們不能用快速簡單的方法恢復在臨時直線下面的內(nèi)容3.13 Logic Operations(XOR write寫入模式-2)Exclusive OR mode異或模式 (XOR) (d = d s)相同值為0,不同值為1x y x =yd = (d s) sHence, if we use XOR mode to write a line, we can draw it a second time and line is erased!因此如果應(yīng)用XOR模式畫一條直線,那么只要在原地再畫一遍這條直線就可以刪除這條直線3.13 Logic Oper
18、ations (Rubberbanding橡皮條式繪圖-1)Switch to XOR write mode切換到XOR寫入模式Draw object繪制對象For line can use first mouse click to fix one endpoint and then use motion callback to continuously update the second endpoint利用第一次單擊鼠標固定線段的一個端點,然后再利用鼠標移動的回調(diào)函數(shù)連續(xù)更新第二個端點3.13 Logic Operations (Rubberbanding橡皮條式繪圖-2)Each tim
19、e mouse is moved, redraw line which erases it and then draw line from fixed first position to new second position每次鼠標移動的時候,重繪一遍原來的直線從而刪除它,然后再從固定的第一個端點到新的第二個端點之間再畫一條直線At end, switch back to normal drawing mode and draw line最后切換回到正常的繪圖模式并繪制直線Works for other objects: rectangles, circles也適用于其它對象:矩形、圓223
20、.13 Logic Operations (Rubberband Lines橡皮條型直線)initial display初始顯示結(jié)果draw line with mouse in XOR mode用XOR模式畫一條直線mouse moved to new position移到新的位置first point第一個點second point第二個點original line redrawn with XOR利用XOR重畫原來的直線new line drawn with XOR新的直線利用XOR畫出來3.13 Logic Operations (XOR in OpenGL中的邏輯操作)There a
21、re 16 possible logical operations between two bits在兩位之間有16種可能的邏輯操作All are supported by OpenGL支持所有的這16種操作Must first enable logical operations必須首先啟動邏輯操作glEnable(GL_COLOR_LOGIC_OP)Choose logical operation然后選擇邏輯操作類型glLogicOp(GL_XOR)glLogicOp(GL_COPY) (default默認值)3.4 Display Lists顯示列表(Immediate and Retai
22、ned Modes快速(立即)模式與記憶(保留)模式-1)Recall that in a standard OpenGL program, once an object is rendered there is no memory of it and to redisplay it, we must re-execute the code for it在標準的OpenGL程序中,一旦某個對象被顯示輸出,對它沒有任何記憶;為了重新顯示它,需要再執(zhí)行一次相應(yīng)的代碼Known as immediate mode graphics這就是快速(立即)模式(immediate mode)的圖形Can b
23、e especially slow if the objects are complex and must be sent over a network如果對象相當復雜,而且通過網(wǎng)絡(luò)傳輸,那么這就可能導致系統(tǒng)非常慢3.4 Display Lists顯示列表(Immediate and Retained Modes快速(立即)模式與記憶(保留)模式-2)Alternative is define objects and keep them in some form that can be redisplayed easily另外一種模式就是首先定義對象,然后以某種形式把它記憶下來,從而更容易重新
24、顯示Retained mode graphics這就是記憶模式(retained mode)的圖形 plished in OpenGL via display lists在OpenGL中是通過顯示列表實現(xiàn)的3.4 Display Lists顯示列表Conceptually similar to a graphics file概念上類似于圖形文件Must define (name, create)必須首先定義列表的名稱并創(chuàng)建它Add contents向列表中添加內(nèi)容Close關(guān)閉列表In client-server environment, display list is placed on s
25、erver在客戶-服務(wù)的體系環(huán)境中,顯示列表是放在服務(wù)器(顯示服務(wù)器)一方Can be redisplayed without sending primitives over network each time這樣不必通過網(wǎng)絡(luò)每次發(fā)送原來的幾何定義就可以重新顯示3.4 Display Lists顯示列表(Display List Functions顯示列表中用到的函數(shù))Creating a display list創(chuàng)建顯示列表GLuint id;void init() id = glGenLists( 1 ); glNewList( id, PILE ); /*other OpenGL routines繪圖子程序或者命令*/ glEndList();Call a created list調(diào)用已創(chuàng)建的顯示列表v
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年中國高分子無塵紙行業(yè)市場發(fā)展前景及發(fā)展趨勢與投資戰(zhàn)略研究報告
- 2025年印花座便套行業(yè)深度研究分析報告
- 2025年中國中式快餐連鎖行業(yè)市場全景監(jiān)測及投資前景展望報告
- 科技企業(yè)如何應(yīng)對網(wǎng)絡(luò)安全挑戰(zhàn)與教育員工策略
- 2025年中國電鍍口琴市場調(diào)查研究報告
- 2025年中國燒杯市場調(diào)查研究報告
- 2025年中國沙灘折疊桌椅市場調(diào)查研究報告
- 車子委托轉(zhuǎn)讓合同范本
- 2025年中國棉滌綸布市場調(diào)查研究報告
- 2025年中國有機系過濾膜市場調(diào)查研究報告
- 《電商直播》 課件 項目一 走入電商直播
- 《中國宮腔鏡診斷與手術(shù)臨床實踐指南(2023版)》解讀課件
- GB/T 9535-1998地面用晶體硅光伏組件設(shè)計鑒定和定型
- 湖南省陽氏宗親分布村落
- 八年級數(shù)學(上冊)整式計算題練習100道無答案_新人教版
- 豐田卡羅拉電路圖介紹
- 中考語文十大專題總復習資料
- 汽車駕駛員專業(yè)競賽實施方案
- 知乎的SWOT分析(表格)
- 常用家電維修基礎(chǔ)知識(課堂PPT)
- 楊氏太極拳37式拳譜
評論
0/150
提交評論