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

人教小學信息第二冊《圖形變換》PPT課件.ppt

上傳人:za****8 文檔編號:22718955 上傳時間:2021-05-30 格式:PPT 頁數(shù):122 大?。?.10MB
收藏 版權申訴 舉報 下載
人教小學信息第二冊《圖形變換》PPT課件.ppt_第1頁
第1頁 / 共122頁
人教小學信息第二冊《圖形變換》PPT課件.ppt_第2頁
第2頁 / 共122頁
人教小學信息第二冊《圖形變換》PPT課件.ppt_第3頁
第3頁 / 共122頁

下載文檔到電腦,查找使用更方便

14.9 積分

下載資源

還剩頁未讀,繼續(xù)閱讀

資源描述:

《人教小學信息第二冊《圖形變換》PPT課件.ppt》由會員分享,可在線閱讀,更多相關《人教小學信息第二冊《圖形變換》PPT課件.ppt(122頁珍藏版)》請在裝配圖網(wǎng)上搜索。

1、第三講 圖形變換 圖形變換是計算機圖形學的基礎內(nèi)容。 有二維(三維)圖形的平移、旋轉、變 比、對稱等變換,三維圖形的投影透視 變換等。 第 6講 圖形變換 二維幾何變換 基本變換與復合變換 三維幾何變換 基本變換與復合變換 本講主要內(nèi)容 圖形變換的數(shù)學基礎 二維圖形的基本變換、復合(組合)變 換; 三維圖形基本變換、復合(組合)變換; 平行投影 透視投影 圖形變換的數(shù)學基礎 矢量運算 矩陣運算 矩陣 單位矩陣 逆矩陣 轉置矩陣 行列式 上機編程,實現(xiàn)兩個矩陣相乘 特別注意: 矩陣相乘不適合交換律 變換的數(shù)學基礎 (1/4) 矢量 矢量和 z y x u u u U z y x v v v V

2、zz yy xx vu vu vu VU 變換的數(shù)學基礎 (2/4) 矢量的數(shù)乘 矢量的點積 性質 z y x ku ku ku Uk zzyyxx vuvuvuVU UVVU VUVU 0 00 UUU 變換的數(shù)學基礎 (3/4) 矢量的長度 單位矢量 矢量的夾角 矢量的叉積 222 zyx uuuUUU VU VU c o s zyx zyx vvv uuu kji VU 變換的數(shù)學基礎 (4/4) 矩陣 階矩陣 n階方陣 零矩陣 行向量與列向量 單位矩陣 矩陣的加法 矩陣的數(shù)乘 矩陣的乘法 矩陣的轉置 矩陣的逆 m n 齊次坐標 用 n+1維向量表示 n維向量 優(yōu)越性 提供了用矩陣運算把

3、二維三維甚至高維 空間的點集從一個坐標系變換到另一個 坐標系的方法。 可以表示無窮遠的點 圖形幾何變換 基本原理: 按某種規(guī)律,改變圖形的形狀、大小、位置 等 方法: 坐標系不動,圖形變動后坐標值變化; 坐標系變化后圖形在新坐標系中的新值。 二 . 圖形變換的過程 建立物體的 WC 變換到 VC 在 VC空間 進行裁剪 投影到 NDC 變換到 DC 在圖形設備 上輸出 三 . 圖形變換的特點 圖形變換就是改變圖形的幾何關系,即改變圖形頂點的坐 標,但圖形的拓撲關系不變。 最基本的圖形變換可以分別用矩陣形式表示為: 平移變換 P P Tm Tm Mx My Mx、 My分別為 X方 向和 Y方向

4、的平移量 。 比例變換 P P Ts Sx 0 0 Sy Sx、 Sy分別表示比例因子 。 旋轉變換 P P Tr cos sin -sin cos 0時為逆時針旋轉 0時為順時針旋轉 Ts Tr 四 . 齊次坐標 從形式上來說,用一個有 n+1個分量的向量去表示一個有 n 個分量的向量的方法稱為齊次坐標表示。 例如二維平面上的點 (x, y)的齊次坐標表示為 (h x, h y, h), h是任 一不為 0的比例系數(shù)。 給定一個點的齊次坐標表示 : (x, y, h), 該 點的二維笛卡兒直角坐標: (x / h, y / h)。 同樣 , 對于一個三維空間的向量 (x, y, z), 它在

