九九热最新网址,777奇米四色米奇影院在线播放,国产精品18久久久久久久久久,中文有码视频,亚洲一区在线免费观看,国产91精品在线,婷婷丁香六月天

歡迎來(lái)到裝配圖網(wǎng)! | 幫助中心 裝配圖網(wǎng)zhuangpeitu.com!
裝配圖網(wǎng)
ImageVerifierCode 換一換
首頁(yè) 裝配圖網(wǎng) > 資源分類 > PPT文檔下載  

人教小學(xué)信息第二冊(cè)《圖形變換》PPT課件.ppt

  • 資源ID:22718955       資源大?。?span id="24d9guoke414" class="font-tahoma">1.10MB        全文頁(yè)數(shù):122頁(yè)
  • 資源格式: PPT        下載積分:14.9積分
快捷下載 游客一鍵下載
會(huì)員登錄下載
微信登錄下載
三方登錄下載: 微信開(kāi)放平臺(tái)登錄 支付寶登錄   QQ登錄   微博登錄  
二維碼
微信掃一掃登錄
下載資源需要14.9積分
郵箱/手機(jī):
溫馨提示:
用戶名和密碼都是您填寫(xiě)的郵箱或者手機(jī)號(hào),方便查詢和重復(fù)下載(系統(tǒng)自動(dòng)生成)
支付方式: 支付寶    微信支付   
驗(yàn)證碼:   換一換

 
賬號(hào):
密碼:
驗(yàn)證碼:   換一換
  忘記密碼?
    
友情提示
2、PDF文件下載后,可能會(huì)被瀏覽器默認(rèn)打開(kāi),此種情況可以點(diǎn)擊瀏覽器菜單,保存網(wǎng)頁(yè)到桌面,就可以正常下載了。
3、本站不支持迅雷下載,請(qǐng)使用電腦自帶的IE瀏覽器,或者360瀏覽器、谷歌瀏覽器下載即可。
4、本站資源下載后的文檔和圖紙-無(wú)水印,預(yù)覽文檔經(jīng)過(guò)壓縮,下載后原文更清晰。
5、試題試卷類文檔,如果標(biāo)題沒(méi)有明確說(shuō)明有答案則都視為沒(méi)有答案,請(qǐng)知曉。

人教小學(xué)信息第二冊(cè)《圖形變換》PPT課件.ppt

