




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、貴州大學實驗報告學院:計算機科學與技術(shù) 專業(yè): 計算機科學與技術(shù) 班級:計科131姓名學號實驗組實驗時間指導教師黃初華成績實驗項目名稱圖形變換實驗目的實驗目的通過本實驗,使學生了解并掌握在光柵顯示系統(tǒng)中直線的生成和顯示算法,熟悉相關(guān)開發(fā)平臺。為后繼實驗打下基礎(chǔ)。實驗要求對于設計性實驗,應根據(jù)“由學生自行設計實驗方案并加以實現(xiàn)的實驗”內(nèi)涵要求,注意省略由學生自主設計的“實驗方案”。根據(jù)本實驗的特點、要求和具體條件,采用“以學生自主訓練為主的開放模式組織教學,還是采用集中授課形式”,須加以明確。實驗原理標準齊次坐標(x,y,1) 二維變換的矩陣表示平移變換旋轉(zhuǎn)變換放縮變換l 平移變換只改變圖形的位
2、置,不改變圖形的大小。l 旋轉(zhuǎn)變換不改變圖形的形狀l 放縮變換引起圖形形狀的變化。復合變換結(jié)果與變換的順序有關(guān)(矩陣乘法不可交換實驗環(huán)境硬件平臺:PC軟件(推薦):Windows平臺,Visual stdio2013,openGL實驗步驟實驗步驟1. 掌握算法原理;2. 依據(jù)算法,編寫源程序并進行調(diào)試;3. 對運行結(jié)果進行保存與分析;4. 把源程序以文件的形式提交;5. 按格式書寫實驗報告。實驗內(nèi)容#include"stdafx.h"#include <glut.h>#include <stdlib.h>#include <math.h>
3、GLsizei winWidth = 600, winHeight = 600;GLfloat xwcMin = 0.0, xwcMax = 225.0;GLfloat ywcMin = 0.0, ywcMax = 225.0;class wcPt2Dpublic:GLfloat x, y;typedef GLfloat Matrix3x333;Matrix3x3 matComposite;const GLdouble pi = 3.14159;void init(void)glClearColor(1.0, 1.0, 1.0, 0.0);void matrix3x3SetIdentity(M
4、atrix3x3 matIdent3x3)GLint row, col;for (row = 0; row<3; row+)for (col = 0; col<3; col+)matIdent3x3rowcol = (row = col);/生成1,0,00,1,00,0,1void matrix3x3PreMultiply(Matrix3x3 m1, Matrix3x3 m2)GLint row, col;Matrix3x3 matTemp;for (row = 0; row<3; row+)for (col = 0; col<3; col+)matTemprowco
5、l = m1row0 * m20col + m1row1 * m21col + m1row2 * m22col;for (row = 0; row<3; row+)for (col = 0; col<3; col+)m2rowcol = matTemprowcol;void translate2D(GLfloat tx, GLfloat ty)/平移Matrix3x3 matTransl;matrix3x3SetIdentity(matTransl);matTransl02 = tx;matTransl12 = ty;matrix3x3PreMultiply(matTransl,
6、matComposite);void rotate2D(wcPt2D pivotPt, GLfloat theta)/旋轉(zhuǎn)Matrix3x3 matRot;matrix3x3SetIdentity(matRot);matRot00 = cos(theta);matRot01 = -sin(theta);matRot02 = pivotPt.x*(1 - cos(theta) + pivotPt.y*sin(theta);matRot10 = sin(theta);matRot11 = cos(theta);matRot312 = pivotPt.x*(1 - cos(theta) - pivo
7、tPt.y*sin(theta);matrix3x3PreMultiply(matRot, matComposite);void scale2D(GLfloat sx, GLfloat sy, wcPt2D fixedPt)/縮放Matrix3x3 matScale;matrix3x3SetIdentity(matScale);matScale00 = sx;matScale02 = (1 - sx)*fixedPt.x;matScale11 = sy;matScale12 = (1 - sy)*fixedPt.y;matrix3x3PreMultiply(matScale, matCompo
8、site);void transformVerts2D(GLint nVerts, wcPt2D * verts)/組合變化后的矩陣GLint k;GLfloat temp;for (k = 0; k<nVerts; k+)temp = matComposite00 * vertsk.x + matComposite01 * vertsk.y + matComposite02;vertsk.y = matComposite10 * vertsk.x + matComposite11 * vertsk.y + matComposite12;vertsk.x = temp;void tria
9、ngle(wcPt2D*verts)GLint k;glBegin(GL_TRIANGLES);for (k = 0; k<3; k+)glVertex2f(vertsk.x, vertsk.y);glEnd();void displayFcn(void)GLint nVerts = 3;wcPt2D verts3 = 50.0, 25.0 , 150.0, 25.0 , 100.0, 100.0 ;wcPt2D centroidPt;GLint k, xSum = 0, ySum = 0;for (k = 0; k<nVerts; k+)xSum += vertsk.x;ySum
10、 += vertsk.y;centroidPt.x = GLfloat(xSum) / GLfloat(nVerts);centroidPt.y = GLfloat(ySum) / GLfloat(nVerts);wcPt2D pivPt, fixedPt;pivPt = centroidPt;fixedPt = centroidPt;GLfloat tx = 0.0, ty = 100.0;GLfloat sx = 0.5, sy = 0.5;GLdouble theta = pi / 2.0;glClear(GL_COLOR_BUFFER_BIT);glColor3f(0.0, 0.0,
11、1.0);triangle(verts);/三角形matrix3x3SetIdentity(matComposite);scale2D(sx, sy, fixedPt);/縮小transformVerts2D(nVerts, verts);glColor3f(1.0, 0.0, 0.0);triangle(verts);matrix3x3SetIdentity(matComposite);rotate2D(pivPt, theta);/旋轉(zhuǎn)90transformVerts2D(nVerts, verts); glColor3f(1.0, 0.0, 0.0);triangle(verts);ma
12、trix3x3SetIdentity(matComposite);translate2D(tx, ty);/平移transformVerts2D(nVerts, verts); glColor3f(1.0, 0.0, 0.0);triangle(verts);matrix3x3SetIdentity(matComposite);transformVerts2D(nVerts, verts);glColor3f(1.0, 0.0, 0.0);triangle(verts);glFlush();void winReshapeFcn(GLint newWidth, GLint newHeight)g
13、lMatrixMode(GL_PROJECTION);gluOrtho2D(xwcMin, xwcMax, ywcMin, ywcMax);glClear(GL_COLOR_BUFFER_BIT);void main(int argc, char* argv)glutInit(&argc, argv);glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);glutInitWindowPosition(50, 50);glutInitWindowSize(winWidth, winHeight);glutCreateWindow("Geometr
溫馨提示
- 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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 中西醫(yī)結(jié)合治療唾液腺炎-洞察及研究
- 順序索引在大數(shù)據(jù)處理中的應用與優(yōu)化研究-洞察及研究
- 云南省師范大學附屬中學2025屆高一下化學期末檢測模擬試題含解析
- 多維度行為分析框架-洞察及研究
- 江蘇省南通市通州區(qū)2025屆高一下化學期末統(tǒng)考模擬試題含解析
- 2025屆山西省呂梁市汾陽中學高一化學第二學期期末經(jīng)典模擬試題含解析
- 旅游數(shù)據(jù)可視化與呈現(xiàn)-洞察闡釋
- 廣西玉林市北流實驗中學2025屆高二下化學期末學業(yè)水平測試試題含解析
- 兼性厭氧菌群落結(jié)構(gòu)分析-洞察及研究
- 房地產(chǎn)租賃市場細分策略-洞察闡釋
- 2025年中國汽車檢測行業(yè)市場調(diào)查研究及投資前景預測報告
- 2025秋初升高銜接新高一物理模擬卷-分班模擬卷(五)
- 2024年上海高中學業(yè)水平合格性考試歷史試卷真題(含答案)
- 公司年終答謝宴策劃方案
- 小學一年級數(shù)學下冊應用題100道
- 安徽省馬鞍山市2023-2024學年高一下學期期末教學質(zhì)量監(jiān)測化學試卷(含解析)
- 反詐騙(企業(yè)員工)講座培訓課件
- T/CBMCA 019-2021醫(yī)用潔凈室裝飾材料技術(shù)標準
- 2025-2030中國微晶纖維素市場深度評估與需求潛力分析研究報告
- 2025年社會調(diào)查方法與實踐考試試題及答案
- 房東合法免責協(xié)議書
評論
0/150
提交評論