5、四維空間中對應的向量 即齊次坐標為 (x h, y h, z h, h), 其中 h 0。 齊次坐標的概念可以推廣到 n維空間的向量 。 齊次坐標的表示不是唯一的 , 通常當 h=1時 , 稱為 規(guī)格化齊次坐標 。 為什么需要齊次坐標? 多個變換作用于多個目標 變換合成 變換合成的問題 引入齊次坐標 變換的表示法統(tǒng)一 齊次坐標表示的優(yōu)點: 可方便地用變換矩陣實現(xiàn)對圖形的變換; 齊次坐標表示法可以表達無窮遠點 。 齊次坐標 二維圖形變換矩陣 一般形式 : a b p c d q l m s P = P T2D (二維仿射變換 : p=q=0) 二維變換矩陣中 : a b c d l m 是對圖形

6、進行平移變換。 S 是整體比例變換。 (非仿射變換) p,q 用于投影變換(三維點時使用) x y 1 = x y 1 是對圖形進行縮放 、 旋轉 、 對稱 、 錯切等變換 。 二維圖形變換 采用齊次坐標可將二維圖形變換表示成如下形式 : a b 0 c d 0 l m 1 P = P M 二維變換矩陣中 : a b c d l m 是對圖形進行平移變換 x y 1 = x y 1 變換后的 頂點坐標 變換前的 頂點坐標 二維變換矩陣 是對圖形進行縮放 、 旋轉 、 對稱 、 錯切等變換 。 二維基本幾何變換 點的變換: 恒等變換 平移變換 比例變換 旋轉變換 對稱變換 錯切變換 平移變換 只

7、改變圖形的位置 , 不改變圖形的大 小和形狀 二維:將圖形對象從一個位置 (x, y) 移到另一個位置 (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

8、) (x, y) x y 比例變換 比例 因子 if sx , sy 1, 物體被拉伸 if 0 sx , sy 1, 物體被壓縮 if sx , sy 0,物體被倒影 均勻 /非均勻 比例變換 if sx = sy ,均勻 比例變換 if sx sy , 非均勻 比例變換 旋轉變換 x y f (x, y) (x, y) 旋轉變換 Remember - 旋轉方向 - 旋轉角度 - 旋轉中心 - 旋轉是剛體變換 x P(x, y) P (x, y) y 旋轉變換 點 P(x,y)的極坐標表示 繞坐標原點旋轉角度 ( 逆時針為正 , 順時針 為負 ) P = P R cos sin 0 -sin

9、 cos 0 0 0 1 R( ) = 旋轉矩陣 cos -sin 0 sin cos 0 0 0 1 R-1 ( ) = 對稱變換 對稱變換 關于 x軸的對稱變換 關于 y軸的對稱變換 100 010 001 xSY 100 010 001 ySY 對稱變換 對稱變換 關于原點的對稱變換 關于 y=x的對稱變換 關于 y=-x的對稱變換 100 010 001 SO 100 001 010 xySY 100 001 010 xySY 錯切變換 以 y軸為依賴軸的錯切變換 y坐標不變 100 01 001 11* bxyyx yy byxx 點的基本幾何變換的推廣 點的變換: 直線的變換 多邊

10、形的變換 曲線的變換(由每一點的變換,重新畫線完成) 二維仿射變換 x=ax+by+m y =cx+dy+n P = P T 二維復合變換(組合變換) 任何一復雜的幾何變換可以看成基本集合 變換的組合: P = PT = P T1 T2 Tn 復合平移 復合比例 復合旋轉 其他常見復合變換 相對于某個參考點的幾何變換(比例、旋轉等) 相對于某直線的幾何變換(對稱等) 相對于某個參考點的幾何變換(比例、 旋轉等) 求某點 P相對于固定點 F( xF,yY)旋轉一 個角度 的變換矩陣 T。 步驟: 將固定點移到坐標原點上; 對原點進行二維旋轉變換; 反平移固定點到原位。 例:求 P(5,4)繞 F