第三講 圖形變換 圖形變換是計(jì)算機(jī)圖形學(xué)的基礎(chǔ)內(nèi)容。 有二維(三維)圖形的平移、旋轉(zhuǎn)、變 比、對(duì)稱等變換,三維圖形的投影透視 變換等。 第 6講 圖形變換 二維幾何變換 基本變換與復(fù)合變換 三維幾何變換 基本變換與復(fù)合變換 本講主要內(nèi)容 圖形變換的數(shù)學(xué)基礎(chǔ) 二維圖形的基本變換、復(fù)合(組合)變 換; 三維圖形基本變換、復(fù)合(組合)變換; 平行投影 透視投影 圖形變換的數(shù)學(xué)基礎(chǔ) 矢量運(yùn)算 矩陣運(yùn)算 矩陣 單位矩陣 逆矩陣 轉(zhuǎn)置矩陣 行列式 上機(jī)編程,實(shí)現(xiàn)兩個(gè)矩陣相乘 特別注意: 矩陣相乘不適合交換律 變換的數(shù)學(xué)基礎(chǔ) (1/4) 矢量 矢量和 z y x u u u U z y x v v v V zz yy xx vu vu vu VU 變換的數(shù)學(xué)基礎(chǔ) (2/4) 矢量的數(shù)乘 矢量的點(diǎn)積 性質(zhì) z y x ku ku ku Uk zzyyxx vuvuvuVU UVVU VUVU 0 00 UUU 變換的數(shù)學(xué)基礎(chǔ) (3/4) 矢量的長(zhǎng)度 單位矢量 矢量的夾角 矢量的叉積 222 zyx uuuUUU VU VU c o s zyx zyx vvv uuu kji VU 變換的數(shù)學(xué)基礎(chǔ) (4/4) 矩陣 階矩陣 n階方陣 零矩陣 行向量與列向量 單位矩陣 矩陣的加法 矩陣的數(shù)乘 矩陣的乘法 矩陣的轉(zhuǎn)置 矩陣的逆 m n 齊次坐標(biāo) 用 n+1維向量表示 n維向量 優(yōu)越性 提供了用矩陣運(yùn)算把二維三維甚至高維 空間的點(diǎn)集從一個(gè)坐標(biāo)系變換到另一個(gè) 坐標(biāo)系的方法。 可以表示無(wú)窮遠(yuǎn)的點(diǎn) 圖形幾何變換 基本原理: 按某種規(guī)律,改變圖形的形狀、大小、位置 等 方法: 坐標(biāo)系不動(dòng),圖形變動(dòng)后坐標(biāo)值變化; 坐標(biāo)系變化后圖形在新坐標(biāo)系中的新值。 二 . 圖形變換的過(guò)程 建立物體的 WC 變換到 VC 在 VC空間 進(jìn)行裁剪 投影到 NDC 變換到 DC 在圖形設(shè)備 上輸出 三 . 圖形變換的特點(diǎn) 圖形變換就是改變圖形的幾何關(guān)系,即改變圖形頂點(diǎn)的坐 標(biāo),但圖形的拓?fù)潢P(guān)系不變。 最基本的圖形變換可以分別用矩陣形式表示為: 平移變換 P P Tm Tm Mx My Mx、 My分別為 X方 向和 Y方向的平移量 。 比例變換 P P Ts Sx 0 0 Sy Sx、 Sy分別表示比例因子 。 旋轉(zhuǎn)變換 P P Tr cos sin -sin cos 0時(shí)為逆時(shí)針旋轉(zhuǎn) 0時(shí)為順時(shí)針旋轉(zhuǎn) Ts Tr 四 . 齊次坐標(biāo) 從形式上來(lái)說(shuō),用一個(gè)有 n+1個(gè)分量的向量去表示一個(gè)有 n 個(gè)分量的向量的方法稱為齊次坐標(biāo)表示。 例如二維平面上的點(diǎn) (x, y)的齊次坐標(biāo)表示為 (h x, h y, h), h是任 一不為 0的比例系數(shù)。 給定一個(gè)點(diǎn)的齊次坐標(biāo)表示 : (x, y, h), 該 點(diǎn)的二維笛卡兒直角坐標(biāo): (x / h, y / h)。 同樣 , 對(duì)于一個(gè)三維空間的向量 (x, y, z), 它在四維空間中對(duì)應(yīng)的向量 即齊次坐標(biāo)為 (x h, y h, z h, h), 其中 h 0。 齊次坐標(biāo)的概念可以推廣到 n維空間的向量 。 齊次坐標(biāo)的表示不是唯一的 , 通常當(dāng) h=1時(shí) , 稱為 規(guī)格化齊次坐標(biāo) 。 為什么需要齊次坐標(biāo)? 多個(gè)變換作用于多個(gè)目標(biāo) 變換合成 變換合成的問(wèn)題 引入齊次坐標(biāo) 變換的表示法統(tǒng)一 齊次坐標(biāo)表示的優(yōu)點(diǎn): 可方便地用變換矩陣實(shí)現(xiàn)對(duì)圖形的變換; 齊次坐標(biāo)表示法可以表達(dá)無(wú)窮遠(yuǎn)點(diǎn) 。 齊次坐標(biāo) 二維圖形變換矩陣 一般形式 : a b p c d q l m s P = P T2D (二維仿射變換 : p=q=0) 二維變換矩陣中 : a b c d l m 是對(duì)圖形進(jìn)行平移變換。 S 是整體比例變換。 (非仿射變換) p,q 用于投影變換(三維點(diǎn)時(shí)使用) x y 1 = x y 1 是對(duì)圖形進(jìn)行縮放 、 旋轉(zhuǎn) 、 對(duì)稱 、 錯(cuò)切等變換 。 二維圖形變換 采用齊次坐標(biāo)可將二維圖形變換表示成如下形式 : a b 0 c d 0 l m 1 P = P M 二維變換矩陣中 : a b c d l m 是對(duì)圖形進(jìn)行平移變換 x y 1 = x y 1 變換后的 頂點(diǎn)坐標(biāo) 變換前的 頂點(diǎn)坐標(biāo) 二維變換矩陣 是對(duì)圖形進(jìn)行縮放 、 旋轉(zhuǎn) 、 對(duì)稱 、 錯(cuò)切等變換 。 二維基本幾何變換 點(diǎn)的變換: 恒等變換 平移變換 比例變換 旋轉(zhuǎn)變換 對(duì)稱變換 錯(cuò)切變換 平移變換 只改變圖形的位置 , 不改變圖形的大 小和形狀 二維:將圖形對(duì)象從一個(gè)位置 (x, y) 移到另一個(gè)位置 (x , y )的變換。 P = P T 1 0 0 0 1 0 dx dy 1 T(dx, dy ) = 平移矩陣 1 0 0 0 1 0 dx - dy 1 T-1 (dx, dy ) = 平移變換 (x, y) (x, y) (dx, dy) x y d y y d x x y x 比例變換 比例矩陣 P = PS sx 0 0 0 sy 0 0 0 1 S (sx, sy ) = 1/sx 0 0 0 1/sy 0 0 0 1 S-1 (sx, sy ) = 比例變換示例 (x, y) (x, y) x y 比例變換 比例 因子 if sx , sy 1, 物體被拉伸 if 0 sx , sy 1, 物體被壓縮 if sx , sy 0,物體被倒影 均勻 /非均勻 比例變換 if sx = sy ,均勻 比例變換 if sx sy , 非均勻 比例變換 旋轉(zhuǎn)變換 x y f (x, y) (x, y) 旋轉(zhuǎn)變換 Remember - 旋轉(zhuǎn)方向 - 旋轉(zhuǎn)角度 - 旋轉(zhuǎn)中心 - 旋轉(zhuǎn)是剛體變換 x P(x, y) P (x, y) y 旋轉(zhuǎn)變換 點(diǎn) P(x,y)的極坐標(biāo)表示 繞坐標(biāo)原點(diǎn)旋轉(zhuǎn)角度 ( 逆時(shí)針為正 , 順時(shí)針 為負(fù) ) P = P R cos sin 0 -sin cos 0 0 0 1 R( ) = 旋轉(zhuǎn)矩陣 cos -sin 0 sin cos 0 0 0 1 R-1 ( ) = 對(duì)稱變換 對(duì)稱變換 關(guān)于 x軸的對(duì)稱變換 關(guān)于 y軸的對(duì)稱變換 100 010 001 xSY 100 010 001 ySY 對(duì)稱變換 對(duì)稱變換 關(guān)于原點(diǎn)的對(duì)稱變換 關(guān)于 y=x的對(duì)稱變換 關(guān)于 y=-x的對(duì)稱變換 100 010 001 SO 100 001 010 xySY 100 001 010 xySY 錯(cuò)切變換 以 y軸為依賴軸的錯(cuò)切變換 y坐標(biāo)不變 100 01 001 11* bxyyx yy byxx 點(diǎn)的基本幾何變換的推廣 點(diǎn)的變換: 直線的變換 多邊形的變換 曲線的變換(由每一點(diǎn)的變換,重新畫(huà)線完成) 二維仿射變換 x=ax+by+m y =cx+dy+n P = P T 二維復(fù)合變換(組合變換) 任何一復(fù)雜的幾何變換可以看成基本集合 變換的組合: P = PT = P T1 T2 Tn 復(fù)合平移 復(fù)合比例 復(fù)合旋轉(zhuǎn) 其他常見(jiàn)復(fù)合變換 相對(duì)于某個(gè)參考點(diǎn)的幾何變換(比例、旋轉(zhuǎn)等) 相對(duì)于某直線的幾何變換(對(duì)稱等) 相對(duì)于某個(gè)參考點(diǎn)的幾何變換(比例、 旋轉(zhuǎn)等) 求某點(diǎn) P相對(duì)于固定點(diǎn) F( xF,yY)旋轉(zhuǎn)一 個(gè)角度 的變換矩陣 T。 步驟: 將固定點(diǎn)移到坐標(biāo)原點(diǎn)上; 對(duì)原點(diǎn)進(jìn)行二維旋轉(zhuǎn)變換; 反平移固定點(diǎn)到原位。 例:求 P(5,4)繞 F(3,2)逆時(shí)針旋轉(zhuǎn) 45度的 變換矩陣,以及變換后 P點(diǎn)的新坐標(biāo) P。 相對(duì)于某直線的幾何變換(對(duì)稱等) 步驟 平移該對(duì)稱直線到原點(diǎn); 旋轉(zhuǎn)角度到與坐標(biāo)軸( X軸或 Y軸)重合; 對(duì)變換對(duì)象進(jìn)行對(duì)稱變換; 反向旋轉(zhuǎn)到原來(lái)方向; 反平移到原來(lái)位置。 關(guān)于任意軸的對(duì)稱變換 課堂練習(xí)(一) 回答下列問(wèn)題: 1. 什么是齊次坐標(biāo)?為什么要用規(guī)范化的齊 次坐標(biāo)? 2. 什么是二維仿射變換?有哪些不變性?寫(xiě) 出它的變換形式(用矩陣表示) 課堂練習(xí)(二) 證明題 1. 證明兩個(gè)連續(xù)的旋轉(zhuǎn)變換(或變比例變換) 的矩陣運(yùn)算具有互換性。 如,兩個(gè)二維旋轉(zhuǎn) 變換 R(1 ), R ( 2 ),具有下式 R(1 )R ( 2 ) = R(1 +2 ) 。 2. 證明二維點(diǎn)相對(duì)于 X軸作對(duì)稱,緊跟著相 對(duì)于 y=-x直線作對(duì)稱變換,完全等價(jià)于該 點(diǎn)相對(duì)于坐標(biāo)原點(diǎn)作旋轉(zhuǎn)變換(旋轉(zhuǎn)角度 是多少?) 課堂練習(xí)(三) 推導(dǎo)題 1. 試推導(dǎo)將二維平面上任意直線段 P1( x1,y1)與 P1 ( x1,y1),轉(zhuǎn)換成與 X軸重合的變換矩陣(線段 P1P2與 X軸的夾角小于 45度)。 2. 求 P點(diǎn)相對(duì)于 L: ax+by+c=0,作對(duì)稱變換后得到的 P。例如: 已知點(diǎn) P( 8, 12),直線 L的方程為: x-2y+6=0, 請(qǐng)推導(dǎo)并計(jì)算該點(diǎn)相對(duì)于作對(duì)稱變換的矩陣 T,使 點(diǎn) P的對(duì)稱點(diǎn) P=PT,并求出該點(diǎn)坐標(biāo)值。 Y X O 已知點(diǎn) P( 8, 12),直線 L的方程為: x-2y+6=0, 請(qǐng)推導(dǎo)并 計(jì)算 P相對(duì)于 L作對(duì)稱變換的矩陣 T,并求出該點(diǎn)坐標(biāo)值。 三維圖形變換 坐標(biāo)系 右手法則 拇指指向坐標(biāo)軸 Z的方向, 其余四指指向旋轉(zhuǎn)方向 Y Z X 0 逆時(shí)針為正 三維圖形變換 三維空間點(diǎn)的齊次坐標(biāo)矩陣( x y z 1) x y z 1 = x y z 1 T 三維圖形變換 三維變換矩陣可表示為 : a b c p d e f q g h i r l m n s 其中 : a b c d e f 產(chǎn)生比例 、 錯(cuò)切 、 鏡象和旋轉(zhuǎn)等基本變換 。 g h i l m n 產(chǎn)生沿 x、 y、 z三軸方向上的平移變換。 p q 產(chǎn)生透視變換 。 r s 產(chǎn)生等比例縮放變換 。 T = 三維圖形變換中要 注意 的幾個(gè)問(wèn)題: 1. (三維 )采用 s 來(lái)實(shí)現(xiàn) 整體的比例 變換。 當(dāng) |s | 1 時(shí),三維圖形整體等比例縮小。 2.(三維 )對(duì)稱 變換是 相對(duì)于各個(gè)坐標(biāo)平面 進(jìn)行的。 3.(三維 )旋轉(zhuǎn) 變換是指 繞坐標(biāo)軸 的旋轉(zhuǎn)。 右手坐標(biāo)系下,繞坐標(biāo)軸逆時(shí)針為正 順時(shí)針旋轉(zhuǎn)為負(fù)。 4.三維圖形的級(jí)聯(lián) (組合 )變換 對(duì)于復(fù)雜的三維圖形變換,也需要通過(guò)若干個(gè)變換矩陣 的級(jí)聯(lián)才能實(shí)現(xiàn)。特別注意 : 變換的方法 和 矩陣級(jí)聯(lián)的順序。 三維幾何變換 平移變換 (相對(duì)于原點(diǎn))比例變換 1 0100 0010 0001 ),( zyx zyx ttt tttT 1 0 0 0 0 0 0 0 0 0 0 0 0 z y x s s s ( ) , , z y x s s s S 三維幾何變換 對(duì)稱變換 只考慮關(guān)于坐標(biāo)平面的對(duì)稱變換 關(guān)于 xy平面對(duì)稱 關(guān)于 yz平面對(duì)稱 關(guān)于 xz平面對(duì)稱 1 0 0 0 0 0 0 0 0 0 0 0 0 -1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 -1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 -1 1 錯(cuò)切變換 變換矩陣為: 三維錯(cuò)切變換矩陣 : 1 b c 0 d 1 f 0 g h 1 0 0 0 0 1 其中 : b=c=f=h=0, 沿 X方向產(chǎn)生錯(cuò)切 T = 三維幾何變換 旋轉(zhuǎn)變換 需要指定旋轉(zhuǎn)角度和旋轉(zhuǎn)軸 . y x z rotation axis (x, y, z) (x, y, z) 三維幾何變換 旋轉(zhuǎn)變換 繞 x軸 1000 0c o ss in0 0s inc o s0 0001 )( xR (x, y, z) (x, y, z) x y z 三維幾何變換 旋轉(zhuǎn)變換 繞 y軸 1000 0c o ss in 0010 0s in0c o s )( yR (x, y, z) (x, y, z) x y z 三維幾何變換 繞 z軸 1000 0100 00c o ss in 00s inc o s )( zR x z (x, y, z) (x, y, z) 幾點(diǎn)說(shuō)明 1) 平移變換只改變圖形的位置 , 不改變圖形的大小和形狀; 2) 旋轉(zhuǎn)變換保持圖形各部分間的線性關(guān)系和角度關(guān)系 , 變換后直 線的長(zhǎng)度不變; 3) 比例變換可改變圖形的大小和形狀; 4) 錯(cuò)切變換引起圖形角度關(guān)系的改變 , 甚至導(dǎo)致圖形發(fā)生崎變; 5) 拓?fù)洳蛔兊膸缀巫儞Q不改變圖形的連續(xù)關(guān)系和平行關(guān)系; 三維復(fù)合變換 實(shí)際的圖形對(duì)象的變換往往是由多個(gè)簡(jiǎn)單變 換復(fù)合而來(lái)。將相關(guān)的簡(jiǎn)單變換的變換矩陣乘 起來(lái)就可得到復(fù)合變換的變換矩陣。 例:求基于參考點(diǎn)( xf, yf, zf)的比例變換, 變換方法步驟: 1)通過(guò)平移變換將參考點(diǎn)移到原點(diǎn),使原點(diǎn) 與參考點(diǎn)重合; 2)相對(duì)于原點(diǎn)進(jìn)行比例變換; 3)通過(guò)平移變換將參考點(diǎn)移原來(lái)位置; 繞空間任意軸的三維旋轉(zhuǎn)變換。 例:有空間任意軸 AB(用點(diǎn) A: xA,yA,zA,方向數(shù) a,b,c 表示),現(xiàn)有空間點(diǎn) P( x,y,z)繞 AB軸旋轉(zhuǎn) 角后為 P ( x ,y ,z ),求該變換矩陣。方法步驟: 1)平移 AB軸與原點(diǎn)重合; 2)AB繞 X軸旋轉(zhuǎn) 角 ,使之落到 ZX平面上; 3)將 AB繞 Y軸旋轉(zhuǎn) 角 ,使之與 Z軸重合; 4)此時(shí) AB與 Z軸重合,繞 Z軸 旋轉(zhuǎn) 角 ; 5)繞 X軸反旋轉(zhuǎn) -角 ; 6)繞 X軸反旋轉(zhuǎn) -角 ; 7)反平移 。 預(yù)備知識(shí):方向數(shù)與各坐標(biāo)軸、 坐標(biāo)平面的關(guān)系(夾角、投影等) B點(diǎn)的方向數(shù) 為( 2, 3, 4) Y X Z 繞 X軸旋轉(zhuǎn) 角; 繞 Y軸旋轉(zhuǎn) 角。 習(xí) 題 7、在坐標(biāo)系 oxyz中,求一個(gè)變換將 P(1,1,1)Q(2,2,2)變換到 z軸上: P在坐標(biāo)原 點(diǎn), Q在 z軸正半軸。(方向數(shù)為:?) x y z P Q o x y z Q o(P) M 隨堂練習(xí) 1. 寫(xiě)出三維基本幾何變換的逆變換; 2. (教材 P213)將圖 7-40中的物體 ABCDEFGH進(jìn)行如 下變換:平移使 C點(diǎn)與 P( 1, -1, 0)重合,然后繞 Z 軸旋轉(zhuǎn) 60度。 3. 將圖 7-41中的空間四面體進(jìn)行關(guān)于 P點(diǎn)的整體放大, 試寫(xiě)出變換矩陣。 4. 假定空間直線 AB兩端點(diǎn)坐標(biāo)為 A(0,0,0)B(2,2,2),試 寫(xiě)出繞 AB軸旋轉(zhuǎn) 30度的三維復(fù)合變換矩陣。 5. *在右手坐標(biāo)系中,從原點(diǎn)到 P( x,y,z)給出一直線, 用三種方法將此直線旋轉(zhuǎn)到正的軸線上,并用代數(shù) 證明所得的結(jié)果等價(jià)。 a. 先繞 X軸旋轉(zhuǎn)到 XZ平面上,再繞 Y軸到 Z軸上; b. 先繞 Y軸旋轉(zhuǎn)到 YZ平面上,再繞 X軸到 Z軸上; c. 先繞 Z軸旋轉(zhuǎn)到 XZ平面上,再繞 Y軸到 Z軸上 . 二維圖形的顯示流程圖 繞繞任意點(diǎn)的旋轉(zhuǎn) x P(x, y) P (x, y) V = (Vx, Vy) y 1. 平移 P點(diǎn)經(jīng)過(guò)矢量 -V. 2. 繞原點(diǎn)旋轉(zhuǎn) . 3. 將 P點(diǎn)平沿矢量 V移回; Coordinate Transformations We can think about, alternatively, a transformation is as a change of coordinate systems. (x,y) (x,y) (dx, dy) (x, y) (dx, dy) Coordinate Transformations Objects are usually defined in theirs own local coordinate system. We wish to express these objects coordinates in a single, global coordinate. Object Coordinates World Coordinates Screen Coordinates Object Coordinates Objects are usually defined in their own local coordinate system. World Coordinates Represent these objects coordinates in a single, global coordinate. Screen Coordinates Finally, we want to project these objects onto the screen. Coordinate Hierarchy Object #1 Object Coordinates Transformation Object #1 - World Object #2 Object Coordinates Transformation Object #2 - World Object #3 Object Coordinates Transformation Object #3 - World World Coordinates Transformation World-Screen Screen Coordinates Transformations in OpenGL Transformations in OpenGL Transformations are specified by matrix operations. Desired transformation can be obtained by a sequence of simple transformations that can be concatenated together. Transformation matrix is usually represented by 4x4 matrix (homogeneous coordinates). Provides matrix stacks for each type of supported matrix to store matrices. Transformation Matrices Model-viewing matrix Projection matrix Texture matrix OpenGL Transformation Pipeline Programming Transformations In OpenGL, the transformation matrices are part of the state, they must be defined prior to any vertices to which they are to apply. In modeling, we often have objects specified in their own coordinate systems and must use transformations to bring the objects into the scene. OpenGL provides matrix stacks for each type of supported matrix (model-view, projection, texture) to store matrices. Steps in Programming Prior to rendering, view, locate, and orient: Eye/camera position 3D geometry Manage the matrices Including matrix stack Composite transformations Current Transformation Matrix Current Transformation Matrix (CTM) The matrix that is applied to any vertex that is defined subsequent to its setting. If change the CTM, we change the state of the system. CTM is a 4 x 4 matrix that can be altered by a set of functions. Current Transformation Matrix The CTM can be set/reset/modify (by post- multiplication) by a matrix Ex: C = M / set to matrix M C = CT / post-multiply by T C = CS / post-multiply by S C = CR / post-multiply by R Current Transformation Matrix Each transformation actually creates a new matrix that multiplies the CTM; the result, which becomes the new CTM. CTM contains the cumulative product of multiplying transformation matrices. Ex: If C = M; C = CT; C = CR; C = CS Then C = M T R S Ways to Specify Transformations In OpenGL, we usually have two styles of specifying transformations: Specify matrices ( glLoadMatrix, glMultMatrix ) Specify operations ( glRotate, glTranslate ) Specifying Matrix Specify current matrix mode Modify current matrix Load current matrix Multiple current matrix Specifying Matrix (1) Specify current matrix mode glMatrixMode (mode) Specified what transformation matrix is modified. mode: GL_MODELVIEW GL_PROJECTION GL_TEXTURE Specifying Matrix (2) Modify current matrix glLoadMatrixfd ( Type *m ) Set the 16 values of current matrix to those specified by m. Note: m is the 1D array of 16 elements arranged by the columns of the desired matrix Specifying Matrix (3) Modify current matrix glLoadIdentity ( void ) Set the currently modifiable matrix to the 4x4 identity matrix. Specifying Matrix (4) Modify current matrix glMultMatrixfd ( Type *m ) Multiple the matrix specified by the 16 values pointed by m by the current matrix, and stores the result as current matrix. Note: m is the 1D array of 16 elements arranged by the columns of the desired matrix Specifying Operations Three OpenGL operation routines for modeling transformations: Translation Scale Rotation Problem Modify cube program to translate, scale, and rotate using glMultMatrix (changes commented out) Specifying Operations (1) Translation glTranslate fd (TYPE x, TYPE y, TYPE z) Multiplies the current matrix by a matrix that translates an object by the given x, y, z. Specifying Operations (2) Scale glScale fd (TYPE x, TYPE y, TYPE z) Multiplies the current matrix by a matrix that scales an object by the given x, y, z. Specifying Operations (3) Rotate glRotate fd (TPE angle, TYPE x, TYPE y, TYPE z) Multiplies the current matrix by a matrix that rotates an object in a counterclockwise direction about the ray from origin through the point by the given x, y, z. The angle parameter specifies the angle of rotation in degree. Example Lets examine an example: Rotation about an arbitrary point Question: Rotate a object for a 45.0-degree about the line through the origin and the point (1.0, 2.0, 3.0) with a fixed point of (4.0, 5.0, 6.0). Rotation About an Arbitrary Point 1. Translate object through vector V. T(-4.0, -5.0, -6.0) 2. Rotate about the origin through angle . R(45.0) 3. Translate back through vector V T(4.0, 5.0, 6.0) M = T(V ) R( ) T(-V ) OpenGL Implementation glMatrixMode (GL_MODEVIEW); glLoadIdentity (); glTranslatef (4.0, 5.0, 6.0); glRotatef (45.0, 1.0, 2.0, 3.0); glTranslatef (-4.0, -5.0, -6.0); Order of Transformations The transformation matrices appear in reverse order to that in which the transformations are applied. In OpenGL, the transformation specified most recently is the one applied first. Order of Transformations In each step: C = I C = CT(4.0, 5.0, 6.0) C = CR(45, 1.0, 2.0, 3.0) C First translate, then rotate = Composition of Transformations We can compose an overall transformation by applying several transformations in succession. Any composition of affine transformations is still affine. When homogeneous coordinates are used, affine transformations are composed by simple matrix multiplication. Problem 1. Draw the car body. 2. Translate to right front and draw wheel. 3. Return back to car body. 4. Translate to left front and draw wheel. 5. Return back to car body. . Always remember where you are! Matrix Stacks OpenGL uses matrix stacks mechanism to manage transformation hierarchy. OpenGL provides matrix stacks for each type of supported matrix to store matrices. Model-view matrix stack Projection matrix stack Texture matrix stack Matrix Stacks Top Bottom Popping Pushing Current matrix is always the topmost matrix of the stack We manipulate the current matrix is that we actually manipulate the topmost matrix. We can control the current matrix by using push and pop operations. Manipulating Matrix Stacks (1) Remember where you are glPushMatrix ( void ) Pushes all matrices in the current stack down one level. The topmost matrix is copied, so its contents are duplicated in both the top and second-from-the top matrix. Note: current stack is determined by glMatrixModel() Manipulating Matrix Stacks (2) Go back to where you were glPopMatrix ( void ) Pops the top matrix off the stack, destroying the contents of the popped matrix. What was the second-from-the top matrix becomes the top matrix. Note: current stack is determined by glMatrixModel() Manipulating Matrix Stacks (3) The depth of matrix stacks are implementation-dependent. The Modelview matrix stack is guaranteed to be at least 32 matrices deep. The Projection matrix stack is guaranteed to be at least 2 matrices deep. glGetIntegerv ( Glenum pname, Glint *parms ) Pname: GL_MAX_MODELVIEW_STACT_DEPTH GL_MAX_PROJECTION_STACT_DEPTH Demonstration (look at code) Demonstration (look at code) Demonstration (look at code) Lets Examine Some Examples Question 1: Draw a simple solar system with a planet and a sun. Sun rotates around its own axis (Y axis) The planet rotates around its own axis (Y axis) The planet also rotates on its orbit around the sun. Example-1 Sun: Locates at the origin and rotates around its own axis (Y axis) M = Ry () Planet: 1. Rotates around its own axis. M1 = Ry () 2. Translate to its orbit. M2 = T (x, y, z) 3. Rotates around Sun. M3 = Ry () M = M3 M2 M1 OpenGL Implementation void main (int argc, char* argv) glutInit ( glutInitDisplayMode (GLUT_DOUBLE | GLUT_RGB); glutInitWindowSize (500, 500); glutCreateWindow (Composite Modeling Transformation); init (); glutDisplayFunc (display); glutReshapeFunc (reshape); glutKeyboardFunc (keyboard); glutMainLoop (); OpenGL Implementation void init (void) glViewport(0, 0, 500, 500); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluPerspective(60.0, 1, 1.0, 20.0); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef (0.0, 0.0, -5.0); / viewing transform glClearColor(0.0, 0.0, 0.0, 0.0); glShadeModel (GL_FLAT); OpenGL Implementation void display(void) glClear(GL_COLOR_BUFFER_BIT); glColor3f (1.0, 1.0, 1.0); glPushMatrix(); / draw sun glPushMatrix(); glRotatef (GLfloat) ang2, 0.0, 1.0, 0.0); glRotatef (90.0, 1.0, 0.0, 0.0); / rotate it upright glutWireSphere(1.0, 20, 16); / glut routine glPopMatrix(); OpenGL Implementation (con.) / draw smaller planet glRotatef (GLfloat) ang1, 0.0, 1.0, 0.0); glTranslatef (2.0, 0.0, 0.0); glRotatef (GLfloat) ang3, 0.0, 1.0, 0.0); glRotatef (90.0, 1.0, 0.0, 0.0); / rotate it upright glutWireSphere(0.2, 10, 8); / glut routine glPopMatrix(); glutSwapBuffers(); Result Lets Examine Some Examples Question 2: Draw a simple articulated robot arm with three segments. The arms should be connected with pivot points as the shoulder, elbow, or other joints. (the three segments have same length, saying 2 units) Pivot points Example-2 Red segment: 1. Translates unit 1 to its pivot point. M1 = T (1, 0, 0) 2. Rotates around its pivot point. M2 = Ro () 3. Translates 1 unit back to origin. M3 = T (-1, 0, 0) M = M3 M2 M1 OpenGL Implementation void display(void) glClear(GL_COLOR_BUFFER_BIT); glPushMatrix(); / draw shoulder (red) glTranslatef (-1.0, 0.0, 0.0); glRotatef (shoulder, 0.0, 0.0, 1.0); glTranslatef (1.0, 0.0, 0.0); glPushMatrix(); glScalef (2.0, 0.4, 0.1); glColor3f (1.0, 0.0, 0.0); glutSolidCube (1); / glut routine glPopMatrix(); Example-2 Green segment: 1. Translates unit 1 to its pivot point. M1 = T (1, 0, 0) 2. Rotates around its pivot point. M2 = Ro () 3. Translates 1 unit to the edge of the Red segment. M3 = T (1, 0, 0) M = M3 M2 M1 OpenGL Implementation void display(void) / draw elbow glTranslatef (1.0, 0.0, 0.0); glRotatef (elbow, 0.0, 0.0, 1.0); glTranslatef (1.0, 0.0, 0.0); glPushMatrix(); glScalef (2.0, 0.4, 0.1); glColor3f (0.0, 1.0, 0.0); glutSolidCube(1); / glut routine glPopMatrix(); Example-2 Yellow segment: 1. Translates unit 1 to its pivot point. M1 = T (1, 0, 0) 2. Rotates around its pivot point. M2 = Ro () 3. Translates 1 unit to the edge of the Green segment. M3 = T (1, 0, 0) M = M3 M2 M1 Result Problems Modify the Sailboat program, utilizing matrix multiplication, to do the following: Translate it to the middle of the window Scale it to half size Make it spin about the : X axis left mouse button Y axis middle mouse button Z axis - right mouse button Problems Modify the Teapot program, utilizing rotate-scale- translate, to do the following: Translate it to the bottom of the window Scale it to 1/3 size Rotate it 120 degrees about the x axis Remember Always keep tracking your current position. Remember where you are, and go back to where you were. Matrix multiplication is not commutative, the transformation order is very important. In OpenGL, the transformation specified most recently is the one applied first. glu quadric Primitives Quadric primitives gluCylinder gluDisk gluPartialDisk gluSphere Displays at 0, 0, 0 Translate to where you want it gluNewQuadric Create a new Quadric Object gluNewQuadric (); gluCylinder Draw a cylinder gluCylinder ( quad, base, top, height, slices, stacks ); quad specifies the quadrics object (create with gluNewQuadric) base specifies the radius of the cylinder at z=0 top specifies the radius of the cylinder at z=height height - specifies the height of the cylinder slices specifies the number of subdivisions around the z axis stacks - specifies the number of subdivisions along the z axis gluDisk Draw a disk gluDisk ( quad, inner, outer, slices, loops ); quad specifies the quadrics object (create with gluNewQuadric) inner specifies the inner radius of the disk (may be 0) outer specifies the outer radius of the disk slices specifies the number of subdivisions around the z axis loops - specifies the number of concentric rings about the origin into which the disk is subdivided gluPartialDisk Draw an arc of a disk gluPartialDisk ( quad, inner, outer, slices, loops, start, sweep ); quad specifies the quadrics object (create with gluNewQuadric) inner specifies the inner radius of the disk (may be 0) outer specifies the inner radius of the disk slices specifies the number of subdivisions around the z axis loops - specifies the number of concentric rings about the origin into which the disk is subdivided start specifies the starting angle, in degrees, of the disk portion sweep specifies the sweep angle, in degrees, of the disk portion gluSphere Draw a sphere gluSphere ( quad, radius, slices, stacks ); quad specifies the quadrics object (create with gluNewQuadric) radius specifies the radius of the sphere slices specifies the number of subdivisions around the z axis stacks - specifies the number of subdivisions along the z axis

注意事項(xiàng)

本文(人教小學(xué)信息第二冊(cè)《圖形變換》PPT課件.ppt)為本站會(huì)員(za****8)主動(dòng)上傳,裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)上載內(nèi)容本身不做任何修改或編輯。 若此文所含內(nèi)容侵犯了您的版權(quán)或隱私,請(qǐng)立即通知裝配圖網(wǎng)(點(diǎn)擊聯(lián)系客服),我們立即給予刪除!

溫馨提示:如果因?yàn)榫W(wǎng)速或其他原因下載失敗請(qǐng)重新下載,重復(fù)下載不扣分。




關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

copyright@ 2023-2025  zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話:18123376007

備案號(hào):ICP2024067431號(hào)-1 川公網(wǎng)安備51140202000466號(hào)


本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務(wù)平臺(tái),本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請(qǐng)立即通知裝配圖網(wǎng),我們立即給予刪除!