




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
1、電子科技大學信息與軟件工程學院三維圖形程序設計綜合實驗標準實驗報告(實驗)課程名稱三維圖形程序設計電子科技大學教務處制表實驗目的按比例大小繪制太陽系(太陽、地球、月亮)自動紋理映射地球以及月亮的自轉地球以及月亮的公轉#include windows.h”#include #include #include #define SunSize 0.6#define EarthSize 0.2#define MoonSize 0.1GLUquadricObj* g_quadratic_sun;GLUquadricObj* g_quadratic_earth;GLUquadricObj* g_quadr
2、atic_moon;GLuint sun_texture;GLuint earth_texture;GLuint moon_texture;GLfloat year = 0.0; /degreesGLfloat day = 0.0;GLfloat moonAroundEarth = 0.0;/月亮繞地球的速度GLfloat moonItsSelf = 0.0;/月球自轉的速度GLfloat EarthOrbitRadius = 1.0; /地球軌道半徑GLfloat MoonOrbitRadius = 0.3;/月亮軌道半徑?#pragma comment( lib, opengl32.lib
3、) OpenGL32.lib While Linking ( NEW ) #pragma comment( lib, glu32.lib) GLu32.lib While Linking ( NEW ) #pragma comment( lib, glaux.lib) GLaux.lib While Linking ( NEW )讀取BMP類型的圖形文件tAUX_RGBImageRec *LoadBMP(const char Filename) Image FILE *File = NULL;Handleif (!Filename)A Filename Was Givenreturn NULL
4、;NULLFile = fopen(Filename, r);See If The File Existsif (File)File Exist?fclose(File);Handlereturn auxDIBImageLoad(Filename);And Return A Pointerreturn NULL;Return NULL /加載綁定紋理GLuint LoadGLTexture(const char *filename) Convert To Textures AUX_RGBImageRec *pImage;/ Search For/ Search For/ Search For/
5、 Loads A Bitmap/ File/ Make Sure/ If Not Return/ Check To/ Does The/ Close The/ Load The Bitmap/ If Load Failed/ Load Bitmaps And/ Create Storage/ Texture IDSpace For The Texture GLuint texture = 0;pImage = LoadBMP(filename);/ Loads TheBitmap Specified By filename/ Load The Bitmap, Check For Errors,
6、 If Bitmaps Not Found Quitif (pImage != NULL & pImage-data != NULL)/ If Texture ImageExistsglGenTextures(1, &texture);/ Create TheTexture/ Typical Texture Generation Using Data From The BitmapglBindTexture(GL_TEXTURE_2D, texture);glTexImage2D(GL_TEXTURE_2D, 0, 3, pImage-sizeX, pImage-sizeY, 0, GL_RG
7、B, GL_UNSIGNED_BYTE, pImage-data);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);/ Free The/ Free The Imagefree(pImage-data);Texture Image Memory free(pImage);Structurereturn texture;/ Return TheStatus void RenderScen
8、e(void) glPushMatrix();glEnable(GL_TEXTURE_2D);gluLookAt(0.0, 0.0, -4.0,0.0, 0.0,1.0,0.0, 1.0,0.0);繪制太陽glColor3f(1.0, 1.0, 0.0);glBindTexture(GL_TEXTURE_2D, sun_texture); gluSphere(g_quadratic_sun, SunSize, 32, 32);glPushMatrix();地球公轉glRotatef(year, 0.0, 1.0, 0.0);glTranslatef(EarthOrbitRadius, 0.0,
9、 0.0);glRotatef(-year, 0.0, 1.0, 0.0);glPushMatrix();地球自轉 glRotatef(day, 0.25, 1.0, 0.0);繪制地球glColor3f(0.0, 0.0, 1.0);glBindTexture(GL_TEXTURE_2D, earth_texture);/綁定紋理 gluSphere(g_quadratic_earth, EarthSize, 32, 32);glPopMatrix();月球公轉glRotatef(moonAroundEarth, 0.0, 1.0, 0.0);glTranslatef(MoonOrbitRa
10、dius, 0.0, 0.0);glRotatef(-moonAroundEarth, 0.0, 1.0, 0.0);/月球自轉 glRotatef(moonItsSelf, 0.0, 1.0, 0.0);/繪制月球glColor3f(0.8, 0.8, 0.0);glBindTexture(GL_TEXTURE_2D, moon_texture);gluSphere(g_quadratic_moon, MoonSize, 32, 32);glPopMatrix();glPopMatrix();glDisable(GL_TEXTURE_2D);void Init(void)glEnable(G
11、L_DEPTH_TEST);glClearColor(0.0, 0.0, 0.0, 0.0);glLoadIdentity();幾何曲面的產生sun_texture = LoadGLTexture(sunmap.bmp);g_quadratic_sun = gluNewQuadric();gluQuadricNormals(g_quadratic_sun, GLU_SMOOTH); earth_texture = LoadGLTexture(earthmap1k.bmp);g_quadratic_earth = gluNewQuadric();gluQuadricNormals(g_quadr
12、atic_earth, GLU_SMOOTH);moon_texture = LoadGLTexture(moonmap4k.bmp);g_quadratic_moon = gluNewQuadric();gluQuadricNormals(g_quadratic_moon, GLU_SMOOTH);glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);glEnable(GL_TEXTURE_GEN_S);glEnable(GL_TEXTUR
13、E_GEN_T);glMatrixMode(GL_MODELVIEW);glLoadIdentity();void Display(void)glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glLoadIdentity();RenderScene();glFlush();glutSwapBuffers();void Reshape(int x, int y)if (y = 0) return;glMatrixMode(GL_PROJECTION);glLoadIdentity();gluPerspective(40.0, (GLdouble)x / (GLdouble)y, 0.5, 20.0);glMatrixMode(GL_MODELVIEW);glViewport(0, 0, x, y);Display();void Idle(void)day += 4;year += 0.5;moonItsSelf += 10;moonAroundEarth += 0.4;Display();int main(int argc, char* argv)glu
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經權益所有人同意不得將文件中的內容挪作商業或盈利用途。
- 5. 人人文庫網僅提供信息存儲空間,僅對用戶上傳內容的表現方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 宜賓職業技術學院《公共危機管理概論》2023-2024學年第二學期期末試卷
- 長豐縣2025屆數學五年級第二學期期末監測試題含答案
- 淮南職業技術學院《醫學遺傳學A》2023-2024學年第二學期期末試卷
- 太湖創意職業技術學院《項目評估》2023-2024學年第一學期期末試卷
- 南通理工學院《Hadoop技術與應用實訓》2023-2024學年第一學期期末試卷
- 湛江市年模擬物理試題(三)
- 棗強中學高二上學期期末考試理數試題
- 建材市場銷售技巧培訓
- 2025裝修合同范本3
- 精神病人衛生護理課件
- 【貿易戰背景下華為公司危機應對措施及其啟示18000字(論文)】
- 【網絡謠言型尋釁滋事罪的認定存在的爭議探析8600字(論文)】
- 2024延遲退休政策詳解
- 水泥標準培訓考核2024
- 圖書館運營管理服務投標方案(技術方案)
- IC反應器的設計11
- IEEE-30節點全套數據2
- (落地式、懸挑式腳手架)設備設施風險分級管控清單
- DL∕T 5046-2018 發電廠廢水治理設計規范
- 高中語文統編版必修上冊《致云雀》課件
- 杉篙架搭設安全技術交底
評論
0/150
提交評論