11、(3,2)逆時針旋轉 45度的 變換矩陣,以及變換后 P點的新坐標 P。 相對于某直線的幾何變換(對稱等) 步驟 平移該對稱直線到原點; 旋轉角度到與坐標軸( X軸或 Y軸)重合; 對變換對象進行對稱變換; 反向旋轉到原來方向; 反平移到原來位置。 關于任意軸的對稱變換 課堂練習(一) 回答下列問題: 1. 什么是齊次坐標?為什么要用規(guī)范化的齊 次坐標? 2. 什么是二維仿射變換?有哪些不變性?寫 出它的變換形式(用矩陣表示) 課堂練習(二) 證明題 1. 證明兩個連續(xù)的旋轉變換(或變比例變換) 的矩陣運算具有互換性。 如,兩個二維旋轉 變換 R(1 ), R ( 2 ),具有下式 R(1 )

12、R ( 2 ) = R(1 +2 ) 。 2. 證明二維點相對于 X軸作對稱,緊跟著相 對于 y=-x直線作對稱變換,完全等價于該 點相對于坐標原點作旋轉變換(旋轉角度 是多少?) 課堂練習(三) 推導題 1. 試推導將二維平面上任意直線段 P1( x1,y1)與 P1 ( x1,y1),轉換成與 X軸重合的變換矩陣(線段 P1P2與 X軸的夾角小于 45度)。 2. 求 P點相對于 L: ax+by+c=0,作對稱變換后得到的 P。例如: 已知點 P( 8, 12),直線 L的方程為: x-2y+6=0, 請推導并計算該點相對于作對稱變換的矩陣 T,使 點 P的對稱點 P=PT,并求出該點坐

13、標值。 Y X O 已知點 P( 8, 12),直線 L的方程為: x-2y+6=0, 請推導并 計算 P相對于 L作對稱變換的矩陣 T,并求出該點坐標值。 三維圖形變換 坐標系 右手法則 拇指指向坐標軸 Z的方向, 其余四指指向旋轉方向 Y Z X 0 逆時針為正 三維圖形變換 三維空間點的齊次坐標矩陣( 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)生比例 、 錯切 、 鏡象和旋轉等基本變換 。 g h i l m n 產(chǎn)生沿 x、 y、

14、z三軸方向上的平移變換。 p q 產(chǎn)生透視變換 。 r s 產(chǎn)生等比例縮放變換 。 T = 三維圖形變換中要 注意 的幾個問題: 1. (三維 )采用 s 來實現(xiàn) 整體的比例 變換。 當 |s | 1 時,三維圖形整體等比例縮小。 2.(三維 )對稱 變換是 相對于各個坐標平面 進行的。 3.(三維 )旋轉 變換是指 繞坐標軸 的旋轉。 右手坐標系下,繞坐標軸逆時針為正 順時針旋轉為負。 4.三維圖形的級聯(lián) (組合 )變換 對于復雜的三維圖形變換,也需要通過若干個變換矩陣 的級聯(lián)才能實現(xiàn)。特別注意 : 變換的方法 和 矩陣級聯(lián)的順序。 三維幾何變換 平移變換 (相對于原點)比例變換 1 010

15、0 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 三維幾何變換 對稱變換 只考慮關于坐標平面的對稱變換 關于 xy平面對稱 關于 yz平面對稱 關于 xz平面對稱 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 錯切變換 變換矩陣為: 三維錯切變換矩陣 : 1 b c 0 d 1 f 0 g h 1 0 0 0

16、0 1 其中 : b=c=f=h=0, 沿 X方向產(chǎn)生錯切 T = 三維幾何變換 旋轉變換 需要指定旋轉角度和旋轉軸 . y x z rotation axis (x, y, z) (x, y, z) 三維幾何變換 旋轉變換 繞 x軸 1000 0c o ss in0 0s inc o s0 0001 )( xR (x, y, z) (x, y, z) x y z 三維幾何變換 旋轉變換 繞 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

17、00s inc o s )( zR x z (x, y, z) (x, y, z) 幾點說明 1) 平移變換只改變圖形的位置 , 不改變圖形的大小和形狀; 2) 旋轉變換保持圖形各部分間的線性關系和角度關系 , 變換后直 線的長度不變; 3) 比例變換可改變圖形的大小和形狀; 4) 錯切變換引起圖形角度關系的改變 , 甚至導致圖形發(fā)生崎變; 5) 拓撲不變的幾何變換不改變圖形的連續(xù)關系和平行關系; 三維復合變換 實際的圖形對象的變換往往是由多個簡單變 換復合而來。將相關的簡單變換的變換矩陣乘 起來就可得到復合變換的變換矩陣。 例:求基于參考點( xf, yf, zf)的比例變換, 變換方法步驟

