三維設計實驗_第1頁
三維設計實驗_第2頁
三維設計實驗_第3頁
三維設計實驗_第4頁
三維設計實驗_第5頁
已閱讀5頁,還剩4頁未讀 繼續免費閱讀

下載本文檔

版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領

文檔簡介

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. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論