18、: 1)通過平移變換將參考點移到原點,使原點 與參考點重合; 2)相對于原點進行比例變換; 3)通過平移變換將參考點移原來位置; 繞空間任意軸的三維旋轉變換。 例:有空間任意軸 AB(用點 A: xA,yA,zA,方向數(shù) a,b,c 表示),現(xiàn)有空間點 P( x,y,z)繞 AB軸旋轉 角后為 P ( x ,y ,z ),求該變換矩陣。方法步驟: 1)平移 AB軸與原點重合; 2)AB繞 X軸旋轉 角 ,使之落到 ZX平面上; 3)將 AB繞 Y軸旋轉 角 ,使之與 Z軸重合; 4)此時 AB與 Z軸重合,繞 Z軸 旋轉 角 ; 5)繞 X軸反旋轉 -角 ; 6)繞 X軸反旋轉 -角 ; 7)

19、反平移 。 預備知識:方向數(shù)與各坐標軸、 坐標平面的關系(夾角、投影等) B點的方向數(shù) 為( 2, 3, 4) Y X Z 繞 X軸旋轉 角; 繞 Y軸旋轉 角。 習 題 7、在坐標系 oxyz中,求一個變換將 P(1,1,1)Q(2,2,2)變換到 z軸上: P在坐標原 點, Q在 z軸正半軸。(方向數(shù)為:?) x y z P Q o x y z Q o(P) M 隨堂練習 1. 寫出三維基本幾何變換的逆變換; 2. (教材 P213)將圖 7-40中的物體 ABCDEFGH進行如 下變換:平移使 C點與 P( 1, -1, 0)重合,然后繞 Z 軸旋轉 60度。 3. 將圖 7-41中的空

20、間四面體進行關于 P點的整體放大, 試寫出變換矩陣。 4. 假定空間直線 AB兩端點坐標為 A(0,0,0)B(2,2,2),試 寫出繞 AB軸旋轉 30度的三維復合變換矩陣。 5. *在右手坐標系中,從原點到 P( x,y,z)給出一直線, 用三種方法將此直線旋轉到正的軸線上,并用代數(shù) 證明所得的結果等價。 a. 先繞 X軸旋轉到 XZ平面上,再繞 Y軸到 Z軸上; b. 先繞 Y軸旋轉到 YZ平面上,再繞 X軸到 Z軸上; c. 先繞 Z軸旋轉到 XZ平面上,再繞 Y軸到 Z軸上 . 二維圖形的顯示流程圖 繞繞任意點的旋轉 x P(x, y) P (x, y) V = (Vx, Vy) y

21、 1. 平移 P點經(jīng)過矢量 -V. 2. 繞原點旋轉 . 3. 將 P點平沿矢量 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 wis

22、h 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. Sc

23、reen 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

24、 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 r

25、epresented 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 matri

26、ces 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 ma

27、trix (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 matr

28、ix 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

29、 = 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 multiplyin

30、g 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

31、 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 glLoa

32、dMatrixfd ( 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.

33、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 Operation

34、s 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 matri

35、x 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) Mul

36、tiplies 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:

37、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 th

38、rough 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 t

39、hat 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

40、 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

41、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

42、 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 matri

43、x 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

44、 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 glMatrixM

45、odel() 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_MA

46、X_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 i

47、ts 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

48、 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); glutMai

49、nLoop (); 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); glShadeMo

50、del (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 glPop

51、Matrix(); 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(); glutSwapBuffer

52、s(); 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

53、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); gl

54、Rotatef (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.

55、 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,

56、 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 th

57、e 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

58、- 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 transformat

59、ion 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 gluNewQuadr

60、ic (); 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 cylind

61、er 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 di

62、sk (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, slice

63、s, 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

64、 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

展開閱讀全文
溫馨提示:
1: 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
2: 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
3.本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
4. 未經(jīng)權益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
5. 裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
6. 下載文件中如有侵權或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

相關資源

更多
正為您匹配相似的精品文檔
關于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

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

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


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